Is there a default verb applied to a Web API ApiController method?

File this under learning something new every day! Typically method name matching is thought of this way. Looking at the WebAPI source, however, there is a branch of logic for fallback. If the method name doesn’t map (through attribute, or convention) to a supported HTTP verb, then the default is POST. By default action selection … Read more

Manually set operationId to allow multiple operations with the same verb in Swashbuckle

EDIT This answer relates to Swashbuckle 5.6 and .NET Framework. Please read mwilson’s answer for Swashbuckle and .NET Core You can use the SwaggerOperationAttribute provided by Swashbuckle for that. [SwaggerOperation(“get”)] public IEnumerable<Contact> Get() { …. } [SwaggerOperation(“getById”)] public IEnumerable<Contact> Get(string id) { … } You can use that attribute to add tags and schemes to … Read more

Query string not working while using attribute routing

I was facing the same issue of ‘How to include search parameters as a query string?’, while I was trying to build a web api for my current project. After googling, the following is working fine for me: Api controller action: [HttpGet, Route(“search/{categoryid=categoryid}/{ordercode=ordercode}”)] public Task<IHttpActionResult> GetProducts(string categoryId, string orderCode) { } The url I tried … Read more

Routing with multiple Get methods in ASP.NET Web API

From here Routing in Asp.net Mvc 4 and Web Api Darin Dimitrov has posted a very good answer which is working for me. It says… You could have a couple of routes: public static class WebApiConfig { public static void Register(HttpConfiguration config) { config.Routes.MapHttpRoute( name: “ApiById”, routeTemplate: “api/{controller}/{id}”, defaults: new { id = RouteParameter.Optional }, … Read more

Multiple actions were found that match the request in Web Api

Your route map is probably something like this in WebApiConfig.cs: routes.MapHttpRoute( name: “API Default”, routeTemplate: “api/{controller}/{id}”, defaults: new { id = RouteParameter.Optional }); But in order to have multiple actions with the same http method you need to provide webapi with more information via the route like so: routes.MapHttpRoute( name: “API Default”, routeTemplate: “api/{controller}/{action}/{id}”, defaults: … Read more