Request chaining
Request chaining lets one request use a value from another request’s response, such as a token from a login request. Courier uses the VS Code REST Client and httpyac syntax.
Name a request
Section titled “Name a request”Reference a request by its # @name. Set it in the @ field next to the request tabs. A request with no name is referenced by its file name.
### Log in# @name loginPOST {{baseUrl}}/v1/auth/loginReference a response
Section titled “Reference a response”### Who am I# @name meGET {{baseUrl}}/v1/meAuthorization: Bearer {{login.response.body.$.access_token}}| Reference | Value |
|---|---|
{{login.response.body.$.user.id}} |
JSONPath into the response body: $.a.b, [0], [*], ['odd key'] |
{{login.response.body.*}} |
The whole response body |
{{login.response.headers.X-Token}} |
A response header, matched in any case |
{{login.response.status}} |
The status code |
{{login.request.body.$.email}} |
The request body as it was sent |
{{login.request.headers.Name}} |
A request header as it was sent |
{{login.request.url}} |
The URL as it was sent |
Right-click a value in a JSON response → Copy as reference and paste it.
Hover a reference to see its value and which run it came from.
When referenced requests run
Section titled “When referenced requests run”Values come from the newest stored run of that request in this folder. By default, if the request has never run, Courier sends it first.
Change this in Settings → Requests → Run referenced requests first: When it has no stored response (the default), Every time, or Never (use the last response).
You can also declare dependencies in the file:
# @ref loginrunsloginfirst when needed, even if nothing references it.# @forceRef loginrunsloginevery time.
Courier catches loops, such as two requests referencing each other, and reports them.
In the command line
Section titled “In the command line”courier run runs referenced requests first, once per run. # @forceRef runs every time.