Importance of Web API documentation
Web API documentation is really very helpful when two different team (Back end and Front end) are working on project and not sitting together so in that scenario you will send your API information through mail or call. What kind of parameter request contain. If you are making any changes in your web API every time you have to inform through mail or call.
So solution of above problem is generate web API documentation web page.
When you create a web API, it is often useful to create web API document web page, so that other developers will know how to call your API. You could create all the documentation manually, but it is better to autogenerate as much as possible.
So let us start with demo.
Step 1: In this step we will create empty web API project. So open Visual Studio press CTRL + SHIFT + N as in the following image,
Now open the DemoController and add some documentation comments (that describe your method) to the controller methods like the following,
Step 5: Run the application, press F5 and type the url http://localhost:portno/help i.e. http://localhost:25316/help,
Click on post link you will see what parameters you have to pass. Here's the pic,
In same way you can see for all method.
Step 6: Suppose you want to hide all controller methods or particular method from document page then use the following code.
For hiding all controller method decorate the controller,
- [ApiExplorerSettings(IgnoreApi = true)]
- public class DemoController: ApiController {}
For particular method use the following code,
- public class DemoController: ApiController
- {
- private WebApiContext db = new WebApiContext();
-
-
-
-
-
- [ApiExplorerSettings(IgnoreApi = true)]
- public IQueryable < Student > GetStudents()
- {
- return db.Students;
- }
- }