API's are crucial part of any project now a days. Swagger is visualization tool for understanding API signature and functionality in real-time. Swagger is a language-agnostic specification for describing REST APIs. It allows both computers and humans to understand the capabilities of a service without any direct access to implementation (source code, network access, documentation). One goal is to minimize the amount of work needed to connect disassociated services. Another goal is to reduce the amount of time needed to accurately document a service.
Steps to implement swagger in .NET core
- From the Manage NuGet Packages dialog:
- Right-click the project in Solution Explorer > Manage NuGet Packages
- Set the Package source to "nuget.org"
- Enter "Swashbuckle.AspNetCore" in the search box
- Select the "Swashbuckle.AspNetCore" package from the Browse tab and click Install
- Add the Swagger generator to the services collection in the
Startup.ConfigureServices
method.
- Import the following namespace to use the Info class:
Startup.ConfigureServices
method.
- In the
Startup.Configure
method, enable the middleware for serving the generated JSON document and the Swagger UI
- Build and run the solution. Browse to Swagger URL now, which will be http://localhost:port/swagger. e.g. http://localhost:60212/swagger/
- You can dig into an api definition by clicking on it and try out by providing parameters required. e.g. in example below we can see what will be provided in POST call to create dealer.
- In the
Startup.Configure
method, enable the middleware for serving the generated JSON document and the Swagger UI
- Build and run the solution. Browse to Swagger URL now, which will be http://localhost:port/swagger. e.g. http://localhost:60212/swagger/
- You can dig into an api definition by clicking on it and try out by providing parameters required. e.g. in example below we can see what will be provided in POST call to create dealer.
No comments:
Post a Comment