How it works...

If you start the server, accessing the /api-docs route will provide access to the main Swagger screen, as follows:

 Swagger produces a main page, with access to every route you defined

Interaction is easy: select an area, click on a given request, and you'll get the list of all routes and operations. Let's see, for example, how to get the regions for Uruguay. First, we must get a token, so we want to open the token area and enter the necessary user and password, as shown in the following screenshot:

 Doing a request is just a matter of filling the fields and executing the query

When the process runs, you'll get the answer, as shown in the following screenshot:

 A successful request returned the security token

You can see the equivalent curl request at the top, which matches what we did earlier in this chapter, in the Testing simple services from the command line section. Now, copying that token and pasting it into the /regions/uy endpoint means that we're ready to do that query:

 After getting a token, we can set up the query to get all of the regions of a country

All that's left to do is execute that query, and we'll get the desired results, as shown in the following screenshot:

 Doing sequences of calls is possible, and Swagger lets you experiment easily with different endpoints

What can we point out? First, obviously, Swagger is a very good tool, in terms of documentation. You can add descriptions to methods, parameters, results, and even include sample values and results. This means that developers who need to use your API will have a very good way of learning about how to use it. In terms of actually using your API, Swagger is simpler than curl or Postman, but it cannot chain operations, which you'll have to do on your own. You should really think about starting your development with this tool, and only moving forward with actual coding once you have everything documented; give it a try!

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset