I've created a RESTful web service using ASP.NET WebApi v2 and I'm using Swashbuckle to generate swagger UI for API documentation.
All API calls are under http://localhost/api/ and the swagger UI page is at http://localhost/browser/index (the 'browser' part is configurable).
Browsing to http://localhost/ however will land on a empty page, so my question is is it possible to route http://localhost/ to http://localhost/browser/index so the user will be able to see the API documentation just by visiting the base uri.
One solution I can think of is to use a physical file system and create a static html page which does a meta fresh to redirect to the landing page I want, but I guess there must be a better way of doing this…
The default route template for Web API is "api/{controller}/{id}". In this template, "api" is a literal path segment, and {controller} and {id} are placeholder variables.
By default Web API returns result in XML format.
You can easily find the Web API addresses and version number for your deployment in the Customer Engagement web application by navigating to Settings > Customization > Developer Resources.
Change the route configuration RouteConfig.cs
.
Instead of the default setting:
routes.MapRoute( name: "Default", url: "{controller}/{action}/{id}", defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } );
Change it to point at swagger:
routes.MapRoute( name: "Default", url: "{controller}/{action}/{id}", defaults: new { controller = "Browser", action = "Index", id = UrlParameter.Optional } );
Make sure you update RouteConfig.cs
and not WebApiConfig.cs
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With