- Instant help with your Developer coding problems

How to convert a Postman request to curl

If you're developing an API, you're probably already familiar with Postman. It is a great help during development when we want a quick and easy-to-use way to build and send API requests. But since this is a desktop GUI application, you cannot use it in all cases. For example, in a server environment or when running automated tests, you can't use Postman. In these cases, a cURL command is much more usable.

Fortunately, the developers of Postman have also thought about this problem. They implemented a Code module for the application. With this module, you can easily convert requests into different formats. But let's start presenting the concrete steps.

Converting Postman request to cURL

  1. Start Postman and open a request
  2. Just for sure, check if it really works
  3. Click on the small code icon in the top right corner of the application window.

    Open code module in Postman

  4. Postman converts your request and displays it in the window that opens.

    Convert to cURL

    The generated cURL command is:

    curl --location 'https://api.publicapis.org/entries?category=science'

  5. Copy and test the command

    Execute cURL command

Other options

cURL parameterization:

If you want to change the basic parameters of the cURL command, you can do so by clicking on the small gear icon. As you change the settings, the generated command will change immediately.

cURL settings in Postman

Convert to other formats:

In addition to the cURL command, you can convert Postman requests to many other formats. For example, to PHP code using the Guzzle library, to a plain JavaScript fetch call, or even to a Python request.

Postman output formats

The generated JS code:

var myHeaders = new Headers();
myHeaders.append("my-header-item", "header-value");

var requestOptions = {
  method: 'GET',
  headers: myHeaders,
  redirect: 'follow'
};

fetch("https://api.publicapis.org/entries?category=science", requestOptions)
  .then(response => response.text())
  .then(result => console.log(result))
  .catch(error => console.log('error', error));

 

 

Share "How to convert a Postman request to curl" with your friends