1

Is it possible to overload an api endpoint?

I would like the endpoint/route to be the exact same thing but the input parameters different. For example....

    [HttpPost]
    [Route("change-xxx")]
    public async Task<IHttpActionResult> ChangeXxx(MyCPModel1 request)

And....

    [HttpPost]
    [Route("change-xxx")]
    public async Task<IHttpActionResult> ChangeXxx(MyCPModel2 request)

I'm getting an "Multiple actions were found that match the request" error when I try it this way.

WebDevGuy2
  • 1,159
  • 1
  • 19
  • 40
  • Thanks @gunr2171 but this is using MVC. I'm sure it's a similar solution though? – WebDevGuy2 Mar 09 '21 at 18:25
  • Please view the comments on the linked post, where it says that even though the question was asked back in 2009, it's still applicable today with every version of ASP.Net. – gunr2171 Mar 09 '21 at 18:26

1 Answers1

1

Short answer -No, it is not possible to overload a Web API Endpoint. You can't have two endpoints with the exactly same path and verb. The error message "Multiple actions were found that match the request" confirms that.

Rafael Biz
  • 424
  • 4
  • 19