Web API: 404, 405

The following will trigger a 404:
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/v1/{controller}/{id}/{action}/{param}",
defaults: new { param = RouteParameter.Optional }
);
 
[AcceptVerbs("GET")]
public RespMessage NextCorpLoanProcessor(string myid)
{
...
}
 
 
The method input parameter should be named “id”, not “myid”. It should match {id}, specified in the route.

If you get an http status code 405 Method Not Allowed for a web API, you may be using the wrong HTTP verb. 

You may need to add attribute [AcceptVerbs(“GET”)] to your method name, especially if the name does not have a HTTP verb prefix.

[AcceptVerbs("GET")]
public RespMessage NextCorpLoanProcessor(string id)
{
...
}
 
 
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s