Anatomy of .http files — requests, headers, bodies, assertions, captures, and more.
hitspec tests live in plain text files with .http or .hitspec extensions. Each file contains one or more HTTP requests along with optional variables, assertions, and captures.
@baseUrl = https://api.example.com@token = my-secret-token### Get all users# @name getUsers# @tags smoke, usersGET {{baseUrl}}/usersAuthorization: Bearer {{token}}>>>expect status 200expect body type array<<<>>>capturetotal from header X-Total-Count<<<### Get single user# @name getUser# @depends getUsersGET {{baseUrl}}/users/1>>>expect status 200expect body.id == 1<<<
Use ### to separate multiple requests within a single file. Everything before the first ### (or before the first request line if no separator is used) is treated as the file-level scope for variable definitions.
Copy
### First requestGET https://api.example.com/posts>>>expect status 200<<<### Second requestGET https://api.example.com/users>>>expect status 200<<<
The ### separator is required when a file contains more than one request. Text after ### on the same line is treated as a human-readable title and is ignored by the parser.
Headers follow the request line, one per line, using standard Name: Value format:
Copy
POST {{baseUrl}}/usersContent-Type: application/jsonAuthorization: Bearer {{token}}Accept: application/jsonX-Request-Id: {{$uuid()}}
A blank line separates headers from the request body. Any lines after the blank line (until the next block marker or separator) are treated as the body.
POST {{baseUrl}}/graphqlContent-Type: application/json>>>graphqlquery GetUsers($limit: Int) { users(limit: $limit) { id name email }}<<<>>>variables{ "limit": 10}<<<
Reference an external file as the request body using < ./path:
Copy
POST {{baseUrl}}/usersContent-Type: application/json< ./fixtures/user.json
The file path is resolved relative to the .http file’s directory. Content-Type is auto-detected from the file extension (.json, .xml, .yaml, .html, .csv, .txt) when no explicit Content-Type header is set.Variable interpolation works in the file path:
Copy
POST {{baseUrl}}/importContent-Type: application/json< ./fixtures/{{scenario}}.json
Capture response values for use in later requests:
Copy
POST {{baseUrl}}/auth/loginContent-Type: application/json{"email": "test@example.com", "password": "secret"}>>>capturetoken from body.access_tokenuserId from body.user.id<<<
The @waitFor directive polls a URL before executing the request. This is useful when your test depends on a service that may not be immediately available (e.g., a container that was just started).
Copy
### Create order (waits for payment service)# @waitFor http://localhost:4000/health 200 30000 1000POST {{baseUrl}}/ordersContent-Type: application/json{"product": "Widget", "quantity": 1}