How to Use curl to Interact with APIs

Опубликовано: 25 Март 2026
на канале: LinuxHowTo
19
0

In this video, we’ll show you how to use curl to interact with APIs. curl is a powerful command-line tool that allows you to send HTTP requests (GET, POST, PUT, DELETE, etc.) directly from the terminal. It’s perfect for testing and debugging APIs. We’ll cover how to install curl, use it to fetch data, send data, update data, and delete data using real API examples. Let’s dive into the details and master curl!

Learn:

Install curl (if needed):

sudo apt install curl
🔹 Real API Examples (Using JSONPlaceholder)

🟢 GET – Fetch Data

curl https://jsonplaceholder.typicode.com/...
→ Get post with ID 1
🔗 https://jsonplaceholder.typicode.com/...

🟠 POST – Send Data

curl -X POST https://jsonplaceholder.typicode.com/... \
-H "Content-Type: application/json" \
-d '{"title":"toto","body":"developer","userId":1}'
→ Create a fake post
🔗 https://jsonplaceholder.typicode.com/...

🔵 PUT – Update Data

curl -X PUT https://jsonplaceholder.typicode.com/... \
-H "Content-Type: application/json" \
-d '{"id":1,"title":"updated title","body":"updated body","userId":1}'
→ Update a fake post
🔗 https://jsonplaceholder.typicode.com/...

🔴 DELETE – Remove Data

curl -X DELETE https://jsonplaceholder.typicode.com/... -v
→ Simulate deleting a resource
🔗 https://jsonplaceholder.typicode.com/...

⚙️ Main curl Powers (Options)

Set HTTP method: -X
ex: -X POST

Add header: -H
ex: -H "Content-Type: application/json"

Send JSON or form data: -d
ex: -d '{"key":"value"}'

Verbose output (headers + status): -v
ex: -v

Save output to file: -o file
ex: -o result.json

Follow redirects: -L
ex: -L http://example.com

Show headers only: -I
ex: -I https://example.com

Basic auth (if needed): --user user:pass
ex: --user admin:1234

Ignore SSL checks (testing only): --insecure
ex: --insecure


💡 Example Combo

curl -X GET https://jsonplaceholder.typicode.com/... \
-v -o user.json -H "Accept: application/json"
→ Fetch user data, show details, and save output
🔗 https://jsonplaceholder.typicode.com/...


✅ Free APIs to Practice

🧱 https://jsonplaceholder.typicode.com
👥 https://reqres.in
⚙️ https://httpbin.org


✅ Pro Tips:
Experiment with Different APIs: Use different APIs to practice and understand how curl works.
Use Verbose Mode: Use the -v option to see detailed information about the request and response.
Save Output: Use the -o option to save the response to a file for further analysis.

GitLab Link: You can find PDF tutorial used in this video at this GitLab link: https://gitlab.com/hatem-badawi/linux....

Hit subscribe for more Linux and productivity tips and like if this helped.
Let us know: What’s your favorite API to practice with curl?

👉 Watch now and master using curl to interact with APIs!

#Curl #APIs #CommandLine #ProductivityHacks #LinuxTips

(Short, clear, and packed with practical knowledge!)