How to interact with web APIs using cURL, Postman | technical purpose (2023)

APIs simplify the work of network engineers in the industry. They rule the high-tech world, from smartphones and smartwatches to the International Space Station and data centers around the world.

Engineers who have previously worked with APIs are unlikely to return to the traditional days of command line interfaces (CLIs) and endless syntax that often causes errors that cause network outages and lost revenue for businesses. APIs are the new CLIs.

In my previous article onWeb API Use Cases, discussed what APIs are, what they are used for, and why network engineers should use them in a world where flexibility is key to delivering the highest level of service. This article describes how network engineers can use tools like cURL and Postman to interact with web APIs.

What are cURL and Postman?

Most web engineers have heard of cURL and Postman in various web and development communities. Postman is GUI basedAPI testsa platform with more than20 million usersWorldwide. It helps developers design, build, test, and improve APIs with multiple iterations. Using the tool simplifies the API workflow in test and production environments.

The cURL command line utility is used to send data to and from the server. The tool is widely used due to itsrich featuressuch as support for multiple protocols, especially HTTP and HTTPS.

To use Postman and cURL, network engineers must determine which HTTP verb to use to interact with the infrastructure. One way to do this is to combine HTTP verbs to create read, update, and delete (CRUD) functions used by databases.

GLAGOL HTTP HARD ACTION

CORREO

CREATE

GET

FILE

PLACE

UPDATE

ABOUT IT

UPDATE

DELETE

DELETE

Data transfer, API creation and automation of network tasks

In networks, Secure Shell (SSH) is a widely used protocol for secure remote access to network devices. But withgrowing need for automationand when using the network device APIs, network engineers need an interface to interact with the device APIs in a programmable way.

(Video) CURL API Testing Tutorial : How to Use CURL to Send API Requests?

HTTP or HTTPS can communicate with web device APIs using CLI and GUI tools like cURL and Postman. These interactions can retrieve data or manipulate data. In the area of ​​networks, the data is mainly device configurations. These tools help engineers integrate network devices with other network management systems, as well as improve network performance and automate network processes.

Let's jump right in and interact with the device API over HTTPS using cURL and Postman. Note: You mustunderstand the device API documentationexplicitly through CRUD operations common to all APIs.

The following examples show different scenarios in which network engineers can use cURL and the Postman GUI in a production or sandbox environment.

Tasks include:

  • Log in to the router.
  • Get interface information in JSON format.
  • Log in to the sandbox via HTTP.
  • Manipulate the interface to change the IP address.
  • Disable the interface.
  • Get a python snippet from Postman.

Interaction with the cURL command line tool

1. Log in to the router

Network engineers must always log into network devices such as switches and routers. For this purpose, engineers can access the remote network using the CLI sandbox and log in with an IP address. In the example below, we log in to the router with the IP address 172.31.0.1 over HTTPS with the following command:

curl -k https://172.31.0.1/restconf/ -u "cisco: cisco"
How to interact with web APIs using cURL, Postman | technical purpose (1)

Here, "-k" bypasses the Secure Sockets Layer certification and "-u" is added to provide the username and password.

Using cURL is an efficient way to remotely access network devices as it supports multiple protocols.

(Video) How to use CURL on Windows | How to test API with CURL | CURL Basics Step by Step

2. Get information from the interface

The next step is to collect information about the interface, such as the primary address, description, and forwarding information. This information is useful to network engineers when analyzing and solving network problems.

To verify the interface of a Cisco device, engineers typically use the following Cisco IOS command:

'show interface'

Engineers can use cURL to accomplish the same task. One possibility is to retrieve information about the interface.JSON. Currently, the JSON data format is used as the standard for data exchange, many programming languages ​​and tools support it. JSON is machine readable and processable. Therefore, engineers may need interface information in JSON format to integrate into an API or use in network automation.

Engineers can collect interface information in JSON format by adding a JSON accept header as shown below with the following command:

curl -H "Akceptuj: application/yang-data+json" -k https://172.31.0.1/restconf/data/cisco-IOS-XE-native:native/interface/gigabitethernet=1 -u "cisco":" cisco"
How to interact with web APIs using cURL, Postman | technical purpose (2)

3. Change the IP address of the interface

Network engineers face changing needs in their daily and monthly tasks. In some cases, it may be necessary to edit the router's configuration or change the IP address of the interface.

This example shows how engineers can use the cURL command to change the IP address via the CLI. Most of the time, network engineers use SSH to access devices remotely. But new web standards and tools offer alternatives, such as the following cURL command:

$curl -X PATCH -H "Type: application/yang-data+json" -H "Accept: application/yang/data+json" -d '{Cisco-IOS-XE-native: GigabitEthernet": [{ name": "1", "off": true}]}' -k https://172.31.0.1/restconf/data/Cisco-IOS-XE-native:native/interface/GigabitEthernet=1 -u "cisco" :"cisco"
How to interact with web APIs using cURL, Postman | technical purpose (3)

Interaction with the Postman GUI

1. Log in to the Cisco DevNet sandbox over HTTP

Network engineers can use Postman's graphical user interface to connect to one of Cisco's sandboxed routers. The tool is usually easy to use compared to cURL.

(Video) Postman - How To Run cURL Command

How to interact with web APIs using cURL, Postman | technical purpose (4)

2. Get information from the interface

Engineers may need to check interface status for troubleshooting or verify router configuration. In that case I can use the Postman GUI over HTTPS.

Here we use the so-calledGETverb obtain information or make aFILEaction using the following command in the postman prompt bar:

GET - https://172.31.0.1/restconf/data/Cisco-IOS-XE-native:native/interface

NavigationAuthorizationyTitlescards in Postman to fill in parameters and provide accurate information.

How to interact with web APIs using cURL, Postman | technical purpose (5)

3. Manipulate the interface to change the IP address

Network engineers can useCORREOhow to manipulate the interface.

CORREO- https://172.31.0.1/restconf/data/Cisco-IOS-XE-native:native/interface

In the following example, I demonstrate the ability to edit the configuration over HTTPS by changing the IP address of the interface using the Postman GUI.

(Video) How to convert Postman REST request to cURL request 2 minute guide

How to interact with web APIs using cURL, Postman | technical purpose (6)

4. Turn off the interface

Network professionals can useABOUT ITmethod to make changes or close the interface via HTTPS and Postman. HeBodyThe Postman tab should contain the configuration needed to close the interface in JSON format.

Network engineers can disable a router or switch interface if, for example, the team doesn't need to use it for a while. Disabling an interface is like closing a door for added security.

In the following example, I show how you can handle tasks in Postman that engineers often perform using the CLI. All engineers need credentials to access the sandbox over HTTP, as shown in the postman request bar.

How to interact with web APIs using cURL, Postman | technical purpose (7)

A unique feature of the postman is the ability to get a fragmentPitoncode to run Postman functions. Because Python is such a common coding language, thanks to its ease of use, flexibility, and rich set of libraries and frameworks, engineers often need source code to manage and maintain network infrastructure.

Engineers can get Python code from Postman to reduce manual work and increase flexibility of use based on project requirements.

How to interact with web APIs using cURL, Postman | technical purpose (8)

Advantages and challenges of cURL and Postman

No tool is perfect. Both cURL and Postman have their advantages and challenges when using the web APIs. For example, cURL is good for beginners, but it doesn't allow users to save requests. Meanwhile, Postman supports any programming language, but it consumes a lot of RAM.

Below is an overview of the pros and cons of cURL and Postman.

(Video) Sending API Requests with Postman and Curl

How to interact with web APIs using cURL, Postman | technical purpose (9)

There are many tools available in the industry to help network engineers and developers interact with web APIs. Although the tools are not perfect, engineers can choose the one that best suits their needs and helps them get the job done quickly.

FAQs

How do you hit API using curl in Postman? ›

11 Answers
  1. Open POSTMAN.
  2. Click on "import" tab on the upper left side.
  3. Select the Raw Text option and paste your cURL command.
  4. Hit import and you will have the command in your Postman builder!
  5. Click Send to post the command.

How to connect Web API to Postman? ›

To run a test collection for an API, do the following:
  1. Select APIs in the sidebar and select an API.
  2. Select Test and Automation.
  3. Under Collections, select. ...
  4. Select any configuration options for the collection run, then select Run API Tests.
May 3, 2023

How do I access API using curl? ›

How to Use CURL to Send API Requests
  1. The endpoint. This is the URL which we send requests to.
  2. The HTTP method. The action we want to perform. ...
  3. The headers. The headers which we want to send along with our request, e.g. authorization header.
  4. The body. The data we want to send to the api.
Oct 15, 2020

How to send request to API using curl? ›

To make a GET request using Curl, run the curl command followed by the target URL. Curl automatically selects the HTTP GET request method unless you use the -X, --request, or -d command-line option. The target URL is passed as the first command-line option.

How do you use the curl command? ›

curl makes HTTP requests just like a web browser. To request a web page from the command line, type curl followed by the site's URL: The web server's response is displayed directly in your command-line interface. If you requested an HTML page, you get the page source -- which is what a browser normally sees.

What is curl and how does it relate to APIs? ›

'cURL' is a command-line tool that lets you transmit HTTP requests and receive responses from the command line or a shell script. It is available for Linux distributions, Mac OS X, and Windows. To use cURL to run your REST web API call, use the cURL command syntax to construct the command.

How to send data to API using Postman? ›

Create a POST Request
  1. Step 1 − Click on the New menu from the Postman application. ...
  2. Step 2 − SAVE REQUEST pop-up comes up. ...
  3. Step 3 − The Request name (Test1) gets reflected on the Request tab. ...
  4. Step 4 − Move to the Body tab below the address bar and select the option raw.
  5. Step 5 − Then, choose JSON from the Text dropdown.

How to get data from API using Postman? ›

GET Request in Postman
  1. Step 1: Create a request. ...
  2. Step 2: Enter the URL in the address bar. ...
  3. Step 3: Now, select the GET request from the list of request methods.
  4. Step 4: Now press send.
  5. Step 5: Once you press the send button, you will get the response from the server.

How to connect web to API? ›

API connection structure
  1. Reference. The reference is the name by which the response will be available in your formulas. ...
  2. URL. The URL is the web address at which the REST API is hosted. ...
  3. Method. The method is the type of request you are sending to the API. ...
  4. Headers. ...
  5. Data. ...
  6. Query parameters.
Nov 7, 2022

How to use cURL to test an API endpoint? ›

The methodology of testing REST
  1. form data for the request.
  2. form a command for the request and select the request method (GET, POST, PUT, DELETE)
  3. pass the command to curl (or to Postman)
  4. get a response from the server (in the form of HTTP code, and data, for example in JSON, HTML, XML) and write to a file.
May 26, 2020

How to get JSON data from cURL? ›

To get JSON with Curl, you need to make an HTTP GET request and provide the Accept: application/json request header. The application/json request header is passed to the server with the curl -H command-line option and tells the server that the client is expecting JSON in response.

What is cURL command in Postman? ›

cURL or “Client URL” is a command-line utility for transmitting data across several network protocols. Any web developer may benefit greatly from this open-source technology. You may develop and utilize APIs with Postman, an API platform. Anyone may use the Postman API platform for free.

How to send a JSON via Curl? ›

To post JSON data using Curl, you need to set the Content-Type of your request to application/json and pass the JSON data with the -d command line parameter. The JSON content type is set using the -H "Content-Type: application/json" command line parameter. JSON data is passed as a string.

What is the difference between postman and Curl? ›

cURL is a command-line tool that allows you to make HTTP requests and see the server's response. On the other hand, Postman is a user-friendly tool that allows you to easily create, test and mock API requests.

What is the Curl command for Web services? ›

