Swagger for WebApi
Swashbuckle
- Swagger for WebApi
Recently I had faced issue while working with large team; more or less currently, we are targeting our application architecture as SOA/ Rest. While doing so we sometimes face issue related to documentation for method/api action part and keep trailing for input/ output signature for the entity to implement. Therefore, I thought to write a step to ease this problem with proper documentation and API explorer
Swagger
Swagger is a unique
technique to represent RESTfull Web API. We can configure Swagger in web application.
It’s easy to use and integrate inside our MVC WebAPI project.
In other words, we can say,
Swagger is technique, which enable cross team / Dev/UX to seamlessly work with
integrated environment without any hurdle, which includes each and everything
from the front-end user interfaces.We can say this is API management solutions.
Command
Options
Via Solution
Right click on Solution =>click on
"Manage NuGet Packages" and search "swagger"
Via PMC
PM>Install-Package
Swashbuckle -Version 5.6.0
Setting to default swagger UI as output
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
// Web API
configuration and services
// Web API
routes
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
name: "swagger_root",
routeTemplate: "",
defaults: null,
constraints: null,
handler: new RedirectHandler((message => message.RequestUri.ToString()), "swagger"));
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
}
}
Run
the solution
Multiple option to test /
check you function with parameters from web pages.
Swagger for WebApi
Reviewed by Rupesh
on
21:15
Rating:
No comments: