DavidSpot Blog

Developer, super curious, a dog lover, sports fan and techie guy


Swagger.NET - Powerful Web API Documentation

If you are a Web Developer and you're working on aweome and powerful RESTFull API that does wonders but you're struggling on way to create a documentation there are some great tools available out there.

You may use the HelpPage nuget package and that's pretty good one, but not as complete as the Swagger.

It's easy to use so in this post I decided to add documentation using Swagger for a simple ASP.NET Web API project which contains a single controller with different HTTP methods

You can see a live demo API explorer here, and the source code can be found on GitHub. The final result for the API explorer will look as the image below:


Swagger is language-agnostic so there are different implementations for different platforms. For the ASP.NET Web API world there is a solid open source implementation named “Swashbuckle

Let's start...

Step 1 - Install Swashbuckle Nuget package

Install Nuget package by opening NuGet Package Manager Console and install the below package:


When the installation ends you can see a new class named swaggerconfig.cs inside your folder App_Start


Step 2 - Enable generating xml docs

Next right click in you your project (in my case WebApplication1) and select properties


When you are in the project properties select the build tab and then check the box that says XML documentation file and build your solution.

And that's it... to see your new REST API Documentation simply hit F5 and navigate to http://yourhost/swagger and voilá (in my case the url is http://localhost:56593/swagger)

Happy coding.