Open In App

Structure of HTTP request in Postman

Last Updated : 11 Jan, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

Postman is a powerful tool that simplifies the process of making HTTP requests for testing APIs. Understanding the structure of a typical HTTP request in Postman is fundamental for everyone who want to test endpoints. In this article, we’ll break down the key components of an HTTP request in Postman in simple terms.

Prerequisite:

Structure of HTTP request includes:

  • Request Method
  • Request URL
  • Headers
  • Request Body
  • Query Parameters

1. Request Method:

The request method defines the type of action you want to perform. In Postman, you’ll encounter methods like GET, POST, PUT, and DELETE. They are used to fetching data, creating something new, updating, or deleting.

request-method

Request method

2. Request URL:

The Request URL is like the address of the destination(endpoint) you want to interact with. It’s the location of the API endpoint where you’re sending your request. In Postman, you input the URL in the address bar at the top, specifically the server and the specific route you want to hit.

request-url

Request URL

3. Headers:

Headers provide additional information about the request. Common headers include things like Content-Type, which specifies the format of the data you’re sending, and Authorization, which might contain authentication details.

headers

Headers

4. Request Body:

The request body is where you include the data you’re sending to the server. For example, when making a POST request to create a new user, you’d include details like the username and email in the request body.

Screenshot-2567-01-04-at-183952

Request Body

5. Query Parameters:

Query parameters are additional pieces of information you append to the URL. For instance, if you’re searching for articles on a website, you might include a query parameter to filter by a specific topic.When the API endpoint hitted, it will take out the query parameter of it.

query-params

Query params

Steps to test HTTP Requests in Postman :

Step 1: Make a new directory for the project.

mkdir express-server-demo
cd express-server-demo

Step 2: Initialize a new Node.js project and installing required dependencies.

npm init -y
npm install express body-parser

Project Structure:

fgfhjk

Folder Structure

The updated dependencies in package.json file will look like:

"dependencies": {
"body-parse": "^0.1.0",
"body-parser": "^1.20.2",
"express": "^4.18.2"
}

Example: Create a file named server.js and add the following code:

Javascript




//server.js
 
const express = require('express');
const bodyParser = require('body-parser');
const app = express();
 
app.use(bodyParser.json());
 
app.get('/users', (req, res) => {
    res.send('You have hitted http://localhost:3000/users');
});
 
 
app.get('/user/:id', (req, res) => {
    const { id } = req.params;
    res.send(`Hello,You have set query id as ${id}!`);
});
 
// Route to inspect headers
app.get('/inspectHeaders', (req, res) => {
    const headers = req.headers;
    res.json({
        headers: headers,
    });
});
 
app.post('/login', (req, res) => {
    const { username, password } = req.body;
    res.json({ username, password });
});
 
app.listen(3000, () => {
    console.log('Server is running on http://localhost:3000');
});


To start the server run the following command.

node server.js


Output: Now Open the Postman and perform the necessary action.

Untitled-design-(27)

Final Output



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads