انتقل إلى المحتوى
أمين أبوزيد
منشورBEG-053-L03

جولة في Postman

  • الدرس 3 من 6
  • 10 دقيقة قراءة
  • مبتدئ
في هذا الدرس 11 موضوعات

هذا الدرس متاح حاليًا باللغة الإنجليزية فقط، ولم تُنشر نسخته العربية بعد.

Lesson Overview

So far you have read requests and responses on the page. Now you will send them. In the restaurant picture, Postman is a practice table with a friendly waiter: you fill in an order form (method, URL, parameters), press a button, and the full answer comes back, laid out neatly.

Postman is a desktop and web application for building and sending HTTP requests and inspecting responses. Backend developers use it daily to try an API before writing code against it, and to check their own API while building it.

This lesson is a guided tour of the few parts you need: the request builder, the response pane, saved requests in a collection, and variables so you do not retype the host. It prepares the lab, where you will export a collection.

Because Postman is software that changes, this lesson names concepts and typical places on the screen. Menus and button positions differ between versions and between the desktop and web apps. If a label does not match your screen, look for the same idea nearby or check Postman's documentation (linked in References).

This lesson builds on Lessons 1 and 2 (APIs, resources, methods, status codes) and on Module BEG-052 (URLs, query parameters, headers, JSON).

Learning Objectives

By the end of this lesson you will be able to:

  • Create and send a GET request in Postman and find the status code and body in the response.
  • Add query parameters with the Params tab and understand how they change the URL.
  • Say where headers and a body go for a POST request.
  • Save a request in a collection and say what a collection is for.
  • Use a variable such as {{baseUrl}} in a URL.
  • Describe how a collection is exported as a file for sharing.

Written Explanation

Getting started

You can use Postman as a desktop app or in the browser. Creating an account is optional for some uses and required for others, and the sign-in options change over time, so follow Postman's own start-up screens. This course does not need any paid feature. If you prefer not to sign in, look for a lightweight or scratch-pad mode in your version; if none is offered, signing in with an account you control is a normal step.

Whenever you start a task you will open a new request tab. Everything below happens in that tab.

The request builder

Postman's documentation describes the steps for a request in this order:

  1. Set the method and URL. The method defaults to GET. Pick another from the drop-down (POST, PUT, PATCH, DELETE) and type the endpoint address next to it.
  2. Add query parameters. Type them in the URL, or use the Params tab, which shows each one as a key and value row.
  3. Add headers, body, and authorization. Headers go in the Headers tab; a body goes in the Body tab; credentials, if an API needs them, go in the Authorization tab.
  4. Send. The Send button submits the request.
  5. Read the response. The response pane shows the result.
  6. Save the request, optionally into a collection.

Think of it as an order form with labeled boxes. Everything you learned in Module BEG-052 appears in a box.

Params tab and the URL

The URL bar and the Params tab are two views of the same thing. If you type https://dummyjson.com/products?limit=2 into the bar, the Params tab shows a row with key limit and value 2. If you add a row select with value title,price, the URL bar updates to ...?limit=2&select=title,price. Use whichever you find easier. The Params tab is handy when values are long or you want to switch parameters on and off with a checkbox.

Headers and body

For a GET you rarely need anything here. For a POST or PUT that sends JSON you need two things:

  • In Headers, a Content-Type header with the value application/json. (Postman often adds this for you when you choose a JSON body type; open the headers list and check, since automatically added headers may be hidden by default.)
  • In Body, choose the raw option and the JSON type, then type the JSON text.

The header tells the server how to read the body. A body without the right Content-Type is a classic reason for a 400 or 415 response.

The response pane

After Send, look for:

PartWhat it tells you
Status (such as 200 OK)Whether the request worked. Read this first.
BodyThe data, usually JSON, shown "pretty" (indented) or "raw"
HeadersThe response headers (for example Content-Type)
Time and sizeHow long it took and how large the answer was (shown near the status in most versions)

Postman also lets you search the body, or filter JSON with JSONPath, which is useful with large answers.

Collections

A collection is a saved group of requests that you can organize, find again, and share. Naming requests clearly ("List products", "One product", "Search") turns a collection into living documentation of an API. The collection format is a portable, open file format that people and tools can read.

To save: use the Save control on a request, give it a name, and choose or create a collection. To export a collection as a file, Postman's documentation says to open the collection's actions menu (the three-dot icon), choose the export option under More, and start the JSON download from the dialog. A teammate can then import that file into their own Postman. Menu names move between versions, so look under the collection's actions menu.

Variables

Typing https://dummyjson.com into twenty requests is tiring, and changing it later is worse. A variable stores a value once. You reference it with double curly braces. If a variable baseUrl holds https://dummyjson.com, then the URL {{baseUrl}}/products is sent to https://dummyjson.com/products.

Postman has different scopes of variables. A collection variable is available to every request in that collection. An environment variable belongs to an environment (for example "local", "test", "production"), and only one environment is active at a time. For this module, a collection variable named baseUrl is enough. Later, when your own API runs on localhost during development and on a server in production, environments let you switch the host with one click.

Examples

Example 1: Simple. One GET request

Steps in Postman:

  1. Open a new request tab. The method is GET.
  2. Enter https://dummyjson.com/products/1.
  3. Press Send.
  4. Look at the response pane: the status should read 200 OK, and the body should be a JSON object for product 1.

The same call from a terminal, trimmed with the API's select parameter so the answer fits here:

bash
curl -s "https://dummyjson.com/products/1?select=title,price"
json
{"id":1,"title":"Essence Mascara Lash Princess","price":9.99}

Postman shows the same JSON, only prettier and with the status displayed as a label.

Example 2: Practical. Params and variables

Goal: list two products, titles and prices only.

  1. In the collection, add a variable baseUrl with the value https://dummyjson.com.
  2. New request. URL: {{baseUrl}}/products.
  3. In the Params tab add limit = 2 and select = title,price.
  4. Check that the URL bar now reads {{baseUrl}}/products?limit=2&select=title,price.
  5. Send. Expect 200 OK and a body with a products array of two items.

The equivalent with the full URL:

bash
curl -s "https://dummyjson.com/products?limit=2&select=title,price"
json
{"products":[{"id":1,"title":"Essence Mascara Lash Princess","price":9.99},{"id":2,"title":"Eyeshadow Palette with Mirror","price":19.99}],"total":194,"skip":0,"limit":2}

Save this request as "List products (limit 2)".

Example 3: Realistic. POST with a JSON body and a planned 404

Part A: POST. DummyJSON's documentation describes POST /products/add as a way to add a product, with one important note: the call only simulates the add and does not store anything on the server. That makes it safe for practice.

  1. New request, method POST, URL {{baseUrl}}/products/add.
  2. Headers: Content-Type = application/json.
  3. Body: raw, JSON: {"title":"Dune"}.
  4. Send.

Real result when we ran the same request from a terminal:

text
HTTP/1.1 201 Created
...
{"id":195,"title":"Dune"}

Notice 201 Created, the status from Lesson 2, and a new id. If you then GET /products/195, you will find nothing, because nothing was really stored. That is the API being a practice sandbox, not a bug in your request.

Part B: a planned 404. Change the URL to {{baseUrl}}/produkts (a typo) and send a GET. Real result from the terminal: the first line is HTTP/1.1 404 Not Found. This API returns an HTML "page not found" page for an unknown path, so the body is not JSON. Fix: reread the documentation, correct the path to /products, send again, and see 200 OK. A 404 on a documented endpoint most often means a wrong path or a missing item.

Backend Insight

You will use a tool like Postman for the rest of your career. When you build your own API in the Junior level, you will test every endpoint with a request tab before any other client exists. A saved collection becomes a regression checklist: after each change, send the requests again and compare statuses. Exported collections also go into team repositories and onboarding guides, because a working example is worth pages of text.

One caution: collections and environments can contain secrets such as tokens. Do not share a file or publish a collection without checking for credentials first. The APIs in this module need none.

Common Mistakes

  • Typing params into the URL and also in the Params tab with different values. They are the same list; edit one place.
  • Forgetting the Content-Type header (or the JSON body type) on a POST. The server may reject the request or misread the body.
  • Reading the body before the status. Always check the status code first.
  • Variable name typos, such as {{baseurl}} instead of {{baseUrl}}. Names are matched exactly, so the request will be sent with the placeholder unresolved. Check that the variable is highlighted as found.
  • Leaving secrets in a shared collection.
  • Assuming a practice API stores data. Check the documentation: some only simulate writes.

Exercises

Level A: Foundation

  1. In your own words, what is a Postman collection for?
  2. Which tab holds query parameters, and which holds the JSON body?
  3. Where do you look first in the response, and why?

