bebopayan
bebopayan

Reputation: 45

Can WebApi have one endpoints and do something different depending on the object sent

Is it possible to have one single endpoint and be able to receive two different objects (but just one, either object1 or object2)?

I don't really mind how it would end up looking in code, all I care is the calling user to be able to call the same endpoint with either of the object types, and well, obviously a way to know which object i'm getting by either having two separate methods or if is the same a way to know which one was sent.

I am not sure how to be more specific, or if there's something else I should mention. Let me know and I'll edit if that is the case.

Upvotes: 3

Views: 340

Answers (1)

C Bauer
C Bauer

Reputation: 5103

Can it? Absolutely. Should it? Nope.

REST describes endpoints as having definitive actions based on their inputs. If you were interacting with a Customer endpoint, it wouldn't make very much sense for that endpoint to also consume Dog! There should be a level of abstraction that allows you to consume a type for the specific purpose you intend, even if that purpose is "log the name of this object and the sound it makes" (eg: "Woof" and "Tacos"), perhaps a Recorder endpoint.

Upvotes: 1

Related Questions