#1 India's Top IT Training Institute
×

About Uncodemy

Know more about who we are and what we stand for.

About Us

About Us

Discover our mission to equip individuals with essential IT skills and industry expertise.

Read More →
UnCodeMy Gallery

UnCodeMy Gallery

Explore highlights from our IT training sessions and success stories.

Read More →
Mentors

Mentors

Meet the industry experts who train and guide you through your course.

Read More →
Free Resources

Free Resources

Free tutorials, interview questions, tools and calculators to help you learn.

Explore →
×

Free Resources

Learn, practice and plan your career — bilkul free.

Tutorials

Tutorials

Step-by-step written tutorials to learn any technology at your own pace.

Read More →
Free Counselling

Free Counselling

Book a free video counselling session and pick the right course for you.

Read More →
Online Compiler

Online Compiler

Write, run and test your code online — no setup required.

Read More →
Node.js & Express

Calling Endpoints Using Postman

Postman is a desktop and web tool for sending HTTP requests to an API and inspecting the responses. While you build an Express backend, it lets you test routes such as POST, PUT and DELETE without writing a frontend first. A browser address bar can only send simple GET requests, so a tool like Postman becomes essential as soon as your API accepts data.

Sending your first request

  1. Start your Express server, for example with node index.js, and note the port.
  2. In Postman, create a new request and choose the method from the dropdown (GET, POST, PUT, DELETE).
  3. Type the URL, such as http://localhost:3000/api/courses.
  4. Press Send. The lower panel shows the status code, the time taken, the response size, the headers, and the body.

Sending JSON in a POST request

To create a resource, switch the method to POST, open the Body tab, choose raw, and select JSON from the format dropdown. Postman then adds the Content-Type: application/json header automatically. Type a JSON object and send it.

// index.js - the endpoint being tested
const express = require("express");
const app = express();
app.use(express.json());   // parses JSON request bodies

const courses = [{ id: 1, name: "HTML Basics" }];

app.post("/api/courses", (req, res) => {
  const course = { id: courses.length + 1, name: req.body.name };
  courses.push(course);
  res.status(201).json(course);
});

app.listen(3000, () => console.log("API on port 3000"));

// Postman, Body tab, raw, JSON:
// { "name": "CSS Flexbox" }
//
// Expected response: 201 Created
// { "id": 2, "name": "CSS Flexbox" }

Reading the response properly

Look at the status code first. A 201 means the resource was created, 400 means your input was rejected, 404 means the route or item was not found, and 500 means the server crashed while handling it. Then check the body; the Pretty view formats JSON so nested objects are easy to read. The Headers tab helps when you are debugging content types, caching or authentication tokens.

Why req.body comes back undefined

The most common problem when testing POST routes is that req.body is undefined or empty. There are two usual causes, and they are often both present:

  • The server is missing app.use(express.json()), so Express never parses the body.
  • In Postman the body is set to Text instead of JSON, or sent as form-data, so the Content-Type header is wrong and the JSON parser ignores it.

Also watch for invalid JSON in the body editor. Single quotes or a trailing comma make express.json() reject the request with a 400 error before your route even runs. Postman underlines such mistakes in red.

Working faster with collections and variables

Save each request into a collection, grouped by resource, so you can rerun the whole set after every code change. Environment variables let you write URLs like {{baseUrl}}/api/courses; switching from a local environment to a deployed one then changes every request at once. You can also store an auth token in a variable and add it to the Authorization tab, rather than pasting it into each request.

Postman's Tests tab accepts small JavaScript snippets that check responses automatically, for example that the status is 201 and the body has an id. It is a gentle first step towards automated API testing.

Alternatives

The same requests can be sent with the command-line tool curl, with editor extensions such as Thunder Client or REST Client, or with similar apps like Insomnia. The concepts are identical: method, URL, headers and body.

Takeaway: choose the method, set the URL, send JSON as raw JSON so the content type is right, make sure the server uses express.json(), and read the status code before the body.

Ready to master real-world web development?

Learn HTML, CSS3, Bootstrap and JavaScript hands-on with mentor-led sessions.

Explore Course