Level B: Application

  1. In Postman, create a GET request for https://dummyjson.com/products/3?select=title,price and send it. Write down the status and the body.
  2. Create a collection variable baseUrl and rewrite the request from exercise 4 as {{baseUrl}}/products/3. Add select through the Params tab. Confirm that you get the same answer.
  3. Send GET {{baseUrl}}/products/99999. Write down the status and what the body says. Is it an error in your request?

Level C: Challenge

  1. Build a request that lists the first five products sorted by price, cheapest first, showing only title and price. Use this API's documented sortBy and order parameters in the Params tab, and write the final URL you see in the bar.
  2. Explain in four or five sentences how you would hand your finished collection to a classmate, and name two things to check in it before you do.
أظهر الحلول
  1. It is a saved, named set of requests that you can reorganize, rerun, and share.
  2. Query parameters go in the Params tab; the JSON body goes in the Body tab (raw, JSON), with a Content-Type: application/json header.
  3. The status code, because it says whether the request succeeded, and tells you how to read the body.
  4. Status 200 OK. At the time of writing the body is {"id":3,"title":"Powder Canister","price":14.99}. If your data differs, the shape (id, title, price) should still match.
  5. With baseUrl set to https://dummyjson.com the request resolves to the same URL and gives the same answer. If you get an error mentioning an unresolved variable, check the name and that the collection is selected.
  6. 404 Not Found. For this API the body is a JSON message saying that product 99999 was not found. No, the request is well formed; the item simply does not exist, which is exactly what 404 means.
  7. The URL should look like {{baseUrl}}/products?limit=5&sortBy=price&order=asc&select=title,price. The sortBy and order parameters are documented for this API; the first row should have the lowest price shown.
  8. Export the collection through its actions menu as a JSON file and send the file; the classmate imports it. Before sending, check that it contains no tokens or passwords, and that the requests have clear names. Also tell them which variables (like baseUrl) it relies on.

Mini Challenge

Build a collection called "Products explorer" with a collection variable baseUrl and four named requests: list with limit, one item, search (the API documents GET /products/search?q=...), and a deliberate wrong path that returns 404. For each request, write the status you got next to its name in the request description.

Summary & Next Lesson

Key takeaways

  • Postman builds, sends, and shows HTTP requests: method, URL, params, headers, body.
  • The URL bar and the Params tab are two views of the same query string.
  • For JSON bodies: a Content-Type: application/json header plus a raw JSON body.
  • Read the response status first, then the body.
  • A collection is a saved, shareable set of requests; export it as a JSON file.
  • {{baseUrl}} style variables stop you repeating the host.

Next lesson

In "curl from the terminal" you will send the same requests without any graphical tool, and learn the few options used in documentation everywhere.

Self-check

  1. What does {{baseUrl}} do?
  2. Why add Content-Type: application/json to a POST with a JSON body?
  3. Which part of the response do you read first?
  4. What does a collection let you do besides saving?
  5. Why check a collection before sharing it?
أظهر الإجابات
  1. Postman replaces it with the stored value of the variable baseUrl when the request is sent.
  2. It tells the server how to read the body.
  3. The status code.
  4. Organize, rerun, and share requests (including by exporting a file).
  5. It may contain secrets such as tokens, and it should have clear names and no accidental personal data.

References

  • Postman Docs, Request basics. Supports the order of steps: method and URL, params, headers/body/auth, Send, response pane, save.
  • Postman Docs, Collections overview. Supports the description of a collection and its portable format.
  • Postman Docs, Export data from Postman. Supports the high-level export steps (actions menu, More, export, JSON download); exact labels vary by version.
  • Postman Docs, Variables. Supports {{name}} references and the collection and environment scopes.
  • DummyJSON, Products documentation. Documents the endpoints, limit, select, search, sorting, and that add, update, and delete are only simulated. Real outputs were produced with curl, not Postman, since the app was not run for this lesson; on-screen layout of Postman is described in general terms and not verified.
  • The 201 and 404 meanings are from the MDN pages 201 Created and 404 Not Found. The claim that a missing Content-Type often causes 400 or 415 is common practice, not verified on a specific page.

التطبيق

طبّق هذا الدرس بمختبر الوحدة وتمارينها واختبارها.

المختبر والتمارين الاختبار

تعليم الدرس كمكتمل اختياري ويمكنك التراجع عنه في أي وقت. يبقى تقدمك محفوظًا في هذا المتصفح.

اكتب للبحث في المستويات والمراحل والوحدات والدروس.