How to Test API Endpoints with Postman

Lilly O.
4 min readJul 23, 2020

--

Whether you’re building your own API or using a third-party API in your project, it’s useful to be able to test API requests. You can make an API request directly in the command line, but Postman provides an easy-to-use interface that makes it simple to test APIs.

Intended for Postman beginners, this article will walk through how to make your first two API requests on Postman.

What you’ll need

Overview

We’ll make two calls to an API, a GET request and. a POST request.

For these examples, we’ll use JSONPlaceholder, a placeholder REST API that is useful for testing and prototyping in web development projects.

The specific resource we’ll use is the /posts API endpoint:

https://jsonplaceholder.typicode.com/posts

Open up the Postman desktop application and let’s get started!

Making a GET request

Select the GET method and enter the API request URL:

We can leave the Params and other settings alone for the GET request. We don't need to send any additional information for this request. We just want to retrieve the data.

Hit Send to get back the response:

Under the Body section, you can see the response from our GET request. We see the JSON response, and can scroll through to review the response.

We also see the request was successful with Status: 200 at the top. If there was an issue with the request, we would see a different HTTP status code and would not receive the expected data in the response body.

Making a POST request

When we make a POST request, we need to include the data we want to send to the server. The POST method will create a new resource with that information.

The data we send in a POST request is typically referred to as the request body.

Select the POST method and enter the API request URL:

Before we hit send, we need to add the request body.

Select Headers. Here we see a number of auto-generated headers.

Deselect the auto-generated Content-Type header.

At the bottom of this section, enter Content-Type as a new key and the following as its value: application/json; charset=UTF-8.

Now that we’ve set the Content-Type header, we need to add the request body.

There are two ways we can add the request body:

  • Add the body as raw JSON
  • Add the body in the x-www-form-urlencoded format

You can choose either option, but we will walk through both options below.

Select Body, then the raw radio button. Here, we can add the raw JSON that comprises our request:

{
"title": "New Blog Post",
"body": "This is a new blog post placeholder test.",
"userId": 1
}

The other option is to select x-www-form-urlencoded and enter the data as key-value pairs:

After you’ve added the request body, hit Send and view the response below:

We know the request succeeded with Status: 201 Created in the upper right corner. We see the response body that has just sent back the new post we created.

If the request failed, we would see an error message and an HTTP status code that we can use to troubleshoot.

Summary

We have just made a GET request and a POST request to an API endpoint using Postman.

From here, feel free to try making other requests such as PATCH, PUT, DELETE.

While we used a placeholder API in this article, Postman can come in handy when building your own API or integrating data from an external API into your application.

If we want to call an external API in our application, we can make a GET request in Postman to see how the data is structured in the response. We can then use that information to help us determine how to retrieve, store, and display data in an application.

If we are developing our own API server, we can make requests to our endpoints in Postman to see if the backend routes are working as intended.

This article only touches the surface of how developers can use Postman. The Postman documentation is a great resource to explore more features and use cases.

← Back Home

--

--