RestApia Request Syntax
This is a basic request example. You can use variables, define request method, endpoint, add custom headers, cookies, and integrated tests.
!response.code == 200
!response.time.minutes < 1
Dynamic Variables
RestApia allows you to make your requests more flexible by using variables. These variables can be defined in any place before request body and then inserted dynamically into various parts of your request, including:
- Endpoint URLs
- Other variables
- Headers
- Cookies
- Request body
Defining Variables:
Variables are defined as key-value pairs. For example:
host: api.example.com
user_id: 12345
Using Variables:
To use a variable, enclose its name within {{ }}
. For instance:
POST https://{{host}}/users/{{user_id}}
Defining Requests
A request definition specifies the HTTP method and the target endpoint. Optionally, you can include query parameters.
Example:
GET https://{{host}}/api/v1/users?user_id=123&active_only=true
Custom Headers
You can add custom headers to your requests using the @
symbol followed by the header name and its value.
Examples:
@MyHeader: Meaw
@Authorization: Bearer {{token}}
@Content-Type: application/json
Injecting Cookies
To include cookies in your requests, use the $
symbol followed by the cookie name and its value.
Examples:
$secret: terces
$session_id: abc123
$user_pref: dark_mode
Integrated Testing
RestApia provides integrated testing to validate your request responses. You can write tests to verify:
- Response status codes
- Response times
- Specific values within the response body
- and moreā¦
Test Expressions:
Tests are written using JavaScript expressions, giving you powerful validation capabilities. For detailed information, refer to the tests feature page.
Examples:
!json.fact != null // Checks if the 'fact' value is not null
!response.code == 200 // Verifies that the response status code is 200 (OK)
!response.time.minutes < 1 // Ensures the response time is less than 1 minute
!json.user.id == {{user_id}} // Checks if the 'user.id' matches the defined variable