REST Client variable syntax¶
REST Client variable syntax refers to the specific notation used within the Visual Studio Code REST Client extension to define, reference, and manipulate dynamic values in HTTP requests.^[600-developer__tools__vscode__RestClient-Postman.md]
Variable Definition¶
Custom variables are defined using the @ symbol at the beginning of a line, followed by the variable name and its value.^[600-developer__tools__vscode__RestClient-Postman.md]
Syntax:
@VariableName = Value
Common usage examples include: * Host Configuration: Defining a base URL or domain to avoid repetition^[600-developer__tools__vscode__RestClient-Postman.md].
@localhostBWS = http://localhost:8080/business-web-service/resources
@ContentType = application/json
Variable Request Reference¶
Once defined, variables are referenced in request lines or headers using double curly braces {{ }}.^[600-developer__tools__vscode__RestClient-Postman.md]
Syntax:
{{VariableName}}
This substitution mechanism allows for dynamic composition of request URLs and headers^[600-developer__tools__vscode__RestClient-Postman.md]. For example, a domain variable can be interpolated into the request path^[600-developer__tools__vscode__RestClient-Postman.md]:
@domain = {{localhostBWS}}
GET {{domain}}/workflow/allMission/count
Chained Requests and Response Capture¶
Variables can also derive their values from the response of a preceding request.^[600-developer__tools__vscode__RestClient-Postman.md] This allows for "chained" requests, such as performing a login and then using the returned session token in subsequent requests.
To enable this, the first request must be annotated with # @name^[600-developer__tools__vscode__RestClient-Postman.md].
Syntax:
# @name RequestName
Subsequent variables can then access the response body using the syntax:
{{RequestName.response.body.$.JSONPath}}^[600-developer__tools__vscode__RestClient-Postman.md].
Example: 1. Named Request:
# @name loginCWS
POST {{domain}}/sessions HTTP/1.1
...
@authToken = {{loginCWS.response.body.$.id}}
Authorization : {{authToken}}
Sources¶
^[600-developer__tools__vscode__RestClient-Postman.md]
Related Concepts¶
- [[REST Client]]
- [[JSONPath]]
- HTTP headers
- [[Chained requests]]