Testing REST API with Postman and curl
Last Updated :
28 Apr, 2025
In the world of API testing, there are many tools available. Postman and cURL are two of the most popular tools for it. Let's look at how to use these tools for testing them. We will send some HTTP requests and explore the basic syntax for both of them in this article. The article focuses on using a fake REST API named JSON placeholder.
What is REST?
REST stands for Representational state transfer. It is an architectural style that can be used in web services for scalable and modifiable communication between client and server. In this architecture, the client-server uses a standardized way to exchange resource representation. The implementation of the client side is independent of the server side. As long as both of them follow the REST architecture style both of them can communicate with each other irrespective of the tech stack of framework used to build them. For example, an API hosted on a single server can be used by both mobile and web applications.
REST API requests should consist of the following:
- An HTTP verb like GET, POST, or DELETE (denotes the kind of operation to be performed)
- Path of the requested resource.
- Headers to pass information about the request like what kind of content is passed in the request.
- Optional message body containing data (if required).
Why Test REST API?
Testing is an important stage in the development of REST APIs. It helps to verify that the APIs are:
- Working correctly and does not cause any unexpected errors.
- Functioning properly under high amounts of user requests.
- Safe and secure.
Methodology of Testing REST
The following questions needs to be asked before writing tests:
- What are the API endpoints that are needed to be tested?
- What kind of data is needed by an API?
- What kind of response is given by an API?
- How much time an API should take to respond?
- What kind of response should an API give in case a request fails?
Then create some input data for your APIs and the corresponding output for it. Send the input data to the API and test whether the response matches with the output data or not. The test case should analyse the following properties of responses:
- Status code.
- Response time.
- Response data.
- Response headers.
Suppose you have created an API for user authentication system that requires username and password. You will create some test cases consisting of multiple username and passwords and their corresponding responses that are expected by the API. Then pass the input data one by one and compare the responses with the output in the test cases.
Using cURL for API Testing
cURL (client for URL) is a command line tool that is used to transfer data using various network protocols (including HTTP). It is available on various platforms including Windows, macOS and Linux.
Open command line terminal on your computer. To send a get request, enter the command given below:
curl -X GET https://jsonplaceholder.typicode.com/posts/1
Here, -X is used to specify an HTTP verb (GET, POST, DELETE etc).
To send a POST request use the command given below:
curl -X POST https://jsonplaceholder.typicode.com/posts -H "Content-Type: application/json" -d "{\"title\": \"foo\",\"body\":\"bar\",\"userId\":1}"
Here, -H option is for setting the headers. Here Content-Type represents the type of content of the request body (here it is json). -d denotes the request body. (\“ is used to escape the “.)
To output your requests to a file using curl command with the -o option:
curl -X GET https://jsonplaceholder.typicode.com/posts/2 -o response.json
cURL can be integrated into scripts and automated test suites by using its command-line capabilities. You can chain multiple cURL commands together to simulate complex API scenarios like user authentication.
Using Postman for API Testing
Postman is a platform for building and testing APIs. It comes with a graphical user interface which makes API testing easy and has features for automated testing and API monitoring.
Step 1: Install Postman
Download postman from here. After installing, launch the application. It will look something like this.
postman desktop applicationStep 2: Create a new collection
On the top left corner, press the + icon to create a new collection. Name it Postman testing. A collection in Postman is a group of requests.

Step 3: Create a new request
On the left side click on the three dots on the collection tab and click Add Request to create a new request. Name the request get request.


Step 4: Sending HTTP requests
Set the HTTP method to GET on the top. Enter https://jsonplaceholder.typicode.com/posts/1 in the URL field. Now, hit the send button. You will get a response in the response tab below with status code 200 meaning the response was successful.

Congratulations, you completed your first REST API test. In this way, you can test REST APIs to make sure the APIs are working well. Of course, there is much more in API testing, but this is the basic workflow.
Sending POST Request
1. Create a new request in the collection.
2. Set the method to POST.
3. Enter https://jsonplaceholder.typicode.com/posts in the URL field.
4. Now we need to send a body with a POST request. Select Body tab below the URL field.
5. Select Raw and JavaScript instead of Text. Paste this JSON object in the text area and hit send.
{ title: 'foo', body: 'bar', userId: 1, }
6. You will get a JSON object in response denoting the id of the newly created object and a 201-status code which means your object was created successfully in the backend.

Sending a DELETE Request
1. Create a new request for DELETE. Select DELETE method and send the request to this URL https://jsonplaceholder.typicode.com/posts/50
2. You will get a response similar to this meaning that the object with id 1 was successfully deleted.

Testing using Script in Postman
While testing real world APIs there would be many APIs and manually checking the status codes and responses of each API would be a cumbersome task. Postman has a solution for this - test scripts. Postman allows writing test scripts to automate the testing of API.
To write a test script go to the get request.
1. Select the Tests tab under it.
2. You can write scripts in JavaScript to assert your API response.
3. Paste the following code into the Tests tab and hit send.
JavaScript
// Check if the response status code is 200 (OK)
pm.test("Status code is 200", function () {
pm.response.to.have.status(200);
});
// Parse the response JSON
const jsonData = pm.response.json();
// Check if the response contains specific properties
pm.test("Response contains userId", function () {
pm.expect(jsonData.userId).to.exist;
});
pm.test("Response contains id", function () {
pm.expect(jsonData.id).to.exist;
});
pm.test("Response contains title", function () {
pm.expect(jsonData.title).to.exist;
});
pm.test("Response contains body", function () {
pm.expect(jsonData.body).to.exist;
});
4. Go to Test Results tab in the response. You can see that all of our test cases passed.

Congratulations, you just created an API test script.
Postman vs cURL
Postman is a platform for building and testing REST APIs. It comes with a graphical user interface and has many useful features like organizing tests into collections, automated testing and API monitoring. Postman allows you to create environments, set variables and so on. You can write scripts through which developers can build automated tests. It also has version control and collaboration features which are useful for developers working in teams.
cURL is a command-line tool for transferring data using many network protocols and HTTP is one of them. It is useful in situations where you don't require a graphical interface. It comes mostly pre-installed with many operating systems. It can also be easily integrated into scripts.
Conclusion
We looked at the process of testing REST APIs with cURL and Postman in this article. You can choose either of them based on your testing requirements. Some developers also use both of them to have the best of both worlds.
Similar Reads
Automation Testing - Software Testing Automated Testing means using special software for tasks that people usually do when checking and testing a software product. Nowadays, many software projects use automation testing from start to end, especially in agile and DevOps methods. This means the engineering team runs tests automatically wi
15+ min read
Automation Testing Roadmap: A Complete Guide to Automation Testing [2025] Test automation has become a vital aspect of the Software Development Life Cycle (SDLC), aimed at reducing the need for manual effort in routine and repetitive tasks. Although manual testing is crucial for ensuring the quality of a software product, test automation plays a significant role as well.
9 min read
How to Start Automation Testing from Scratch? Automation Testing is the practice of using automated tools and scripts to execute tests on software applications, reducing manual effort and increasing efficiency. Starting automation testing from scratch involves several key steps, including selecting the right automation tool, identifying test ca
8 min read
Benefits of Automation Testing Automation Testing is the process of using tools and scripts to automatically run tests on software, instead of performing them manually. It helps developers and testers save time, catch bugs early, and ensure that applications work as expected after every change. In this article, weâll explore the
4 min read
Stages of Automation Testing Life Cycle In this article, we will explore the phases and methodologies involved in automation testing and the phases of the automation testing lifecycle. We'll cover everything from scoping your test automation to creating a solid test plan and strategy. You'll also learn about setting up the perfect test en
12 min read
Top Automation Testing Books For 2024 In this article, we can explore the top 10 books for automation testing, providing a top-level view of each book's content material and why it's worth considering for everybody interested in this sector. Table of Content Top 10 Books for Automation Testing BooksConclusionFAQs on Top Automation Test
12 min read
Top Test Automation mistakes and Tips for QA teams to avoid them In the dynamic landscape of software testing, avoiding common test automation pitfalls is crucial for QA teams aiming for efficient and successful testing processes. This article delves into prevalent errors in test automation and provides valuable insights on how QA teams can steer clear of these m
7 min read
Essential Skills for a Successful Automation Tester In the domain of software testing, automation plays a crucial role in ensuring efficiency, accuracy, and speed. However, to be a successful automation tester, one must possess a specific set of skills beyond just technical proficiency. This article explores the essential skills required for automati
6 min read
Steps to Select the Right Test Automation tools Selecting the right test automation tools is critical for ensuring efficient and effective testing processes in software development projects. In this article, we will discuss the key steps involved in choosing the most suitable automation tools for your project needs. From understanding project req
5 min read
Best Test Automation Practices in 2024 Test Automation continues to evolve with new technologies and methodologies emerging each year. In 2024, staying updated with the latest best practices is crucial for efficient and effective testing processes. From robust test design to continuous integration and deployment, this article explores th
7 min read