Postman Setup & API Testing for Your NestJS Blog (Beginner‑Friendly Guide)
As a former 3D Animator with more than 12 years of experience, I have always been fascinated by the intersection of technology and creativity. That's why I recently shifted my career towards MERN stack development and software engineering, where I have been serving since 2021.
With my background in 3D animation, I bring a unique perspective to software development, combining creativity and technical expertise to build innovative and visually engaging applications. I have a passion for learning and staying up-to-date with the latest technologies and best practices, and I enjoy collaborating with cross-functional teams to solve complex problems and create seamless user experiences.
In my current role as a MERN stack developer, I have been responsible for developing and implementing web applications using MongoDB, Express, React, and Node.js. I have also gained experience in Agile development methodologies, version control with Git, and cloud-based deployment using platforms like Heroku and AWS.
I am committed to delivering high-quality work that meets the needs of both clients and end-users, and I am always seeking new challenges and opportunities to grow both personally and professionally.
1) Install Postman
Go to postman.com/downloads.
Download the installer for your OS (Windows/macOS/Linux).
Install and open Postman. If you’re prompted to sign in, you can choose “Use the lightweight API client” to skip account setup.
Tip: Keep Postman updated—it ships frequent improvements to the client and testing features.
2) Start your NestJS app (local)
In your project folder:
npm run start:dev
By default, NestJS serves on http://localhost:3000 (unless you changed the port in main.ts).
3) Create a Postman Environment
Environments let you avoid hard‑coding URLs/tokens.
Create a new environment named “Local (Nest Blog)” with variables:
base_url→http://localhost:3000token→ leave empty for now (we’ll set it after login)
You’ll reference variables like this: {{base_url}} and {{token}}.
Switch the active environment (top‑right environment selector in Postman).
4) Create a Collection for your API
Click Collections → New Collection and name it “Blog API (Local)”. Inside it, create folders:
Auth (login, refresh)
Users
Posts
Tags (later)
We’ll add requests to these folders as we build features.
5) Your first request (GET /)
In the Blog API (Local) collection, add a request:
Method: GET
URL:
{{base_url}}/Click Send → you should see the default Hello World JSON/string from your Nest app.
6) Working with routes: params & query
A. List posts with pagination
Method: GET
URL:
{{base_url}}/posts?limit=10&offset=0Save it as Posts → List posts.
B. Posts by author (path param)
Method: GET
URL:
{{base_url}}/posts/author/:authorId
In Postman, click Params → Path Variables and setauthorIdto42. Save as Posts → Posts by author.
7) Sending JSON bodies (create & update)
Always set the header Content-Type: application/json when sending JSON.
A. Create a post
Method: POST
URL:
{{base_url}}/postsHeaders:
Content-Type: application/json,Authorization: Bearer {{token}}(optional until auth is added)Body → raw → JSON
{
"title": "My first NestJS post",
"description": "Hello, world!",
"authorId": 42
}
Save as Posts → Create post.
B. Replace a post (PUT)
Method: PUT
URL:
{{base_url}}/posts/:id(setidpath variable)Body (full resource): send the complete post object.
C. Partially update a post (PATCH)
Method: PATCH
URL:
{{base_url}}/posts/:idBody (partial)
{
"title": "Updated title only"
}
D. Delete a post
Method: DELETE
URL:
{{base_url}}/posts/:id
PUT vs PATCH: PUT replaces the entire resource; PATCH updates selected fields.
8) Headers & Authorization (Bearer JWT)
As we add auth later, most endpoints will require a token. In requests that need auth, include:
Authorization: Bearer {{token}}
You can set this in the request’s Headers or in the Authorization tab (Type: Bearer Token → {{token}}).
Auto‑inject the token for the whole collection
In the collection Authorization tab, set Type = Bearer Token and Value = {{token}}. Child requests inherit this, so you don’t have to repeat it.
9) Save the token automatically after login
When you implement POST /auth/login (later), have it return a JSON like:
{ "access_token": "<jwt>" }
In the Tests tab of your Auth → Login request, add:
pm.test('status is 200', function () {
pm.response.to.have.status(200);
});
const data = pm.response.json();
if (data && data.access_token) {
pm.environment.set('token', data.access_token);
}
Now, once you log in, Postman saves {{token}} to the environment automatically.
10) Add lightweight tests to any request
Open the Tests tab and paste checks like:
pm.test('response is JSON', function () {
pm.response.to.be.json;
});
pm.test('request succeeded', function () {
pm.expect(pm.response.code).to.be.oneOf([200, 201]);
});
pm.test('responded quickly', function () {
pm.expect(pm.response.responseTime).to