In
this blog, we will discuss about web api documentation and will demonstrate
basic steps how to setup swagger in web api project and also show how to test web
api by submitting http request GET/POST/PUT via swagger UI.
Please read my previous blog when we discussed how
to create a web api in ASP.NET MVC Application and describe basic
steps to create an asp.net web api.
Swagger
is API developer tools for the Open API Specification (OAS), enabling
development across the entire API life cycle, from design and documentation, to
test and deployment.
Definition
-
“Swagger is a simple yet
powerful representation of your RESTful API. With the largest ecosystem of API
tooling on the planet, thousands of developers are supporting Swagger in almost
every modern programming language and deployment environment. With a
Swagger-enabled API, you get interactive documentation, client SDK generation
and discoverability.”
To add Swagger into WEBAPI
Project, you need to perform only 2 steps
2. Configure Swagger Config File
:
After package installed, you will find a new file
‘SwaggerConfig.cs’ under App_Start Folder
public class SwaggerConfig
{
public static void Register()
{
var thisAssembly
= typeof(SwaggerConfig).Assembly;
GlobalConfiguration.Configuration
.EnableSwagger(c
=>
{
c.SingleApiVersion("v1", "DemoWebAPI");
})
.EnableSwaggerUi(c
=>
{
c.DocumentTitle("Demo
Web API");
});
}
}
It
is done J
now build the web api
project and run it.
Browser http://localhost:65096/swagger
Swagger allows you to submit HTTP
request GET, HTTP POST, HTTP PUT against Web API
here is an an example
Submit HTTP GET Request For /api/Projects/{projectId}
Other swagger related posts:
Thanks for visiting!!
No comments:
Post a Comment