Webservices (ASMX and WCF) provided description of the services through WSDL. The WSDL file contains detailed information about the service in XML format including format of the messages, protocols used for the service etc. In ASP.NET Core WebApi project there is no user interface to obtained information about API and this context Swagger comes to the aid by providing a mechanism to visually present information about the WebApi.
The steps to include Swagger support in WebApi project include:
- Create a ASP.NET Core WebAPI project
- Add a reference to Nuget package Swashbuckle.AspNetCore
- In the Startup.cs file make the following modifications to ConfigureServices and Configure method
The IncludeXmlComments will show more descriptive information against each verb in WebApi and for this the comments should be generated out to an XML file and the build settings in the project will facilitate that as shown below:
- In the Debug tab on project properties window under Launch browser enter “swagger”
- Now run the WebAPI project and the Swagger UI will look like the one below: