Crates.io | requestr-cli |
lib.rs | requestr-cli |
version | 0.1.0 |
source | src |
created_at | 2021-01-29 20:31:40.124425 |
updated_at | 2021-01-29 20:31:40.124425 |
description | CLI tool to store, share and run http request templates easily |
homepage | https://github.com/Semptic/requestr |
repository | https://github.com/Semptic/requestr |
max_upload_size | |
id | 348227 |
size | 40,865 |
Store, share and run http request templates easily
Install the cli tool with cargo install requestr
.
requestr uses request configuration to make HTTP requests. In the request template you can store following:
If you want to send a json to an endpoint you would setup following config. The config is stored in a yaml file.
url: https://your.host.com/api/user
method: post
header:
Content-Type: application/json
Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==
body: |
{
"name": "Stefan",
"id": 1001
}
If you store this in ./request.yaml
, you can make a request with requestr request.yaml
To increase reusability of the request configuration you can use template variables. We can
use {{ variable_name }}
to insert variables into the request config.
Using the above example it would be great if we could provide the name
and the id
from the cli. The modified config would look like:
url: https://your.host.com/api/user
method: post
header:
Content-Type: application/json
Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==
body: |
{
"name": "{{ user_name }}",
"id": {{ user_id }}
}
We can now provide user_name
and user_id
from the cli: requestr request.yaml -p user_name=Stefan -p user_id=42
For a lot of requests we want to share common template variables for different environments. One example could be different credentials and hosts for your test and production environment. To cope with this it is possible to create a yaml file per environment.
We modify the above example and add variables for the host and the Authorization.
request.yaml
url: https://{{ host }}/api/user
method: post
header:
Content-Type: application/json
Authorization: Basic {{ auth }}
body: |
{
"name": "{{ user_name }}",
"id": {{ user_id }}
}
To switch quickly between test and prod we can create following environment configs.
test.yaml
host: test-api.com
auth: 11111111111111111111111111==
prod.yaml
host: api.com
auth: 22222222222222222222222222==
To use one of those files you can run
requestr request.yaml --env test.yaml -p user_name=Stefan -p user_id=42