.http directives
Comment directives that add names, tags, auth, assertions, captures, files, scripts, and per-request network settings.
Directives are comment lines such as # @name above a request. Other .http tools ignore the ones they do not know, so the file stays portable.
# @name createOrder
# @tag orders
# @assert status == 201
# @assert body.status == pending
# @capture orderId = body.id
POST {{baseUrl}}/v1/orders
Content-Type: application/json
{ "sku": "KB-75", "qty": 1 }Directive list
| Directive | What it does |
|---|---|
@name, @tag | Name the request; tag it for filtering |
@auth | Set auth for this request. See Auth. |
@assert | Check the response after it arrives |
@capture | Save a value from the response into a variable |
@form, @file, @body-file | Form fields, file uploads, and a body read from a file |
@allow-external-files | Allow uploads from outside the collection folder |
@timeout | Request timeout in seconds |
@proxy, @insecure | Proxy for this request; skip TLS verification |
@graphql, @no-encode | Treat the body as GraphQL; send the URL without encoding |
Assertions
Operators: == != > < >= <= contains matches exists empty.
Targets: status, body.<path>, headers.<name>, time (ms), and size. The response panel shows each assertion as pass or fail.
Scripts
# @script:post
test("has an id", () => expect(res.body.id).to.exist);
bru.setVar("orderId", res.body.id);
# @end@script:preruns before send;@script:postruns after.- Scripts run in a JavaScript sandbox with a Bruno-style API:
req,res,bru,expect,test. console.logoutput appears inline.- Collection and folder scripts are not executed. Put scripts on the request.
Plugins
Plugins are JavaScript files that add pre and post hooks, custom auth (# @auth plugin name), and body renderers (*.body.js).
Rules worth knowing
- File, TLS, and proxy directives count only when they sit before the method line.
- Uploads from outside the collection folder are refused unless the request has
@allow-external-files. - A body line that starts with
#,###, or@name=is saved with one leading backslash, so it is not read as a directive.