A CLI-Based API Client for Simplified API Testing
Project description
SnapReq: A CLI-Based API Client for Simplified API Testing
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.
Key Features
- 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.
Installation
SnapReq is available on PyPI. Install it using pip:
pip install snapreq
Usage
Command Overview
To see all available commands, use:
snapr --help
Output:
usage: cli.py [-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
Performing Requests
SnapReq provides detailed help for each HTTP method. Below are examples for each method:
GET Request
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/data
Get Method Help:
snapr get --help
Output:
usage: cli.py 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)
POST Request
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/data
Post Method Help:
snapr post --help
Output:
usage: cli.py 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)
PUT Request
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/data
PATCH Request
Make a PATCH request to partially update resources.
snapr patch --data "field=value" --headers "Authorization=Bearer token" https://api.example.com/data
DELETE Request
Perform a DELETE request to remove resources.
snapr delete --headers "Authorization=Bearer token" https://api.example.com/resource
Advanced Options
-
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
Examples
Example 1: GET Request with Parameters and Headers
snapr get --params "search=python&limit=10" --headers "User-Agent=SnapReq" https://api.example.com/search
Example 2: POST Request with Data and Response File
snapr post --data "key1=value1&key2=value2" --headers "Content-Type=application/json" --output post_response.json https://api.example.com/resource
Contributing
Contributions are welcome! If you encounter any bugs or have feature suggestions, feel free to open an issue or submit a pull request.
License
This project is licensed under the MIT License. See the LICENSE file for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file snapreq-1.1.0.tar.gz.
File metadata
- Download URL: snapreq-1.1.0.tar.gz
- Upload date:
- Size: 8.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.10.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b73a61552b3bfee875d702c688f37fb27a0ffd3d0892e5dedbacba0a3b2c06c1
|
|
| MD5 |
f3b320f5aed9ffa5b0e79b5f5e94b15e
|
|
| BLAKE2b-256 |
04157dfe9f8ad7f7533f1288599c0a165b34947057a3cc8629f809b875762e36
|
File details
Details for the file snapreq-1.1.0-py3-none-any.whl.
File metadata
- Download URL: snapreq-1.1.0-py3-none-any.whl
- Upload date:
- Size: 8.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.10.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
acad56ab1cdcc705e0d4942b04026245509f8f38d147930195e6d21311ed5f6c
|
|
| MD5 |
bb775d4a5547449aaabc2bd9f0ce1b5d
|
|
| BLAKE2b-256 |
917760aa72997c8c3fce69b80646dafe1ad6f1811c20c218a84d10f063ecbc9a
|