Swagger in .NET Core APIs
Summarize and save time
- Add swagger generator to the service collection after services.AddMvc(); in ConfigureServices() method.
services.AddSwaggerGen(cย =>ย ย
{ย
ย ย c.SwaggerDoc("v1",ย newย Infoย {ย Titleย =ย "Myย API",ย Versionย =ย "v1"ย });ย ย
});
- Enable middleware to serve generated swagger as JSON endpoint afterย app.UseStaticFiles();
app.UseSwagger();
- Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.), specifying theย Swagger JSONย endpoint.
app.UseSwaggerUI(c =>ย
{ย
ย ย ย c.SwaggerEndpoint("/swagger/v1/swagger.json",ย "Myย APIย V1");ย ย
});
REPORT THIS AD
4. Setup completed now run the project. we are ready to go.
your local port number will different than mine, use your port number with slash swagger.
Click on try it out, by giving expected request parameters you will get response in response body section.
Summary
In this article, we learned. How to use swagger with .NET core web Api’s.
I have managed SEO and digital campaigns in several industries, but the industries that have really benefited have one thing in common; the traffic we are driving is the right traffic, and each rupee spent relates to an actual business goal. It is easy to rank for a keyword and get clicks, but the challenge comes in when we need to ensure that these visits convert, and the team knows from which medium the visit came. It is here where most "set and forget" campaigns fail, and it is here where we concentrate most of our efforts.