How to generate Curl Command from Postman | ninjasquad
In this tutorial, we’ll learn how to generate Curl command using Postman.
Many times we need to execute GET, POST, PUT, PATCH, DELETE Http requests to verify endpoints. Normally we use:
- Browser to execute GET request
- Postman to execute GET, POST, PUT, PATCH, DELETE requests
There are many times where we stuck in a situation where:
- Browser is not available on the machine
- Postman is not able to install on certain machine
- Using Linux environment
In such cases Curl command is very useful which can be used to execute HTTP endpoints from command prompt or terminal.
curl package is pre-installed on most Linux distributions today.
curl is not installed you can easily install it using the package manager of your distribution.
Install Curl on Ubuntu and Debian
sudo apt update sudo apt install curl
Install Curl on CentOS and Fedora
sudo yum install curl
Generate Curl from Postman
Considering that you are already familiar with Postman. Follow these steps:
Create HTTP request using Postman
Click on the Code button.
A dialog “GENERATE CODE SNIPPET” will appear. Select “cURL” from the dropdown.
curl -X POST \ https://postman-echo.com/post \ -H 'cache-control: no-cache' \ -H 'content-type: application/x-www-form-urlencoded' \ -H 'postman-token: 2fbfab60-2a72-6c9d-754a-c7ff0fdedd23' \ -d strange=boom
You can copy the command using Copy to Clipboard button.
Please note that Postman generate multi-line CURL command which works in Mac and Linux environment but not in windows terminal. In such cases, you need to change command to single-line manually.