Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET Web API Help Page package does not get all api endpoints

I installed ASP.NET 4 Web API Help Page package via nuget to my Web Api project. For some reason it does not display all the api endpoints. I have the documentation set to use XML. Not sure why this is happening, any help is appreciated.

Here is an example controller

    public class ProductController : BaseController
    {
        // GET api/Product/Get/5/43324
        [AcceptVerbs("GET")]
        public ApiProduct Get(int id, [FromUri]int productId)
        {
             //// logic
        }
   }

routes

config.Routes.MapHttpRoute(
                name: "api-info",
                routeTemplate: "api/{controller}/{action}/{id}",
                defaults: new { id = RouteParameter.Optional, action = RouteParameter.Optional }
            );

Thanks

like image 825
tmjam Avatar asked Jun 28 '13 17:06

tmjam


Video Answer


2 Answers

I figured out the issue, the problem here is, In Web API there is no action and methods are mapped to the verb and arguments directly, Updating my route to this fixed the problem and all the routes show up.

config.Routes.MapHttpRoute(
                name: "apsi-info",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
            );
like image 194
tmjam Avatar answered Sep 18 '22 03:09

tmjam


If the above solution doesn't solve your problem - take a look and make sure you aren't defining BOTH the AcceptVerbs attribute and its shortcut:

public class ProductController : BaseController
{
    // GET api/Product/Get/5/43324
    [AcceptVerbs("GET")]
    [HttpGet]
    public ApiProduct Get(int id, [FromUri]int productId)
    {
         //// logic
    }

}

Remove one of them and it should work.

like image 43
Forty3 Avatar answered Sep 21 '22 03:09

Forty3