3

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.

bebopayan
  • 45
  • 5
  • 1
    The term for what you're talking about is called overloading. http://stackoverflow.com/questions/14353466/overload-web-api-action-method-based-on-parameter-type – bcr Oct 26 '15 at 19:59

1 Answers1

1

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.

C Bauer
  • 5,003
  • 4
  • 33
  • 62