Configure Swagger UI in Asp.net Core Web API

Documentation is very much important when Web.API has been exposed for public access. A clean documentation gives a more helpful to integrate APIs.Today, we are going to discuss and implement simple yet powerful API documentation library that's definitely going to help you to make your works easy.

What is Swagger?

Swagger provides rich documentation and seamless API testing experience to developers. It is a open source framework backed by a large ecosystem of tools that helps you design, build, document, and consume your RESTful APIs. Swagger UI allows anyone — be it your development team or your end consumers — to visualize and interact with the API’s resources without having any of the implementation logic in place. It’s automatically generated from your Swagger specification, with the visual documentation making it easy for back end implementation and client side consumption.

Once the service is configured, navigate to Configure method to add below codes. Here, app.UseSwaggerUi() will set up the dashboard http://<website-url>/Swagger/ui, and app.UseSwagger() will enable middleware to serve generated Swagger as a JSON endpoint.

After running the web API application, append the swagger ui url and you will be presented with a page similar to this.
The page contains list of the controllers and API methods available publicly and allows to execute different method straight through the browser. Here we have ValuesController along with it's all API methods. A different colors are used to identify different HttpVerb API methods. Expanding an API by clicking on it will gives you a unique testing experience.

Configure Swagger UI url

Be default Swagger set http://<website-url>/Swagger/ui to access the UI. It's easy to configure your custom url.