Rapid Profile picture
Leading API hub for developers and enterprises. 40K+ APIs to unleash innovation. Join a community of 4M+ innovators today.

Feb 28, 2023, 10 tweets

How to use cURL with APIs.

Thread 🧵

cURL is a command line tool for transferring data specified with URL syntax.

cURL supports a wide variety of protocols, including HTTP, HTTPS, FTP, FTPS, SFTP, SMB, TELNET, DICT, LDAP, LDAPS, FILE, IMAP, SMTP, POP3, RTSP, and RTMP.

cURL also supports HTTPS certificates, HTTP POST, HTTP PUT, FTP uploading, Kerberos, HTTP form-based upload, proxies, and cookies.

Curl offers a wide range of options (over 200) to customize your commands.

It's always good to set the verbose mode on when testing.

We can set verbose "on" with "-v" command.

The command provides vital information such as:

- the resolved IP address
- the port we're trying to connect to
- headers

cURL's default behavior is to output the response body to standard output.

However, the output can be redirected to a file using the output option.

For this, we'll use the "-o" command.

What we can see here is the classic GET request.

If we want to perform a POST request, we must specify the data we want to send to the API.

This can be done with the "-d" command.

For this purpose, we're using variable name/value pairs concatenated with "&."

If you prefer to define your payload in the file, you can do so by using the example below.

As you can see, we're specifying the header with the "-H" command so the server can understand the payload is in JSON format.

Below you can see how to perform a PUT request.

We're using the "-X" command that allows specifying the method. In our case, it's "PUT."

For DELETE, we're using the "-X" command again with the "DELETE" specified for the method.

That’s all for now!

Follow @Rapid_API for more exclusive content. 🐙

Share this Scrolly Tale with your friends.

A Scrolly Tale is a new way to read Twitter threads with a more visually immersive experience.
Discover more beautiful Scrolly Tales like this.

Keep scrolling