SnapReq is a command-line tool designed to simplify API testing and interactions, similar to Postman but entirely in the terminal. With SnapReq, you can easily perform GET, POST, PUT, PATCH, and DELETE requests on any provided URL. It supports adding headers, query parameters, or payloads and allows saving responses to files.
- Support for All HTTP Methods: Perform
GET,POST,PUT,PATCH, andDELETErequests. - Custom Headers: Add request headers using the
--headersoption. - Query Parameters and Data Payloads:
- Use
--paramsfor query parameters inGETrequests. - Use
--datafor payloads in other methods.
- Use
- Response Management:
- Save responses to a file with the
--outputoption. - View response headers using
--show-headers.
- Save responses to a file with the
- User-Friendly Help:
snapr --helpprovides an overview of available commands.snapr <method> --helpshows specific options for each HTTP method.
SnapReq is available on PyPI. Install it using pip:
pip install snapreqTo see all available commands, use:
snapr --helpOutput:
usage: snapr [-h] {get,post,put,patch,delete} ...
SnapReq: A simple API Client
options:
-h, --help show this help message and exit
commands:
{get,post,put,patch,delete}
get Make a GET request
post Make a POST request
put Make a PUT request
patch Make a PATCH request
delete Make a DELETE request
SnapReq provides detailed help for each HTTP method. Below are examples for each method:
Make a GET request with query parameters, headers, and optional response output.
snapr get --params "key1=value1&key2=value2" --headers "Authorization=Bearer token" --output response.json https://api.example.com/dataGet Method Help:
snapr get --helpOutput:
usage: snapr get [-h] [--headers HEADERS] [--show-headers] [--output OUTPUT] [--params PARAMS] url
positional arguments:
url API endpoint URL
options:
-h, --help show this help message and exit
--headers HEADERS Headers as a string of key-value pairs (e.g. header1=value1&header2=value2)
--show-headers, -sh Show response headers
--output OUTPUT, -o OUTPUT
Output file path
--params PARAMS, -p PARAMS
Query parameters as a string of key-value pairs (e.g. key1=value1&key2=value2)
Make a POST request with data, headers, and optional response output.
snapr post --data "key1=value1&key2=value2" --headers "Content-Type=application/json" --output response.json https://api.example.com/dataPost Method Help:
snapr post --helpOutput:
usage: snapr post [-h] [--headers HEADERS] [--show-headers] [--output OUTPUT] [--data DATA] url
positional arguments:
url API endpoint URL
options:
-h, --help show this help message and exit
--headers HEADERS Headers as a string of key-value pairs (e.g. header1=value1&header2=value2)
--show-headers, -sh Show response headers
--output OUTPUT, -o OUTPUT
Output file path
--data DATA, -d DATA Payload as a string of key-value pairs (e.g. key1=value1&key2=value2)
Make a PUT request similar to POST, using the --data option for payload.
snapr put --data "key1=value1" --headers "Authorization=Bearer token" https://api.example.com/dataMake a PATCH request to partially update resources.
snapr patch --data "field=value" --headers "Authorization=Bearer token" https://api.example.com/dataPerform a DELETE request to remove resources.
snapr delete --headers "Authorization=Bearer token" https://api.example.com/resource-
Show Response Headers: Use
--show-headers(or-sh) to print response headers to the console.snapr get --headers "Authorization=Bearer token" --show-headers https://api.example.com/data -
Save Response: Use
--output(or-o) to save the response body to a file.snapr get --output response.json https://api.example.com/data
snapr get --params "search=python&limit=10" --headers "User-Agent=SnapReq" https://api.example.com/searchsnapr post --data "key1=value1&key2=value2" --headers "Content-Type=application/json" --output post_response.json https://api.example.com/resourceContributions are welcome! If you encounter any bugs or have feature suggestions, feel free to open an issue or submit a pull request.
This project is licensed under the MIT License. See the LICENSE file for details.