Client URL (cURL, pronounced “curl”) is a command line tool that enables data exchange between a device and a server through a terminal. Using this command line interface (CLI), a user specifies a server URL (the location where they want to send a request) and the data they want to send to that server URL.

What is the format of curl command? ›

cURL (curl) is an open source command-line tool used for transferring data over a network. POST is an HTTP request method which is used to send data to the server. (Read more on POST requests here.) The format of a POST request with curl is: curl -X POST [options] [URL].

What is the difference between URL and curl? ›

curl is called curl because a substring in its name is URL (Uniform Resource Locator). It operates on URLs. URL is the name we casually use for the web address strings, like the ones we usually see prefixed with HTTP:// or starting with www. URL is, strictly speaking, the former name for these.

How to call cURL API with username and password? ›

To make a Curl request with user credentials (with username and password ), you need to use the --user "username:password" command line parameter and pass the username and password to Curl. The username and password are separated by colons.

How to send JSON data to API in Postman? ›

Create a Bulk Write POSTMAN Request with Absolute Timestamps
  1. In the Headers tab, set the Content-Type as application/json .
  2. Set the Body of the request as a raw JSON object, and enter the JSON object in POSTMAN. The format for the complete POST is shown here. ...
  3. The response is a JSON object indicating success.

How to work with Postman? ›

Overview
  1. Getting started. To get started using Postman, check out the getting started section.
  2. Sending requests. You can send requests in Postman to connect to APIs you are working with. ...
  3. Writing scripts. ...
  4. Using collections. ...
  5. Using Postman Flows. ...
  6. Using the Postman CLI. ...
  7. Collaborating in Postman. ...
  8. Designing and developing your API.

How to import JSON API in Postman? ›

On your computer, drag and drop folders or files into the Import modal. Choose to import your API as a Postman Collection or as OpenAPI 3.0 with a Postman Collection. If you're importing an API definition with multiple files, select the files you want to import into Postman, then select Import.

How do I get responses from API in Postman? ›

Once you send the request, API sends the response. A response is a message the server receives in return for a Request we send. When we send the request, then server accepts that request in and sends back a packet of the requested information, which is called the response.

How do I pull all data from an API? ›

The most straightforward way of accessing data from an API endpoint is simply viewing it in the browser. As long as you're connected to the internet, you should be able to preview most API's data regardless of its format.

How do I fetch data from API? ›

Use the fetch() method

The fetch() is a browser's method to get the data from the API. It takes the API URL as the first parameter we need to get data and options as a second parameter. The options can contain headers and authentication tokens.

How do I send data to Web API? ›

Example of the application.
  1. Create a Web API application as in the following: Start Visual Studio 2012. ...
  2. Create Model Class: In the "Solution Explorer". ...
  3. Create a Controller: In the "Solution Explorer". ...
  4. Create a View. In the "UserController". ...
  5. Execute the application and change the URL as http://localhost:2669/User/Show.
Feb 10, 2021

How to send data in API? ›

To send data to the REST API server, you must make an HTTP POST request and include the POST data in the request's body. You also need to provide the Content-Type: application/json and Content-Length request headers.

How do I connect my API to my app? ›

Start using an API
  1. The easiest way to start using an API is by finding an HTTP client online, like REST-Client, Postman, or Paw. ...
  2. The next best way to pull data from an API is by building a URL from existing documentation. ...
  3. Not all APIs will require a key. ...
  4. An API is how two computers talk to each other.
Jul 29, 2022

How do you show responses in curl? ›

In default mode, curl doesn't display request or response headers, only displaying the HTML contents. To display both request and response headers, we can use the verbose mode curl -v or curl -verbose .

How to check HTTP 2 with curl? ›

To tell curl to use http2, either plain text or over TLS, you use the --http2 option (that is “dash dash http2”). curl defaults to HTTP/1.1 for HTTP: URLs so the extra option is necessary when you want http2 for that. For HTTPS URLs, curl will attempt to use http2.

How do I pass data to Curl? ›

You can pass the body of the POST message to Curl with the -d or --data command-line option. Curl will send data to the server in the same format as the browser when submitting an HTML form. To send binary data in the body of a POST message with Curl, use the --data-binary command-line option.

How do I send a file using Curl? ›

How to send a file using Curl? o upload a file, use the -d command-line option and begin data with the @ symbol. If you start the data with @, the rest should be the file's name from which Curl will read the data and send it to the server. Curl will use the file extension to send the correct MIME data type.

How to get XML response in Curl? ›

To retrieve an XML from the server using Curl, you need to pass the target URL to Curl along with the -H "Accept: application/xml" command line option. The -H command line switch sends an Accept: application/xml header to the server and tells the server that the Curl client expects an XML response.

Is Postman an alternative to cURL? ›

Postman simplifies how users can plan these APIs. This cURL alternative uses cloud computing to let users share their API data with others. In this situation, the system stores programming data online and makes it accessible to multiple parties that are authorized to access it.

What is the difference between cURL and swagger? ›

The Swagger UI uses the JSON data interchange format for requests and responses. The Curl command, which can be use in scripts, contains the information from the request (including the request URL, shown in bold).

What are the advantages of cURL? ›

Some pros of using Curl are: Platform-independent: making it easy to use on any system. Supports many protocols: including HTTP, FTP, SMTP, POP3, IMAP, and more, making it a versatile tool for data transfer. Easy to use: Curl has a simple command-line interface, making it easy to use and automate with scripts.

How do I send and receive JSON data? ›

Send JSON Data from the Client Side
  1. Create a JavaScript object using the standard or literal syntax.
  2. Use JSON. stringify() to convert the JavaScript object into a JSON string.
  3. Send the URL-encoded JSON string to the server as part of the HTTP Request.

How to send JSON data in POST request? ›

Let's see the steps now.
  1. Select POST request and enter your service POST operation URL.
  2. Click on Headers. In the key column enter Content-Type and in the Value column enter application/json .
  3. Click on the body section and click the raw radio button. enter your JSON data. Click the Send button.
May 14, 2021

How do I import a cURL request? ›

Importing via cURL
  1. Make a post or get a request from the browser.
  2. Press F12 or right and 'Inspect', it will open the DevTools for the page and go to the 'Network' tab as below:
  3. Next, right-click on your request name here in my case 'weatherforecast', and select 'Copy' then select the 'Copy as cURL(cmd)' option as below:
May 4, 2022

Is curl a rest client? ›

curl can send all common HTTP commands to a REST API including GET , POST , PUT , and DELETE . The curl utility is straightforward to use. It has a few main options for data transmission, user authentication, and making header changes. For more information about curl, see the curl documentation.

How to get HTTP code from curl command? ›

How to Get the HTTP Status of a Site Using cURL
  1. Overview. cURL is a de facto standard utility in Linux to connect and transfer data from URLs. ...
  2. Using –head Option. ...
  3. Using –include Option. ...
  4. Using –write-out Option. ...
  5. Handling Redirection. ...
  6. Conclusion.
Feb 23, 2023

Is curl a web client? ›

Curl stands for client URL, it is a free command-line tool for transferring files with URL syntax. Curl supports a number of protocols, including HTTP, FTP, SMB, and SSL certificates. There are a number of Curl clients for Windows, Linux, macOS, Android and iOS, and now with the ReqBin Online client for the web.

How do you hit curl command in Windows? ›

Any recent version of Microsoft Windows (Windows 10 build 1803 and later, for example), including Windows 11, come with cURL already installed. To ensure you have it already, simply open a command prompt (or PowerShell if you are more comfortable in that environment), type “curl,” and hit enter.

How do I copy a curl from Chrome to Postman? ›

In Chrome, right cick and then select Inspect to open the DevTools panel. Under the Chrome DevTools Network tab, you will see a log of the network requests as you navigate and interact with the page. Find the request that you would like to import into Postman. Select it, right click, and then select Copy as cURL.

Can we run curl command in PowerShell? ›

