首页 > 解决方案 > Overloading an api endpoint

问题描述

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.

标签: c#api

解决方案


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.


推荐阅读