Monday, September 21, 2015

ASP.NET Web API Documentation using Swagger

Now the trend is APIs  and we need documentations for APIs to publish and share with teams for Apps and Application development. .NET comes with the in-build tool which have some challenges and not very impressive.

On the other hand, Swagger is a framework for describing, consuming and visualizing RESTful APIs. It keeps the documentation system, client and server code in sync always. We don't need to update manually and its fully automated.

Installing and configuring Swagger is simple, easy and no dependency. The following are the simple steps to enable API documentation in your ASP.Net site.

Step 1 : Install Swagger using Nuget package manager


Step 2 : Use Install-Package command to install Swagger



Step 3 : Step 2 adds a few changes in your project (updates web.config and adds a file "SwaggerConfig.cs" as shown in the figure)



Step 4 :  Minimal changes to enable Swagger and Swagger UI.



Step 5 : That's it. Now time to check the documentation. Use your application URL for your testing. Example "http://YourLocalhostURL/swagger/ui"



Step 6 : I changes some APIs with Swagger decorations as shown below.



Step 7 : Documentation for the Values Controller in Step 6


Enjoy API Programming and documentation.


No comments:

Post a Comment