🚀 API Testing with curl and jq in Termux
APIs (Application Programming Interfaces) are the backbone of modern applications. Whether you are a developer, tester, or cybersecurity enthusiast, testing APIs quickly from the terminal can save a lot of time. In this article, we’ll explore how to use curl and jq in Termux to test APIs with the example of the free dummy.restapiexample.com API.
🔧 What You Need
Termux installed on your Android device.
curl (for making API requests).
jq (for parsing and formatting JSON).
👉 Install jq in Termux:
pkg install jq
🌐 Step 1: Making a Simple GET Request
To fetch employee data from the dummy API:
curl -X GET https://dummy.restapiexample.com/api/v1/employees
This returns raw JSON with employee details.
🎨 Step 2: Pretty Print JSON with jq
Raw JSON is often messy. Use jq to format it:
curl -s https://dummy.restapiexample.com/api/v1/employees | jq
Here,
-s suppresses extra output.
jq beautifies the JSON response.
🎯 Step 3: Extract Specific Data
Want just the employee names?
curl -s https://dummy.restapiexample.com/api/v1/employees | jq '.data[].employee_name'
Want only salaries?
curl -s https://dummy.restapiexample.com/api/v1/employees | jq '.data[].employee_salary'
🔍 Step 4: Fetch a Single Employee
To get details of employee with ID 1:
curl -s https://dummy.restapiexample.com/api/v1/employee/1 | jq
🛠 Pro Tip: Add Headers if Blocked
Sometimes APIs block requests without a User-Agent header. In that case:
curl -s -H "User-Agent: Mozilla/5.0" https://dummy.restapiexample.com/api/v1/employees | jq
📌 Why Use curl + jq in Termux?
✅ Lightweight, runs directly on Android.
✅ No need for heavy apps like Postman.
✅ Great for quick debugging and testing.
✅ Works offline with saved API responses.
🏁 Conclusion
With just curl and jq in Termux, you can test, debug, and filter API responses right from your phone. Whether you’re learning APIs, doing quick tests, or working on DevOps tasks, this combo is a powerful and minimalist toolkit.