Advanced dev
Testing Backend APIs with Postman

Customizing Requests in Postman

Learn how to make requests with custom headers, parmeters or payloads using Postman.

Setting Query Parameters

There are a couple ways of setting query parameters on a request in Postman. The most obvious way is to append the query string to the end of the URL, which will work as expected. The second way is clicking the Params button to the left of the URL field, which will presents additional text fields under the URL field to enter query parameters in key-value pairs. These parameters will automatically be added to the URL as they are typed, and the interface can help keep your parameters organized for requests that require a great number of query parameters.

Use a query parameter to filter articles on Conduit by tag.

Make sure the request method is GET and the request URL is https://conduit.productionready.io/api/articles

Press the Params button to the left of the URL field, and enter in tag as the key and dragons as the value. ?tag=dragons should then get appended to the request URL.

Press Send to fire off the request. The response should contain an array of articles, each with dragons included in the list of tags.

Constructing a POST request

Now that we're familiar with fetching data from a server using GET requests with Postman, let's go over how to make POST requests with a body payload. We'll be constructing a request to the Conduit application for authenticating a user. Before we begin, we'll need an existing account on Conduit.

Create an account on the Conduit demo app

The login endpoint for Conduit is https://conduit.productionready.io/api/users/login and the endpoint expects a JSON payload with a user object that contains an email and password.

Create a POST request that points to the Conduit login endpoint.

Change the request method to POST using the dropdown to the left of the URL field.

Use the following URL for the request:

https://conduit.productionready.io/api/users/login

Put your account credentials in to the body of the POST request.

In the Body tab of the request editor, select the raw option, and then select JSON in the dropdown that appears to the right of the options.

Put the following JSON payload in the text field for our body, replacing the example email and password with the credentials of the account made in the previously.

{"user":{"email":"hello@example.com", "password":"examplepassword"}}

Press Send to fire off the request. If the request is successful, we should see a user object returned to in the response that contains a JWT under the token field. We'll be using this token authenticated requests next.

Adding Headers to a Request

The Conduit application implements authentication using the Authorization header, where it expects a value of Token jwt.token.here for the header and then tries to validate the provided JWT. If the JWT is valid, the server uses the user specified within the JWT as the authenticated user. Requests that require authentication must have this header present with a valid token or else the server returns an error. The user endpoint in Conduit is an authenticated endpoint which returns the current user in the same format as the login endpoint. We'll need a JWT from a previous login request in order to make an authenticated request.

Create a request to fetch your profile from Conduit.

Change the request method to GET using the dropdown to the left of the URL field.

Use the following URL for the request:

http://conduit.productionready.io/api/user

Add an Authorization header to the request.

Go to the Headers tab below the request URL and add a new header with Authorization as the key and Token jwt.token.here as the value, replacing jwt.token.here with a token from a previous login request. Be sure to keep the space between Token and your JWT token.

Press Send to fire off the request. If you see a user object in the response that's similar to the login response, that means the request was successful!

In the next section, we'll go over how to use collections in Postman and import a collection of requests for the Conduit application into our client.