.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

DirectiveWhat it does
@name, @tagName the request; tag it for filtering
@authSet auth for this request. See Auth.
@assertCheck the response after it arrives
@captureSave a value from the response into a variable
@form, @file, @body-fileForm fields, file uploads, and a body read from a file
@allow-external-filesAllow uploads from outside the collection folder
@timeoutRequest timeout in seconds
@proxy, @insecureProxy for this request; skip TLS verification
@graphql, @no-encodeTreat 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

Plugins

Plugins are JavaScript files that add pre and post hooks, custom auth (# @auth plugin name), and body renderers (*.body.js).

Rules worth knowing

↑↓ move↩ open