.http syntax
Reqjet reads and writes the .http format that Visual Studio, VS Code REST Client and JetBrains IDEs use. Reqjet’s
own extras are written as comments (# @reqjet.…), which other tools ignore, so your files stay portable.
A request
Section titled “A request”@baseUrl = https://httpbin.org # a file variable
### Create an item # ### starts a request; the text after it is its title# @name createItem # a name, for chaining# @reqjet.assert status == 200 # a test (a plain comment to other tools)POST {{baseUrl}}/anythingContent-Type: application/json
{ "id": "{{$guid}}", "at": "{{$datetime iso8601}}" }- The request line is a method, the URL and an optional
HTTP/1.1. Any method works. A long query string can continue on the following lines, each starting with?or&. - Headers follow, one per line. A blank line ends them, and the body follows.
- Comments start with
#or//. A comment that starts with# @is a directive. {{name}}is a variable. See Environments and variables and Built-in variables.
Bodies
Section titled “Bodies”POST {{baseUrl}}/uploadContent-Type: application/json
< ./payload.json| Written as | Sends |
|---|---|
| Text after the headers | That text, with {{variables}} filled in. |
< ./payload.json |
The file, unchanged. The path is relative to the .http file. |
<@ ./payload.json |
The file, with {{variables}} filled in first. |
Multipart uploads (Content-Type: multipart/form-data; boundary=…) can send files alongside form fields: a part’s
content can be < ./photo.png or <@ ./note.txt.
Saving the response
Section titled “Saving the response”GET {{baseUrl}}/report.csv
>> ./out/report.csv>> pathwrites the response body to a file, relative to the.httpfile. If the file exists, the new one isreport-1.csv,report-2.csvand so on.>>! pathoverwrites the file instead.- Files are only saved inside the folder the requests are in. A path outside it is refused.
Sign-in headers
Section titled “Sign-in headers”Basic, Digest, AWS and Windows sign-in are written as the Authorization header, in VS Code REST Client’s form, and
Reqjet works out the real header when it sends the request. You can also choose them on a request’s Auth tab.
Authorization: Basic {{user}}:{{password}} # base64-encoded when sentAuthorization: Digest {{user}} {{password}} # answered when the server challengesAuthorization: AWS {{accessKey}} {{secretKey}} # AWS Signature Version 4Authorization: NTLM CORP\ann {{password}} # Windows sign-in as someone elseAuthorization: Negotiate # Windows sign-in as you (Kerberos or NTLM)Authorization: Bearer {{$auth.token("my-api")}} # an OAuth 2.0 tokenOAuth 2.0 profiles are set in the environment files.
GraphQL
Section titled “GraphQL”GRAPHQL https://countries.trevorblades.com/graphql
query Country($code: ID!) { country(code: $code) { name capital }}
{ "code": "GB" }Use the GRAPHQL method (JetBrains), or an X-REQUEST-TYPE: GraphQL header (VS Code REST Client). The body is the
query, optionally followed by a blank line and a JSON object of variables.
WebSockets and server-sent events
Section titled “WebSockets and server-sent events”### Price feedWEBSOCKET wss://feed.example.com/prices
{ "subscribe": "EURUSD" }=== wait-for-server{ "subscribe": "GBPUSD" }
### NotificationsGET {{baseUrl}}/notificationsAccept: text/event-streamWEBSOCKETconnects and sends the body’s messages in order.===separates messages, and=== wait-for-serverwaits for a message from the server before sending the next.- A request with
Accept: text/event-streamis read as a stream of server-sent events.
Scripts
Section titled “Scripts”< {% request.variables.set("requestId", $random.uuid);%}GET {{baseUrl}}/meX-Request-Id: {{requestId}}
> {% client.test("Status is 200", () => client.assert(response.status === 200));%}< {% … %}before the request line is a pre-request script.> {% … %}after the request is a response handler.> ./handler.jsruns a handler from a file.- They use the JetBrains script API, and run in a sandbox with no access to your files.