simple cli program to send requests
Project description
Cli-Requests
Cli-Requests is a command-line interface tool for simplifying HTTP requests. It allows you to effortlessly interact with APIs and websites directly from the terminal. This tool is designed to provide a seamless experience, enabling you to focus on making requests without the complexities of traditional tools.
Installation
To get started with Cli-Requests, you can install it using pip. Ensure you have Python 3.8 or higher installed.
pip3 install cli-requests
Usage
Cli-Requests makes it easy to send HTTP requests with various options. Here are some examples:
Basic Request
cli-requests https://example.com/
It's a basic GET request that will return nothing on success or an error.
Get Specific Response Data
You can use various command-line arguments to get specific information from the response:
--status-code
: Show the HTTP status code.--headers-content
: Show the response headers.--text-content
: Show the text content of the response.--binary-content
: Show the binary content of the response.--json-content
: Show the response content as JSON.--final-url
: Show the final URL after following redirects.--elapsed-time
: Show the elapsed time for the request.--cookies-content
: Show the cookies.
For example, to get the status code and headers, use:
cli_requests https://google.com --status-code --headers-content
This code will print stauts code and headers in console.
Save Response to a File
To save the response content to a file, you can use IO redirection with --nocolor argument or --output-file parameter. For example, to save the response to a file named output.txt
, use:
cli_requests https://google.com/ --headers-content --status-code --elapsed-time --nocolor > output.txt
OR
cli_requests https://google.com/ --headers-content --status-code --elapsed-time --output-file output.txt
output.txt example
Status Code:
200
Headers:
{'Date': 'Sat, 18 Nov 2023 14:05:29 GMT', 'Expires': '-1', ...}
Elapsed Time:
0:00:00.193750
Sending POST Request with JSON Data
cli-requests (YOUR URL) --method POST --data '{"key": "value"}'
Issue with Escaping Quotes in Windows Console when Using JSON Objects
When working with JSON objects in the Windows console, there might be issues due to the required escaping of quotes. You must pass JSON objects like this.
cli-requests (YOUR URL) --method POST --data '{\"key\": \"value\"}'
Reading Request Configuration from a File
URL is always required, so make sure that you passed it even with configuration file.
cli-requests (YOUR URL) --load-config path/to/request_config.json
Colorized Output
The output from cli-requests is always presented in color for improved readability. However, for those who prefer a monochromatic display or have specific requirements, there is an optional parameter --nocolor
. Adding this parameter to the command will disable the colorful output. For example:
cli-requests https://google.com --status-code --nocolor
Request Configuration
Create a JSON file to define your request configuration. Below is an example for a GET request:
{
"url": "YOUR URL",
"method": "GET",
"params": {
"key1": "value1",
"key2": "value2"
},
"headers": {
"Authorization": "Bearer YourAccessToken"
},
"timeout": 5000
}
List of parameters
Use -h
| --help
for help
Request parameters
-m
|--method
: HTTP method (default: GET)-p
|--params
: Request parameters (in JSON format)-f
|--files
: Files to upload with the request (in JSON format)-x
|--proxies
: Proxies for the request (in JSON format)-d
|--data
: Data for the request (in JSON format)-s
|--headers
: Headers for the request (in JSON format)-t
|--timeout
: Timeout for the request (in seconds)-a
|--auth
: Authentication credentials (username and password)-c
|--cookies
: Cookies for the request (in JSON format)-v
|--verify
: Verify SSL certificate (default: True)-e
|--cert
: Path to SSL certificate file-r
|--allow-redirects
: Allow redirects (default: True)
Additional parameters for displaying information:
-S
|--status-code
: Show the status code-H
|--headers-content
: Show the headers-T
|--text-content
: Show the text content-B
|--binary-content
: Show the binary content-J
|--json-content
: Show the JSON content-U
|--final-url
: Show the final URL-E
|--elapsed-time
: Show the elapsed time-C
|--cookies-content
: Show the cookies
Additional parameters:
-L
|--load-config
: Load configuration from a JSON file-O
|--output-file
: Save the output to a file
To disable colored output, use -w
| --nocolor
.
Contribution
Feel free to fork the project, make your changes, and submit a pull request.
License
Cli-Requests is licensed under the MIT License. See the LICENSE file for details.
Author
Sabberian
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
File details
Details for the file cli-requests-0.2.1.tar.gz
.
File metadata
- Download URL: cli-requests-0.2.1.tar.gz
- Upload date:
- Size: 6.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 67e2ba4948dc82e89bbc7cce8dbfa6c84808e902b454ab68c0db464643b6be9f |
|
MD5 | 0aa5c4db50ac8096a98b4c9b7f6e98e1 |
|
BLAKE2b-256 | 2181260a3ea438e5c483c014fd989b8a95533b4bacfa1ff078ac5ff0221dca6a |
File details
Details for the file cli_requests-0.2.1-py3-none-any.whl
.
File metadata
- Download URL: cli_requests-0.2.1-py3-none-any.whl
- Upload date:
- Size: 7.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 32eece741eee22ac0853cddaf041b57645f559ca39b4439f9f69ed8fc33f32b7 |
|
MD5 | aec61784da8e2ac36857e83695cf8c80 |
|
BLAKE2b-256 | 91d1acaf1280396a8cdeb9ba5b92b1ad66d0aebb60f8edea3d4d574ec7812469 |