Structure of HTTP request in Postman
Last Updated : 23 Jul, 2024
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 method2. 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 URL3. 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.
Headers4. 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.
Request Body5. 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 paramsSteps 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:
Folder StructureThe 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.
Similar Reads
API Response Structure in Postman
Postman, a widely-used API testing tool, is essential for developers to interact with APIs efficiently. Understanding the API response structure in Postman is key to successful testing and debugging. From status codes to response body options, Postman provides a user-friendly interface for analyzing
5 min read
Send Get request in Postman
Postman is a well-known tool for doing Manual API Testing. It has lots of features and at the beginner level, it is used for testing the HTTP responses like GET, POST, PUT, and DELETE. In this article, we will discuss how to deal with Get requests in Postman. What is GET Request?This is an HTTP requ
3 min read
How HTTP POST requests work in Node ?
The HTTP POST method is used to send data from the client to the server. Unlike GET, which appends data in the URL, POST sends data in the request body, which makes it ideal for form submissions, file uploads, and secure data transfers. In Node.js, handling POST requests is commonly done using the E
2 min read
How to Retrieve the Request Object in PostMan
Postman is a popular API testing tool used by developers to test, document, and share APIs. While Postman primarily focuses on sending HTTP requests and receiving responses, it also provides features for inspecting request objects. In this article, we'll explore how to retrieve the request object in
5 min read
How to set header request in Postman?
Postman is a powerful API development tool that offers a feature known as environment variables. These variables are used for efficient testing and development of APIs by allowing users to manage dynamic values across requests easily. In this article, we will learn How you can set header requests in
2 min read
Postman pre-request-script URL not defined
Postman is an API (application programming interface) development tool that helps to build, test and modify APIs. It can make various types of HTTP requests (GET, POST, PUT, PATCH), save environments for later use, and convert the API to code for various languages (like JavaScript, and Python). In t
3 min read
Sending a Post request in postman pre-script
Postman stands out as a go-to tool for crafting and testing APIs, offering a robust set of features including API monitoring and script-based testing. Pre-request scripts which are effectively snippets of JavaScript code, play an important role in API testing. This article focuses on discussing send
2 min read
How to Send an HTTP POST Request in JS?
We are going to send an API HTTP POST request in JavaScript using fetch API. The FetchAPI is a built-in method that takes in one compulsory parameter: the endpoint (API URL). While the other parameters may not be necessary when making a GET request, they are very useful for the POST HTTP request. Th
2 min read
How to Import cURL Request into Postman ?
Postman is an API development tool that helps us do everything related to APIs, make API calls, perform API testing, create automations, etc. This is a one-step tool to perform operations on the backend server, and show the outputs in various readable formats. In this article, we will learn how to i
2 min read
How to test query strings in Postman requests ?
To test query strings in Postman requests, we only need to simply enter the key and value of each parameter and Postman will append them to the URL automatically. To the end of the request URL, the parameters are appended using '?' and key-value pairs are separated by '&'. e.g. :- ?id=22&typ
3 min read