12/15/25, 1:03 PM Using Curl to make REST API requests - GeeksforGeeks
Search... Sign In
Using Curl to make REST API requests
Last Updated : 23 Jul, 2025
REST APIs are essential for modern web applications, enabling
programmatic interaction with data and functionality. Curl is a
command-line tool for making web requests, often used directly from
the terminal. For example, curl -L [Link] fetches IP address
details in JSON format, just like visiting the site in a browser.
Essentially, Curl prints the web response to the terminal. In this article,
we will learn how to make REST API requests using Curl.
Using curl to make REST API requests
Using curl to make REST API requests
Example 1: Create (POST) Request
Example 2: Read (GET) Request
Example 3: Update (PUT) Request
Example 4: Delete (DELETE) Request
Important curl command flags
For the sake of this article, let's use a sample social media API that I
have created. This will help demonstrate how to make REST API
requests using cURL.
Example 1: Create (POST) Request
In this example, we use curl to send a POST request to the endpoint
[Link] to create a new user. The -X POST flag
specifies the request method, -H "Content-Type: application/json"
sets the content type header, and -d '{"name": "Ba3a", "email":
"someMail@[Link]"}' sends the user data in JSON format.
[Link] 1/9
12/15/25, 1:03 PM Using Curl to make REST API requests - GeeksforGeeks
Command:
#!/bin/bash
curl -X POST \
-H "Content-Type: application/json" \
-d '{"name": "Ba3a", "email": "someMail@[Link]"}' \
[Link]
Explanation:
-X POST: Specifies the HTTP method for creating a new resource.
-H "Content-Type: application/json": Sets the content type header
to indicate JSON data is being sent.
-d '{"name": "Ruchi", "email": "someMail@[Link]"}': Includes
the user data in JSON format using the -d flag.
Output:
Create (POST) Request
Example 2: Read (GET) Request
In this example, we use curl to send a GET request to the endpoint
[Link] that fetches user data based on the
user-id i.e. 1.
Command:
curl [Link]
[Link] 2/9
12/15/25, 1:03 PM Using Curl to make REST API requests - GeeksforGeeks
Explanation:
curl: Command-line tool for transferring data using various network
protocols. In this context, it's used to make an HTTP GET request.
[Link] The URL to which the GET request is
sent.
Output:
Create Read (GET) Request
ew Questions Shell Scripting Kali Ubuntu Red Hat CentOS Docker K Sign In
Example 3: Update (PUT) Request
In this example, we use curl to send a PUT request to the endpoint
[Link] to update the user. The -X PUT flag
specifies the request method, -H "Content-Type: application/json"
sets the content type header, and -d '{"email":
"[Link]@[Link]"}' sends the user data in JSON format.
Command:
#!/bin/bash
curl -X PUT \
-H "Content-Type: application/json" \
-d '{"email": "[Link]@[Link]"}' \
[Link]
Explanation:
curl: This is the command-line tool used to transfer data with URLs.
-X PUT: Specifies the HTTP method to use, in this case, PUT, which is
used to update a resource on the server.
[Link] 3/9
12/15/25, 1:03 PM Using Curl to make REST API requests - GeeksforGeeks
-H "Content-Type: application/json": Sets the Content-Type header to
application/json, indicating the data format being sent.
-d '{"email": "[Link]@[Link]"}': Specifies the data to be
sent in the request body. Here, it is a JSON object updating the
email field.
[Link] The URL endpoint for the API
request.
Output:
Create Update (PUT) Request
Example 4: Delete (DELETE) Request
In this example, we use curl to send a DELETE request to the endpoint
[Link] to delete the user with ID 3. The -X
DELETE flag specifies the request method.
Command:
curl -X DELETE [Link]
Explanation:
curl: This is the command-line tool used to transfer data with URLs.
-X DELETE: Specifies the HTTP method to use, in this case, DELETE,
which is used to remove a resource on the server.
[Link] The URL endpoint for the API
request.
[Link] 4/9
12/15/25, 1:03 PM Using Curl to make REST API requests - GeeksforGeeks
Output:
Create Delete (DELETE) Request
Now that we know how to make REST API requests with CURL, let us
see some important flags that might be useful.
Important curl command flags
Flag Description Example
Verbose Mode Gain insights into the
(-v) request-response process
curl -v
with detailed information
[Link]
by enabling verbose
mode.
Silent (-s) Don't show progress
curl -s
meter or error messages.
[Link]
Makes Curl mute.
Output to File (- Save the API response to
o) a file for further analysis curl -L [Link]
using the -o flag followed -o [Link]
by the desired filename.
[Link] 5/9
12/15/25, 1:03 PM Using Curl to make REST API requests - GeeksforGeeks
Flag Description Example
Authentication Curl supports various
authentication
mechanisms, allowing curl -u user:password
secure access to [Link]
protected APIs. Use -u for
basic authentication.
Error Handling Capture the HTTP status
(-w % code returned by the API
{http_code}) using the -w %{http_code} curl -w %{http_code}
flag. Helps identify errors [Link]
(e.g., 404 Not Found, 500
Internal Server Error).
Conclusion
In conclusion, cURL is a versatile and powerful tool for making REST
API requests, enabling efficient interaction with web services directly
from the command line. Understanding its various options and flags
allows for robust handling of different API operations, from data
retrieval to resource updates and deletions.
Comment B ba3a Follow 0
Article Tags : Linux-Unix
[Link] 6/9
12/15/25, 1:03 PM Using Curl to make REST API requests - GeeksforGeeks
[Link] 7/9
12/15/25, 1:03 PM Using Curl to make REST API requests - GeeksforGeeks
Fresher Jobs Experienced Jobs
Trainee Software…
Opkey
Internship • Onsite - Noida (Uttar…
Apply by Wed Dec 17 2025
Talent Acquisition Intern
9yards Technology
Internship • Onsite - Noida (Uttar…
Apply by Thu Dec 18 2025
SEO Intern
9yards Technology
Internship • Onsite - Noida (Uttar…
Apply by Thu Dec 18 2025
Corporate & Communications Address: View All →
A-143, 7th Floor, Sovereign Corporate
Tower, Sector- 136, Noida, Uttar Pradesh
(201305)
Registered Address:
K 061, Tower K, Gulshan Vivante
Apartment, Sector 137, Noida, Gautam
Buddh Nagar, Uttar Pradesh, 201305
Company Explore
About Us POTD
Legal Job-A-Thon
Privacy Policy Connect
Careers Blogs
Contact Us Nation Skill Up
Corporate Solution
Campus Training Program
[Link] 8/9
12/15/25, 1:03 PM Using Curl to make REST API requests - GeeksforGeeks
Tutorials Courses
Programming Languages ML and Data Science
DSA DSA and Placements
Web Technology Web Development
AI, ML & Data Science Data Science
DevOps Programming Languages
CS Core Subjects DevOps & Cloud
GATE GATE
School Subjects Trending Technologies
Software and Tools
Offline Centers Preparation Corner
Noida Interview Corner
Bengaluru Aptitude
Pune Puzzles
Hyderabad GfG 160
Patna System Design
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
[Link] 9/9