Skip to content
Tutorials Center
My learning

Topics

Lesson 7 of 30 ยท Sending Requests

Query params, headers and cookies

Master Postman's Params and Headers tabs: query and path variables, automatic and custom headers, content negotiation with Accept, and the cookie jar.

Almost every real request carries small pieces of extra information beyond the method and the body. Query parameters narrow down what you want, path variables pick one resource, headers describe the request, and cookies let a server recognize you between calls. Postman has a place for each of them, and knowing where they live (and what is added automatically) saves a lot of debugging.

The Postman screens are described in text, since they cannot run on this site. The runnable examples are stand-ins: local Node servers that echo what they receive, so you can watch each of these features work at the HTTP level. Real APIs behave similarly but add authentication, validation and their own rules.

Four ways to add information

Query params After the ?, to filter or sort.
Path variables Inside the path, like /users/42.
Headers Facts about the request.
Cookies Small values the server asks you to return.
1 / 2

Query parameters

Query parameters follow a ? in the URL, as key=value pairs joined by &:

TEXT
https://api.example.com/books?genre=fantasy&sort=year&limit=10

They usually filter, sort, search or paginate a list. In Postman, use the Params tab: each row has a key, a value and a checkbox, and the URL updates as you type. Some details worth knowing:

  • Values must be encoded: a space becomes %20 and an ampersand inside a value becomes %26. Postman encodes for you, so type the readable value in the table.
  • The same key may appear several times (tag=a&tag=b). Whether the API accepts that, and how it combines the values, is up to the API.
  • An unticked row stays in the table but is not sent, which is perfect for toggling a filter on and off.

Path variables

A path variable is a part of the path that changes, such as the id in /users/42/orders. In Postman you write it with a leading colon:

TEXT
https://api.example.com/users/:userId/orders/:orderId

Postman notices the :userId and :orderId parts and lists them in a Path Variables table below the query params. You type 42 and 7001 as the values, and the request goes to /users/42/orders/7001. Path variables identify which resource; query params describe how to list or filter it. Later, Environments and variables shows how to fill them from variables instead.

The first stand-in builds a URL the same way and sends it to a server that reports how it parsed the path and query.

Node.js Path variables and query params on the wire

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or process.stdin), it gets the next line from this box.

The & inside shipped & paid was encoded, so the server received the value intact. The repeated tag key arrived as a list, and the disabled debug row was never sent. The second request has no order part, so it does not match the path and gets a 404.

Headers

Headers are name/value pairs that describe the request. In Postman, open the Headers tab to add your own rows. You will also see a link to reveal hidden headers that Postman adds automatically. Typical automatic headers include:

  • Host, the server you are talking to.
  • User-Agent, which names the client (Postman identifies itself here).
  • Accept, usually */* unless you set it.
  • Content-Type and Content-Length, set from your body type and its size.
  • Accept-Encoding and Connection, which control compression and connection reuse.

You can override an automatic header by adding a row with the same name. Common custom headers you will add yourself are Authorization, X-Api-Key, Accept, If-None-Match (for caching checks) and API-specific ones such as a version header. Header names are case-insensitive; values often are not.

Content negotiation with Accept

A server may be able to give the same data in several formats. The client states what it can handle with the Accept header, and the server picks one and reports its choice in the Content-Type of the response. If it cannot satisfy the request, it may answer 406 Not Acceptable. The same idea applies to language (Accept-Language) and compression (Accept-Encoding).

The next stand-in is a /report endpoint that can answer in JSON, CSV or plain text, depending on Accept. It also reads a custom X-Api-Version header.

Node.js Content negotiation with the Accept header

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or process.stdin), it gets the next line from this box.

The same URL gave JSON, CSV and finally a 406, purely because of the Accept header. The custom X-Api-Version: 2 header travelled along and was reflected back. This is how many real APIs handle versions and formats, so always check the documentation for which headers are required.

A cookie is a small value the server asks the client to store and send back on later requests. A login endpoint typically answers with a Set-Cookie header, and the client returns it in a Cookie header on each following request, so the server recognizes the session.

How a cookie travels

  1. Log in
Send your credentials.
  1. Set-Cookie
Server replies with a session cookie.
  1. Stored
The client keeps it in a cookie jar.
  1. Cookie
Sent back on later requests.
1 / 2

Postman keeps a cookie jar, a store of cookies grouped by domain. When a response contains Set-Cookie, Postman saves it, and for later requests to the same domain it adds the Cookie header automatically. Click Cookies (below the Send button, next to the response area in many versions) to open the cookie manager, where you can view, edit and delete cookies per domain. This explains a common puzzle: a request works in one tab and fails in another because a cookie was deleted, or works when you did not expect it to because an old cookie is still stored. Scripts can also read cookies, which comes up in Writing tests with pm.test and Chai.

Many modern APIs use tokens in the Authorization header rather than cookies. Cookies matter mainly for APIs that serve browser sessions. They are still worth knowing, because they explain behavior that otherwise looks like magic.

The stand-in below has a /login endpoint that sets a cookie and a /profile endpoint that requires it. The client first calls /profile without a jar and is refused. After logging in, a tiny cookie jar stores the cookie and attaches it automatically, just as Postman would.

Node.js A tiny cookie jar

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or process.stdin), it gets the next line from this box.

The first /profile call has an empty jar and gets 401. The /login response contains Set-Cookie, which the jar stores. The final /profile call carries Cookie: session=abc123 without you adding it, and succeeds. Note that the jar here ignores Path, HttpOnly and Max-Age; a real jar, such as Postman's, respects them.

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. How do you write a path variable named orderId in a Postman URL?

    A leading colon marks a path variable. Postman lists it in a Path Variables table where you enter the value.
  2. 2. A server can return JSON or CSV. Which request header asks for CSV?

    Accept states the formats the client can handle. Content-Type describes the body being sent.
  3. 3. Your request works in one Postman tab but fails in another to the same domain after you cleared cookies. What is the likely cause?

    Cookies are stored per domain and added automatically. If the session cookie is gone, the server no longer recognizes you.
  4. 4. What does an unticked row in the Params table do?

    Disabled rows are kept for convenience but are left out of the request.
  5. 5. A server answers 406 Not Acceptable. What is the most likely reason?

    406 means the server cannot produce a representation matching the client's Accept header.

Summary

  • Query parameters filter and sort (?genre=fantasy&limit=10); the Params tab edits them as a table and encodes special characters for you.
  • Path variables use a leading colon (/users/:userId) and get their own table, which identifies which resource you want.
  • Postman adds hidden headers automatically; add a row with the same name to override one.
  • Accept requests a response format, and Content-Type on the response says what you got; 406 means no match.
  • Cookies are set with Set-Cookie, stored in a per-domain cookie jar and sent back with Cookie.
  • Clearing or editing cookies in the cookie manager can change how requests behave.
  • The servers and the cookie jar here are stand-ins that model the behavior; real APIs and Postman's own jar are richer.

Next: Authentication: API keys, Basic, Bearer and OAuth 2.0.