Execute .http
files from the command line
Warning
req is in early development and is not yet ready for use
req
is a command line toolkit to execute .http
files
// Comments can begin with slashes '/' or hashes '#' and last until the next newline character '\n'
# This is also a comment (I'll use '/' from now on but you are free to use both)
// Global variables (e.g. base url) can be defined with '@ident = <value>'
@base = https://api.company.com
// 3 '#' in a row mark a new HTTP request, with an optional name e.g. 'Delete employee 1'
### [name]
HTTP_METHOD <url>
Header-Name: <header value>
// You can also give them names like this, although names like this
// do not allow spaces e.g. 'Delete employee 1' must be 'DeleteEmployee1'
###
# @name <name>
# @name=<name>
# @name = <name>
HTTP_METHOD <url>
...
// Global variables are interpolated like this
### Get employee 1
GET {{base}}/employees/1
// Pass the body of requests like this
### Update employee 1 name
PATCH {{base}}/employees/1
Content-Type: application/json
{
"name": "Namey McNamerson"
}
See the Spec and Syntax Guide for more info.
Note
The custom javascript portions (e.g. the {% ... %}
blocks) of the spec are not implemented as these are editor specific and require a javascript runtime.
Compiled binaries for all supported platforms can be found in the GitHub release. There is also a homebrew tap:
brew install FollowTheProcess/tap/req
Given a .http
file containing http requests like this:
// demo.http
@base = https://localhost:5167
### Create a new item
POST {{base}}/todoitems
Content-Type: application/json
{
"id": "{{ $guid }}",
"name":"walk dog",
"isComplete":false
}
### Get All items
GET {{base}}/todoitems
### Update item
PUT {{base}}/todoitems/1
Content-Type: application/json
{
"id": 1,
"name":"walk dog",
"isComplete": true
}
### Delete item
DELETE {{base}}/todoitems/1
You can invoke any one of them, like this...
req do ./demo.http --request "Get All items"
This package was created with copier and the FollowTheProcess/go_copier project template.