You already know Postman sends requests. But what exactly happens between the moment you click "Send" and the moment you see results? Every single request travels through the same 6 stations — no exceptions:
📝Set UpBuild the request
→
🤖Pre-requestScript runs
→
🛵SendTo the server
→
🍕ResponseServer replies
→
✅TestsScript runs
→
🎉EndResults shown
🧒 The Story We'll Follow
Imagine you're ordering a pizza. You fill out an order form, a robot helper double-checks it before it leaves, a scooter delivers it to the kitchen, the kitchen sends back a pizza, the robot inspects it, and finally the results land on your table. That's the entire lifecycle. Now let's walk through each station!
The complete API execution lifecycle in Postman
🚉 Station-by-Station: The Full Journey
📝
STATION 1Set Up Request
You fill out the order form. This is where YOU do all the work:
🏠URLThe restaurant's address (the endpoint).
🔤MethodWhat you want: GET (read menu), POST (new order), PUT/PATCH (change order), DELETE (cancel).
✍️HeadersNotes on the form: "I'm a VIP" (Authorization), "I speak JSON" (Content-Type).
📄BodyThe actual order details (your JSON payload).
🤖
STATION 2Pre-request Script ⏰ RUNS BEFORE SENDING
Before your order leaves the table, a robot helper inspects it. This is JavaScript code you write in the Pre-request Script tab, and it can magically improve your request before it's sent:
📝 Fills in blanks — today's date, a random test email
🎫 Stamps a fresh VIP code — generates auth tokens
🧮 Does math — computes hashes, signatures, timestamps
📦 Sets variables that your request will use
PRE-REQUEST SCRIPT TAB · JAVASCRIPT
// 1. Add a fresh timestamp to every request
pm.variables.set("timestamp", Date.now());
// 2. Generate a random email for signup testing
const random = Math.random().toString(36).substring(2, 8);
pm.variables.set("email", "user_" + random + "@testmail.com");
// 3. Leave a note for debugging
console.log("Request prepared at:", new Date());
⚠️ Important Limit
The Pre-request script runs before any response exists — it can't read the response (there isn't one yet!). Its only job: prepare.
🛵
STATION 3Send API Request
The scooter ride! Postman packages everything (with any variables the robot just set) and sends it to the server. Under the hood, in a flash:
📖DNS LookupFind the server's address
→
🤝ConnectOpen a connection
→
🔒TLS HandshakeSecure the tunnel
→
📤RequestDeliver the goods
💡 Pro Tip
Hover over the Time value in Postman's response bar — it breaks the ride down into DNS, TCP, TLS, and waiting time. Great for finding why an API feels slow!
🍕
STATION 4Receive Response
The kitchen replies! The server processes your request and sends back three things:
The robot helper returns — this time to taste the pizza. Your Tests script (JavaScript) checks the response automatically:
TESTS TAB · JAVASCRIPT
// 1. Is it the right pizza? (status check)
pm.test("Status code is 200", () => {
pm.response.to.have.status(200);
});
// 2. Did it arrive hot? (speed check)
pm.test("Server responded in under 500ms", () => {
pm.expect(pm.response.responseTime).to.be.below(500);
});
// 3. Right toppings? (data check)
pm.test("Response has a title", () => {
const data = pm.response.json();
pm.expect(data.title).to.exist;
});
Every check shows up as PASS ✅ or FAIL ❌ — your API's homework gets auto-graded!
🎁 Hidden Superpower
The Tests robot can also save part of the response for later (like remembering your order number for dessert). That's called request chaining — we'll do it below!
🎉
STATION 6End — Results Displayed
The journey is complete. Postman shows you:
📊Response PanelStatus, time, size, body, headers.
✅Test Results TabAll your PASS/FAIL checks.
🖥️ConsoleEvery console.log from your robots.
And in the Collection Runner, your entire recipe book runs through all 6 stations automatically, one request after another! 🏃
🍔 The Script Sandwich (Memorize This!)
The easiest way to remember the execution order forever: a request is a sandwich, with scripts as the bread on both sides:
🤖 PRE-REQUEST SCRIPT — top bread (prepares the request)
🛵 REQUEST → 🍕 RESPONSE — the delicious middle (the main event)
✅ TESTS SCRIPT — bottom bread (verifies the response)
🤖 Pre-request Script
When: BEFORE the request is sent
Can see: The request only — no response exists yet
Job:Prepare — set variables, generate tokens & random data
Kid version: Robot checks your order form before it leaves
✅ Tests Script
When: AFTER the response arrives
Can see: Request AND response
Job:Verify — assert status, time, and body values
Kid version: Robot tastes the pizza and grades it
🔗 The Superpower: Chaining Requests Together
Here's where it gets really powerful — and this exact scenario is asked in interviews constantly. Real apps don't call one API; they call sequences: log in first, then use the token to fetch your profile.
Step 1 — Login request (POST /login). In its Tests tab, the robot saves the token from the response:
TESTS TAB OF THE LOGIN REQUEST
pm.test("Login successful", () => {
pm.response.to.have.status(200);
});
// Grab the token from the response and SAVE it
const data = pm.response.json();
pm.collectionVariables.set("token", data.token);
console.log("Token saved for the next request!");
Step 2 — Profile request (GET /profile). Just use the saved token with double curly braces:
HEADERS TAB OF THE PROFILE REQUEST
Key: Authorization
Value: Bearer {{token}}
🎤 Why This is Interview Gold
This pattern is called request chaining (or token chaining). The analogy: the kitchen gives you an order number with your pizza — your robot remembers it, and automatically shows it when you order drinks later. No re-explaining needed!
Advanced flex: mention pm.sendRequest() — it lets a pre-request script fetch a fresh token automatically before every request.
🖥️ Debugging: The Robot's Walkie-Talkie (Postman Console)
When something goes wrong, both robots can radio for help using console.log(). Open the console via View → Show Postman Console (or Ctrl+Alt+C) and you'll see every log, warning, and the actual request/response data — your #1 debugging tool in Postman.
WORKS IN BOTH SCRIPT TABS
console.log("Current environment:", pm.environment.name);
console.log("Response body:", pm.response.json());
🎤 The Interview Corner — 10 Questions & Crisp Answers
Q1What is the execution order of a request in Postman?
1) Request is set up, 2) Pre-request script runs, 3) Request is sent to the server, 4) Response is received, 5) Tests script runs, 6) Results are displayed. Mnemonic: Prepare → Travel → Verify (the Script Sandwich 🍔).
Q2What is a Pre-request Script?
JavaScript that runs before the request is sent. Used to set variables, generate dynamic data (timestamps, random emails), or fetch tokens using pm.sendRequest().
Q3What is a Tests Script and when does it run?
JavaScript that runs after the response arrives. It validates the response — status codes, response time, and body values — using pm.test() assertions.
Q4Difference between a Pre-request Script and Tests?
Pre-request runs before sending and can only see/modify the request (prepare). Tests run after the response and can see both request and response (verify). Tests can also save response data into variables for chaining.
Q5What is the pm object?
The Postman sandbox's JavaScript object — the robot's toolbox. It gives scripts access to the request (pm.request), response (pm.response), variables (pm.variables, pm.environment, pm.collectionVariables), and testing utilities (pm.test, pm.expect).
Q6How do you pass data from one request to another?
Request chaining: in the first request's Tests tab, save a value with pm.collectionVariables.set("token", data.token), then reference it in the next request as {{token}}.
Q7Where do you see console.log() output?
The Postman Console — View → Show Postman Console, or Ctrl+Alt+C. It shows logs, warnings, and full request/response details for debugging.
Q8What happens if a Pre-request script has an error?
The request is not sent — a failing pre-request script blocks execution. The error appears in the console. (A failing test, by contrast, doesn't block anything — the request already completed.)
Q9Can you send a request from inside a script?
Yes — pm.sendRequest() lets a pre-request script call another API (e.g., auto-fetch a fresh login token before each request). It's the key to fully automated auth flows.
Q10If a test fails, was the request still sent?
Yes — the request completed and the response was received; only the assertion failed (shown in red). But in CI/CD pipelines (Newman), failing tests fail the whole build, which is exactly how teams catch API bugs early.
📋 One-Glance Cheat Sheet (Screenshot This!)
Station
Who's Working
Superpower
📝 1. Set Up
You
Build the order — URL, method, headers, body
🤖 2. Pre-request Script
Robot (before)
Fill blanks, stamp tokens, set variables
🛵 3. Send
The scooter
DNS → connect → TLS → deliver
🍕 4. Response
The kitchen
Status code + headers + body
✅ 5. Tests Script
Robot (after)
Verify results, save data for the next request
🎉 6. End
Postman UI
PASS/FAIL results + console logs
🥇 The Golden Rule (say this in any interview)Pre-request = Prepare (before). | Tests = Verify (after).
Scripts are the bread, the request is the patty — the Script Sandwich! 🍔
🎬 Watch It in Action
Prefer video? Here's the full walkthrough of the API execution lifecycle in Postman:
🏁 Final Words
Every request you'll ever send in Postman follows this exact 6-station journey — Set Up → Pre-request → Send → Response → Tests → End. Once you internalize the Script Sandwich, questions about scripts, chaining, and debugging become free marks in any interview.
Join the discussion! Sign in with your Google or Blogger account, or comment as Anonymous - no account needed.
For quick questions, also reach me on Telegram @cytestch.
Comments
Comments
Post a Comment