Outline
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.
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.
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.
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:
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.
Change the request method to GET
using the dropdown to the left of the URL field.
Use the following URL for the request:
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.