req is a command-line tool for sending http request.
Request tasks are defined in a file usually named req.toml
. For example:
[tasks.get]
GET = 'https://httpbin.org/get'
description = "GET request"
[tasks.post]
POST = 'https://httpbin.org/post'
description = "POST request"
To send request, run req
command with task name:
$ req get
# => GET https://httpbin.org/get
$ req post
# => POST https://httpbin.org/post
Without task name, req
prints list of tasks:
$ req
get GET request
post POST request
Print help information.
Print version information.
Read task definitions from <DEF>
. (default: req.toml
)
Include response headers in the output
Pass variable in the form KEY=VALUE
.
This option can be specified multple times.
Dump internal structure of specified task without sending request.
$ req get --dryrun
ReqTask {
method: Get(
"https://httpbin.org/get",
),
headers: {},
queries: {},
body: Plain(
"",
),
description: "GET request",
config: None,
}
Print compatible curl command. This feature may not perform stably.
$ req get --curl
curl -X GET 'https://httpbin.org/get'
Define a task named {NAME}
.
Speify description for the task.
Specify HTTP method and URL to send request.
Specify headers and queries as table to be given to request. Values of these table should be string or array of string.
Specify request plain text body with Content-Type: text/plain
.
[tasks.with-plain-text.body]
plain = "seinding body"
Specify request json body with Content-Type: application/json
.
[tasks.with-json.body.json]
number = 42
string = "foo"
nested.value = "bar"
Specify request form body with Content-Type: application/x-www-form-urlencoded
.
[tasks.with-form.body.form]
key = "value"
Specify request multipart body with Content-Type: multipart/form-data
.
To upload files, file path tagged with file
.
[tasks.post.body.multipart]
file-to-upload.file = "/path/to/upload/file"
text = "plain text"
Specify configure for each task. This setting overwrites top-level configure. See config for details.
Define variables for string interpolation. For example:
[variables]
DOMAIN = "example.com"
TOKEN = "XXXX-XXXX"
KEY = "interpolated-key"
[tasks.interp]
GET = "https://${DOMAIN}"
# => resolved by `GET = "https://example.com"`
[tasks.interp.headers]
Authorization = "Bearer ${TOKEN}"
# => resolved by `AUthorization = "Bearer XXXX-XXXX"`
[tasks.interp.queries]
"${KEY}" = "value"
# => resolved by `"interpolated-key" = "value"`
If true
, ignore verifying the SSL certificate. (default: false
)
Specify a maximum number of redirects. (default: 0
)