Open In App

What are Request Parameters in Postman ?

Last Updated : 15 Mar, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

Postman, a powerful tool for API testing, offers many features that make it easier to test, share, and document APIs. One of the crucial aspects of API testing using Postman involves handling request parameters. In this article, we will see what request parameters are, how to send them using Postman, and how to use them for efficient API testing.

Prerequisites:

What are Request Parameters?

Request parameters, an integral part of API testing, serve as additional data sent with the request URL to the server. They typically follow a ‘Key=Value’ structure and are appended to the URL after a question mark. For instance, consider the URL:

 https://www.example.com/search?q=Postman. Here, q=Postman

is the request parameter where q is the key and Postman is the value. The server reads this request parameter and sends a response based on the value.

Sending Request Parameters in Postman

To send request parameters in Postman, you need to use the Params option in the request builder.

GET Requests

Let’s consider a simple example where we are sending a GET request to https://www.google.com/search with the parameter q=Postman.

Step 1: Open Postman and click on the ‘+’ button to create a new tab.

Untitled-design-(1)_11zon

Step 2: Select the HTTP method as ‘GET’.

Untitled-design-(2)_11zon

Step 3: Enter the URL https://postman-echo.com/get

Untitled-design-(3)_11zon

Step 4: Click on ‘Params’ next to the URL field. Here you can add the Key-Value pairs for the parameters.

Untitled-design-(5)_11zon

Step 5: Enter ‘q’ as the Key and ‘Postman’ as the Value.

Untitled-design_11zon

Step6: Click on ‘Send’.

Untitled-design-(4)_11zon

The server responds with the search results for ‘Postman’. You can change the value in the Params to get different results.

POST Requests

In a POST request, parameters are included in the request body rather than in the URL. The process to send parameters in a POST request remains the same, the only difference is, you need to enter the parameters in the ‘Body’ section instead of ‘Params’.

Multiple Parameters

Postman also allows you to send multiple parameters in a single request. If, for example, you want to send two parameters, q=Postman and ie=UTF-8, you can add them in the ‘Params’ section as separate Key-Value pairs. Postman will automatically append these parameters to the URL with an ‘&’ symbol separating them.

Separating Parameters from URL

Postman simplifies the process of separating a URL with its parameters. You can paste the whole URL in the URL field and Postman will automatically fill the parameters in the ‘Params’ section.

Extracting Parameters in Postman Tests

You can access the request parameters in Postman tests by parsing the request.url. The request.url is a string that contains the complete URL including the parameters. You can use JavaScript functions to extract the parameters from the URL string.

var paramsString = request.url.split('?')[1];
var eachParamArray = paramsString.split('&');
var params = {};
eachParamArray.forEach((param) => {
    const key = param.split('=')[0];
    const value = param.split('=')[1];
    Object.assign(params, { [key]: value });
});
console.log(params); 

This script splits the URL at the ‘?’ symbol to separate the base URL and the parameters. It then splits the parameters string at the ‘&’ symbol to get an array of parameters. Each parameter is split at the ‘=’ symbol to get the Key and Value, which are then added to the ‘params’ object.

Conclusion

Handling request parameters is crucial in API testing as it allows you to send tailored requests and receive specific responses. Postman provides easy and intuitive ways to send and manipulate request parameters, making it a preferred tool for API testing. Remember to keep exploring and experimenting with different request parameters to make the most of your API testing with Postman.



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads