Code Generator API
ExportRequest
The resolved request a generator turns into code.
Declaration
function generate(req /* ExportRequest */, r) { … }Overview
The first argument to generate is a plain JavaScript object describing the request as Relay would send it. Relay has already applied everything a generator shouldn't have to work out:
- Variables are replaced with their values, unless Reveal Variables is off in the Preview panel's options.
- Inherited authentication is resolved to the level that applies. Bearer, basic, Digest, NTLM, AWS Signature, OAuth 1.0 and Hawk authentication are described in
auth, so a generator can use its client's own idiom. API keys, JWTs and OAuth 2.0 tokens arrive as ordinary headers or query parameters. - Turned-off rows and rows without a name are left out.
- The request's settings are resolved from its folders, collection, workspace and Relay's defaults.
A property that doesn't apply is absent rather than null, so test for it before you use it: if (req.settings && !req.settings.verifiesCertificates) { … }.
For a JSON POST request, req looks like this:
{
"kind": "http",
"name": "Create item",
"method": "POST",
"url": "https://api.example.com/items?draft=true",
"urlWithoutQuery": "https://api.example.com/items",
"urlParts": { "scheme": "https", "host": "api.example.com", "path": "/items", "query": "draft=true" },
"headers": [
{ "name": "Accept", "value": "application/json" },
{ "name": "User-Agent", "value": "Relay" },
{ "name": "Content-Type", "value": "application/json" }
],
"queryParams": [{ "name": "draft", "value": "true" }],
"body": { "type": "json", "text": "{\n \"name\": \"Widget\"\n}", "contentType": "application/json" },
"auth": { "type": "bearer", "token": "abc123" },
"cookies": [{ "name": "session", "value": "xyz" }],
"settings": { "timeout": 30, "followsRedirects": true, "maximumRedirects": 10, "verifiesCertificates": true },
"meta": { "missingVariables": [], "variablesResolved": true }
}Topics
Properties
Prop
Type
URLParts
Prop
Type
Header
A name and value pair, used for headers, query parameters, form fields and cookies.
Prop
Type
Body
Prop
Type
Part
Prop
Type
GraphQL
Prop
Type
Auth
Only the properties for the auth's type are present.
Prop
Type
Settings
Prop
Type
WebSocket
Prop
Type
Message
Prop
Type
Meta
Prop
Type
See Also
- generate: The function that turns a request into code.
- relay: The helper functions for building, quoting and encoding generated code.
- Generating code from requests: Turn a request into code for curl, Python, JavaScript, Swift and other languages.