Now that we have created our API endpoints, we need to check whether they work properly or not. To do so, we will use Postman.
Postman is a collaboration platform for API development. Postman's features simplify each step of building an API and streamline collaboration so you can create better APIs—faster.
The Collaboration Platform for API Development. (n.d.). Retrieved from https://www.postman.com/
Caution: Before proceeding, make sure your server is running. If not, runnpm start
Let's try to test our get call where we ask for a list of the books:
We select GET as request method, and we enter the URL that we previously specified in our router. As a result of sending the request (by pressing the blue button Send), the server returns an empty array since our database has no books yet.
The next step is therefore to create a new book:
Since adding books is done through a POST method, we select that in Postman. Then, we specify the URL and we also provide the necessary data in the body. For that, we also have to make sure that we click on Body
, then raw
and finally select JSON
as format in the drop-down list whose text is highlighted in orange.
If we try to get the list of books again, the book should be displayed.
Finally, we can remove the book that we added. Note that we should add in the URL the ISBN of the book and select DELETE as the request method.