Request File
Definition | An .http file which contains definition of (multiple) HTTP request(s). |
Naming Convention | <test-case-name>-req.http |
Purpose | Definition of HTTP requests which will be executed within test case. |
Example Usage | Single Request, Multiple (Named) Requests, Advanced Request File with Directives, Request File with Retry Directives |
Features
A request file can contain one or more HTTP requests. To separate requests, use the ###
comment line between two requests.
Named Request
You can also name your requests for easier management by adding a metadata line just before request definition:
# @name RequestName
GET https:/localhost:3001/customers
Content-Type: application/json
{
"Id": 3,
"FirstName": "Alice",
"LastName": "Johnson",
"Email": "alice.johnson@example.com"
}
Variables
All variables can be used in the request file with the {{variableName}}
notation.
💁♂️ When you want to use reference types for variables, make sure that they override
ToString()
method. During variable resolution,ToString()
will be called on them.
For named requests, you can access request and response data using the following syntax:
{{requestName.(request|response).(body|headers).(*|JPath|XPath)}}
# Example that will fetch 'Id' property from 'AddNewCarRequest' request's JSON body
{{AddNewCarRequest.request.body.$.Id}}
This gives you comprehensive access to headers and body content of named requests.