Swagger is yet another powerful API documentation tool .Microsoft has come up with easy integration methodology with WebAPi
It specifies the format (URL, method, and representation) to describe REST web services.
Earlier I used to use Fiddler for the same purpose. to do CRUD operations. using WEBAPI
or other alternative was to install RESTclient addon for firefox .
now Swagger UI provides more cleaner and efficient interactive API console for people to quickly learn about and try the API.
Now to do this you need to add references to your ASP.Net WebApi solution called SwashBuckle
from Nugets PM
now create your Model class as usual
public class Questions
{
[Key]
public int QuestionId { get; set; }
public string QuestionName { get; set; }
}
scaffold your controllers
public class QuestionController : ApiController
{
private QuestionContext db = new QuestionContext();
// GET api/Question
public IQueryable<Questions> GetQuestions()
{
return db.Questions;
}
}
now run the solution .
append swagger word to the url http://localhost:49775/swagger/
you will find Swagger UI
below is the example of GET by id method using Swagger
It specifies the format (URL, method, and representation) to describe REST web services.
Earlier I used to use Fiddler for the same purpose. to do CRUD operations. using WEBAPI
or other alternative was to install RESTclient addon for firefox .
now Swagger UI provides more cleaner and efficient interactive API console for people to quickly learn about and try the API.
Now to do this you need to add references to your ASP.Net WebApi solution called SwashBuckle
from Nugets PM
now create your Model class as usual
public class Questions
{
[Key]
public int QuestionId { get; set; }
public string QuestionName { get; set; }
}
scaffold your controllers
public class QuestionController : ApiController
{
private QuestionContext db = new QuestionContext();
// GET api/Question
public IQueryable<Questions> GetQuestions()
{
return db.Questions;
}
}
now run the solution .
append swagger word to the url http://localhost:49775/swagger/
you will find Swagger UI
below is the example of GET by id method using Swagger
No comments:
Post a Comment