Postman: Making API Testing Simple (and Fun)

Postman: Making API Testing Simple (and Fun)

Every full stack developer has had to write at least one curl command in their career, and I know the pain. Tell me if this sounds familiar:

“Did I include the right headers?”

“Which tag is for authentication?”

“Did I enter the url correctly?”

If you answered yes to any of these, then Postman is about to become your new best friend. 

What is Postman?

Postman is a powerful platform that makes it easy to build, test, debug and document API’s. No more writing out tedious curl commands by hand, Postman simplifies the request building process. It includes Collections to organize your requests, documentation features and a user-friendly UI.

A Quick Example: MyBricks API

To show you how Postman works, I’ll walk through testing my new project: MyBricks, an API I built for LEGO fans to organize their collections.

Step 1: Create a User

First we start by creating a new collection and adding our first request. Then we select what request method we need. We’ll hit the /user endpoint with a POST request to create a new user. Postman makes it easy to manage all of our request headers and body with tabs for each. Click the body tab and in a JSON format, enter the username, email, and password we’d like to use to create our new user. Once we have all that juicy data entered we hit send and watch the API magic happen. 

Article content
Creating a user

Congratulations you’ve made your first request to my new API using Postman! And we’ve got a new user to make further requests with! As you can see Postman shows us the JSON formatted response which includes a status code a message verifying the user was created along with an id associated with the user and the email address used. And here's the best part! With Postman we can save the response to our collection for reuse later! 

Step 2: Log In

Now that we have a user we need to login! Let’s build another request to login and get our JWT token so the API can authenticate us. Again, select the POST method and this time we’ll target the /login endpoint. In the body tab include the email and password we used last time. Hit send and we’ll receive our JWT token which is good for one hour. Then we’ll again save that response.

Article content
Logging in

Step 3: Add a LEGO Set to the Collection 

Finally I’ll show you how easy it is to include authentication tokens in your requests by adding our first LEGO set to our collection! In a new request target the /collection endpoint with the POST method. Then click the headers tab. We’ll find a few headers which Postman automatically includes. These headers are ones that your browser would send automatically as well so we can ignore those for now. In one of the empty key value spaces click on key and choose the Authorization header. This will tell the API that our user is logged in and  has access to secure endpoints which require authentication. In the value space enter Bearer and the key we received in the response of our previous request.

Article content
Including the Auth token

Then just like our other requests we’ll need to include some data in the body tab to tell the API which LEGO set we’d like to add to our collection as well as the quantity of that set. I’m a Star Wars superfan so we’ll enter the set number associated with the  massive 7,541piece LEGO Millennium Falcon with a quantity of one. Hit send one more time and you’ve added your first LEGO set to your collection!

Article content
Adding a set to the collection

And there you go! That’s how easy Postman makes building API requests as well as saving those responses for later use. I invite you to explore my swagger API documentation at https://mybricks.dev/api-docs/ and build more requests to create your own LEGO collection!

Why Postman Matters

While I was building myBricks, Postman saved me hours of troubleshooting. Instead of second guessing tedious curl commands, I could focus on the fun part, actually building the functionality of my API. Postman also makes it easy to export your collection complete with requests and example responses for use in API Documentation which I might get into in another post.

Wrapping Up

Postman has quickly become my go-to tool as a full stack developer. It’s user-friendly, powerful, and makes working with APIs fun! I invite you to try Postman and test out myBricks for yourself! Check out my swagger documentation at https://mybricks.dev/api-docs/ and build your own LEGO collection!

Sources:

Postman Learning Centerhttps://learning.postman.com/

FreeCodeCamp: Postman Beginner’s Guide - https://www.freecodecamp.org/news/postman-api-platform-explained/

Disclaimer: This post was not sponsored by Postman — I just really like the tool.

To view or add a comment, sign in

More articles by Tanner Saint

  • Hack Sprint Retrospective

    My group and I have just finished our Hack Sprint project for the end of T2 at Atlas School! This project was the first…

    5 Comments
  • Everything Is Object!

    During this module of my Python learning journey, I learned about how Python3 handles mutable and immutable objects and…

Others also viewed

Explore content categories