How to generate Curl Command from Postman How to generate Curl Command from Postman

Page content

In this tutorial, we’ll learn how to generate Curl command using Postman.

Overview

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 when we are stuck in a situation where:

  • Browser is not available on the machine
  • Postman is not able to install on a certain machine
  • Using Linux environment

In such cases, Curl command is very useful and can be used to execute HTTP endpoints from a command prompt or terminal.

Installing Curl

The curl package is pre-installed on most Linux distributions today.

If 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:

  1. Create an HTTP request using Postman

  2. Click on the code </> icon from the menu on the right.

    Generate Code Snippet from Postman for HTTP Request
    You may find the code icon or text button somewhere else depending on the Postman version.

  3. A dialog “Code Snippet” will appear. Select “cURL” from the dropdown and copy the generated command code snippet.

    Generate cURL from Postman for HTTP Request
    curl 'https://reqres.in/api/users' \
    --header 'Content-Type: application/json' \
    --data '{
      "name": "morpheus",
      "job": "leader"
    }'
    
  4. Postman generates multi-line cURL code snippets by default. Mac and Linux support multi-line cURL code snippets but not Windows.

    You can change the default behavior by changing the settings using the icon next to the dropdown.

Setting for cURL Code Snippet generated from Postman