Testing APIs does not always require a computer or a graphical application like Postman. With Termux, you can turn your Android device into a powerful command-line development environment and test REST APIs, HTTP endpoints, JSON responses, authentication, headers, and more.
Termux provides a Linux-like environment on Android and supports installing command-line packages through its package manager.
In this guide, we will explore the best command-line API testing tools for Termux, along with installation commands and practical examples.
Table of Contents
- Update Termux
- 1. cURL
- 2. HTTPie
- 3. Wget
- 4. jq for JSON Responses
- 5. Python Requests
- 6. Node.js and Fetch
- Comparison Table
- Recommended API Testing Workflow
- FAQ
Update Termux First
Before installing any API testing tools, update your Termux packages:
pkg update && pkg upgrade -y
The Termux project recommends keeping packages updated, and its pkg command provides a simplified interface for package installation and upgrades.
1. cURL — The Essential API Testing Tool
cURL is one of the most widely used command-line tools for working with URLs and HTTP APIs. It is excellent for sending GET, POST, PUT, PATCH, and DELETE requests.
Install cURL
pkg install curl -y
Test a GET API Request
curl https://jsonplaceholder.typicode.com/posts/1
Show Response Headers
curl -I https://example.com
Send a POST Request
curl -X POST https://jsonplaceholder.typicode.com/posts \
-H "Content-Type: application/json" \
-d '{"title":"Hello","body":"Testing API","userId":1}'
Send an Authorization Token
curl https://api.example.com/profile \
-H "Authorization: Bearer YOUR_TOKEN"
Verbose API Debugging
curl -v https://api.example.com
Best for: Developers who want maximum control and a lightweight API client.
2. HTTPie — Human-Friendly API Testing
HTTPie is a command-line HTTP and API client designed to provide simpler syntax and formatted output. It supports JSON, headers, authentication, sessions, forms, uploads, and other common API workflows.
Install HTTPie
One common method in Termux is to install Python and then install HTTPie:
pkg install python -y
python -m pip install --upgrade pip
python -m pip install httpie
HTTPie's official documentation supports installation through Python's package ecosystem.
Test a GET Request
http https://jsonplaceholder.typicode.com/posts/1
Send JSON Data
http POST https://jsonplaceholder.typicode.com/posts \
title="Hello" \
body="Testing from Termux" \
userId:=1
Add a Custom Header
http https://api.example.com/users \
Authorization:"Bearer YOUR_TOKEN"
Use Basic Authentication
http -a username:password https://api.example.com/profile
Show Detailed Request Information
http -v https://api.example.com
HTTPie is particularly useful when you want readable, formatted terminal output and concise request syntax.
Best for: Beginners and developers who want a cleaner alternative to cURL.
3. Wget — Quick Endpoint Requests and Downloads
Wget is primarily known as a file-downloading utility, but it can also be useful for making simple HTTP requests and retrieving API responses.
Install Wget
pkg install wget -y
Download an API Response
wget -O response.json https://jsonplaceholder.typicode.com/posts/1
View the Response
cat response.json
Best for: Downloading API responses, files, and simple endpoint checks.
4. jq — Process and Filter JSON API Responses
jq is not an HTTP client by itself, but it is one of the most useful tools to combine with cURL or HTTPie. It allows you to filter, format, and extract information from JSON responses.
Install jq
pkg install jq -y
Format JSON Output
curl -s https://jsonplaceholder.typicode.com/posts/1 | jq
Extract a Specific Value
curl -s https://jsonplaceholder.typicode.com/posts/1 | jq '.title'
Extract Multiple Fields
curl -s https://jsonplaceholder.typicode.com/posts/1 | jq '{id, title}'
Filter an Array
curl -s https://jsonplaceholder.typicode.com/posts | jq '.[0:5]'
Best for: Reading, filtering, and automating JSON API responses.
5. Python Requests — API Testing with Scripts
If you need more advanced testing, automation, or repeated API requests, Python is a good option.
Install Python
pkg install python -y
Install Requests
pip install requests
Create an API Test Script
nano api_test.py
Add the following code:
import requests
url = "https://jsonplaceholder.typicode.com/posts/1"
response = requests.get(url)
print("Status Code:", response.status_code)
print(response.json())
Run the script:
python api_test.py
POST Request Using Python
import requests
url = "https://jsonplaceholder.typicode.com/posts"
data = {
"title": "Termux API Test",
"body": "Hello from Android",
"userId": 1
}
response = requests.post(url, json=data)
print(response.status_code)
print(response.json())
Best for: Automated testing, scripting, and reusable API test cases.
6. Node.js and Fetch — JavaScript API Testing
If you are a JavaScript developer, you can use Node.js in Termux for API testing and automation.
Install Node.js
pkg install nodejs -y
Create a JavaScript API Test
nano api.js
Add:
async function testAPI() {
const response = await fetch(
"https://jsonplaceholder.typicode.com/posts/1"
);
const data = await response.json();
console.log(data);
}
testAPI();
Run the script:
node api.js
Best for: JavaScript developers and automated API workflows.
Combine Tools for Better API Testing
One of the most powerful approaches is to combine command-line tools.
cURL + jq
curl -s https://jsonplaceholder.typicode.com/users | jq '.[].name'
This command requests user data and extracts only the names.
Save API Response to a File
curl https://api.example.com/data -o response.json
Check HTTP Status Code
curl -o /dev/null -s -w "%{http_code}\n" \
https://api.example.com
Measure API Response Time
curl -o /dev/null -s -w \
"Time: %{time_total}s\n" \
https://api.example.com
API Testing Tools Comparison
| Tool | Best Use | Difficulty | JSON Support |
|---|---|---|---|
| cURL | General API testing | Medium | Yes |
| HTTPie | Readable API testing | Easy | Excellent |
| Wget | Downloading responses | Easy | Basic |
| jq | JSON filtering | Medium | Excellent |
| Python Requests | Automation and scripting | Medium | Excellent |
| Node.js Fetch | JavaScript automation | Medium | Excellent |
Recommended Installation Command
If you want to prepare your Termux environment with several useful API development tools, you can start with:
pkg update && pkg upgrade -y
pkg install curl wget jq python nodejs git -y
python -m pip install --upgrade pip
python -m pip install httpie
Termux supports installing additional packages through its package management system, while HTTPie provides a command-line client specifically designed for API interaction and testing.
Recommended API Testing Workflow in Termux
A practical workflow for API development can look like this:
- Use cURL for quick endpoint testing.
- Use HTTPie when you want readable requests and responses.
- Use jq to filter JSON data.
- Use Python for automated testing.
- Use Node.js if your project is based on JavaScript.
- Use Git to manage your API testing scripts and projects.
For beginners, the combination of cURL + HTTPie + jq provides an excellent command-line API testing setup.
Important Security Tips
- Do not paste private API keys into screenshots or public repositories.
- Store sensitive tokens in environment variables when possible.
- Test only APIs you own or are authorized to access.
- Use HTTPS endpoints whenever available.
- Be careful when executing third-party scripts in Termux because they can modify files or damage your installation.
Example: Using an Environment Variable
export API_TOKEN="YOUR_TOKEN"
curl https://api.example.com/profile \
-H "Authorization: Bearer $API_TOKEN"
Frequently Asked Questions
Can I test APIs on Android using Termux?
Yes. Termux provides a Linux-like command-line environment where you can install tools such as cURL, Python, Node.js, jq, and other development utilities.
What is the best API testing tool for Termux?
For most users, cURL is the essential tool. HTTPie is easier to read and use for many API requests, while jq is useful for processing JSON responses.
Can I use HTTPie in Termux?
Yes. HTTPie can be installed through Python's package ecosystem and provides commands for sending HTTP requests with formatted output.
How can I send a POST request from Termux?
You can use cURL:
curl -X POST https://api.example.com \
-H "Content-Type: application/json" \
-d '{"name":"Sahil"}'
How do I read JSON responses easily?
Install jq and combine it with cURL:
pkg install jq
curl -s https://api.example.com/data | jq
Conclusion
Termux can turn your Android device into a capable command-line environment for API development and testing. For quick requests, use cURL. For a cleaner and more human-friendly experience, try HTTPie. Add jq for JSON processing and Python or Node.js when you need automation.
With these tools, you can test REST APIs, inspect headers, send JSON requests, work with authentication, automate repeated tests, and build lightweight API testing workflows directly from your Android device.
Quick Setup Commands
pkg update && pkg upgrade -y
pkg install curl wget jq python nodejs git -y
python -m pip install --upgrade pip
python -m pip install httpie
curl --version
http --version
jq --version







0 comments:
Post a Comment