DEV Community

Cover image for Using Postman to Test APIs
Marcos Freitas
Marcos Freitas

Posted on

Using Postman to Test APIs

I must confess it took me a bit to understand the functionalities and purposes of using Postman as a client to make non-GET requests. For some reason I did not see it as a testing app at first and kept using the browser as a client to run my backend API tests. In the browser you can run GET requests and get json data back in the URL or by fetching with chrome dev tools (option + command + J). There is also Curl, which is a client built in your machine terminal that can also fetch and get json data as response. However, it is more complicated and time consuming making other HTTP requests like a POST, PATCH, or DELETE in the browser other than with Postman. Adding more practice to using Postman, I came to understand it better and prefer to use it now to run my backend tests instead of the browser or curl.
In case you don't have Postman yet, you can download it in your platform at: https://www.postman.com/downloads/
While creating a web application with Rails, you need to take HTTP requests and return a json response that follows the idea of client-server communication. In case you forget your HTTP requests, paths, its controller actions, and what is used for you can check this website for references; https://guides.rubyonrails.org/routing.html.

See Postman request examples below:

GET request to show all

Index

GET request to show a specific id

Show

GET with id error status and message working

Show

POST request to create a new id

Create

PATCH request to update an id

Update

Last but not least a DELETE request to delete/destroy an id

Delete

Results that your id was successfully deleted.
You can either check with a Postman GET(index) request to see your last id or you can also close your terminal with (control + C) and in your project directory run (rail c) to run test and see if your updates worked and the data arrived. Then exit to leave your (rails c). A common mistake I did multiple times was to go back to my Postman after running tests with (rails c) and forgetting to open your rails server (rails s).

In conclusion, there are different clients (Browser, Curl, Postman) that you can use to run your backend APIs data to get a json response. And it is always up to the developer how they will run their tests depending on what they are more comfortable with using.

REFERENCES

https://www.postman.com/downloads/

https://guides.rubyonrails.org/routing.html

Top comments (0)