HTTP Client
Make HTTP requests to external APIs and services.
Quick Start
GET Request
node /path/to/skills/http-client/scripts/request.js GET https://api.example.com/data
POST with JSON
node /path/to/skills/http-client/scripts/request.js POST https://api.example.com/users '{"name":"John"}'
With Headers
node /path/to/skills/http-client/scripts/request.js GET https://api.example.com/data --header "Authorization: Bearer token123"
Scripts
request.js
General-purpose HTTP request script.
Usage:
node request.js <METHOD> <URL> [BODY] [OPTIONS]
Options:
--header "Key: Value" - Add custom header (can be used multiple times)
--output <file> - Save response to file
--timeout <ms> - Request timeout (default: 30000)
fetch-json.js
Simplified script for JSON APIs.
Usage:
node fetch-json.js <URL> [--post '{"data":"value"}']
Examples
Fetch JSON Data
node request.js GET https://jsonplaceholder.typicode.com/posts/1
Post Form Data
node request.js POST https://httpbin.org/post '{"key":"value"}' --header "Content-Type: application/json"
Download File
node request.js GET https://example.com/file.pdf --output downloaded.pdf
Response Format
The script outputs JSON with:
{
"status": 200,
"headers": { "content-type": "application/json" },
"body": { "response": "data" }
}
Error Handling
- Network errors return exit code 1 with error message
- HTTP errors (4xx, 5xx) return the response with status code
- Timeout errors after 30 seconds (configurable)