curl in PowerShell uses Invoke-WebRequest . From PowerShell 3.0 and above, you can use Invoke-WebRequest , which is equivalent to curl .

How do I access a website using curl? ›

The syntax for the curl command is as follows: curl [options] [URL...] In its simplest form, when invoked without any option, curl displays the specified resource to the standard output. The command will print the source code of the example.com homepage in your terminal window.

What is curl command in Windows? ›

Curl (client URL) is a command-line tool powered by the libcurl library to transfer data to and from the server using various protocols, such as HTTP, HTTPS, FTP, FTPS, IMAP, IMAPS, POP3, POP3S, SMTP, and SMTPS. It is highly popular for automation and scripts due to its wide range of features and protocol support.

What is the curl command to get data from URL? ›

The most basic command in curl is curl http://example.com . The curl command is followed by the URL, from which we would like to retrieve some kind of data. In this case, it would return the html source for example.com .

How do I convert Postman curl to Windows curl? ›

To generate curl output for windows using postman click on settings next to curl code section and change line continuation character to ^ and quote double and shown in the image. This should generate output for windows. You can also change the output to single or multiline.

Can I use curl instead of Postman? ›

Postman is a platform for testing APIs. cURL is a command-line utility that allows you to transmit data over URLs. To do the same operations with REST APIs, we may use Postman as a GUI (graphical user interface) and cURL as a CLI (command-line interface). Check out how to use Postman and PDF.co Web API.

How to send curl POST request in JavaScript? ›

To post JSON data using Curl, you need to set the Content-Type of your request to application/json and pass the JSON data with the -d command line parameter. The JSON content type is set using the -H "Content-Type: application/json" command line parameter. JSON data is passed as a string.

How do you automate curl commands? ›

Automate queries with cURL
  1. Log into the project through the web interface.
  2. Create and save the queries and reports that you want your script to execute. ...
  3. Configure the saved queries/reports so that the results are exported to a MS Excel or TSV file.
  4. Go to the appropriate page to see your saved query or report.

How do I run a curl command in a script? ›

The -H option and “Accept: application/json” header are used with the “curl” command to do this task. Run the following “curl” command with the -H option to read the content of the https://linuxhint.com/echo/get/json server in JSON format. If the server does not support the JSON format, no JSON output is generated.

How to install curl command? ›

Installing curl
  1. Log in to your server via SSH.
  2. Make sure you're in your user's home directory. [server]$ cd ~
  3. Unzip the file. [server]$ unzip curl-7.70.0.zip.
  4. Navigate into this new directory. ...
  5. Run the following to install: ...
  6. Open your .bash_profile using nano or vim. ...
  7. Add this line to your .bash_profile: ...
  8. Update your .
Apr 10, 2023

Videos

1. How To Execute CURL Commands In postman- Postman Tutorial For Beginner
(Mukesh otwani)
2. How to import curl command in postman request | how to run curl command in postman
(1N1 TechGuru)
3. Example of using a REST API with curl
(CSDoctorr)
4. How to use PHP cURL to Handle JSON API Requests
(Coding Reflections)
5. Copy Curl from browser and run in postman | cURL Request | API Testing | Automation Testing
(CodeWith { Parveen Yadav })
6. how to import curl to postman
(Code With Malindu)

References

Top Articles
Latest Posts
Article information

Author: Nathanael Baumbach

Last Updated: 12/09/2023

Views: 6344

Rating: 4.4 / 5 (75 voted)

Reviews: 82% of readers found this page helpful

Author information

Name: Nathanael Baumbach

Birthday: 1998-12-02

Address: Apt. 829 751 Glover View, West Orlando, IN 22436

Phone: +901025288581

Job: Internal IT Coordinator

Hobby: Gunsmithing, Motor sports, Flying, Skiing, Hooping, Lego building, Ice skating

Introduction: My name is Nathanael Baumbach, I am a fantastic, nice, victorious, brave, healthy, cute, glorious person who loves writing and wants to share my knowledge and understanding with you.