Context
Context
The Context
is an object that acts as a proxy to the document data. A context is created for each evaluation and is destroyed after. It is passed as the first argument of the generate
, import
, evaluate
, title
and text
methods of the Extensions.
allowsMutation
allowsMutation
Returns a boolean, whether the context is mutable (if we can use setters, and creation/update/delete methods). True
only for Importers.
(Read-only)
getCurrentRequest
getCurrentRequest
Returns:
None: Request
The current
Request.
function evaluate(context) {
// access the current request
var request = context.getCurrentRequest();
// return its name (for example)
return request.name;
}
getRequestByName
getRequestByName
Argument:
name: string: None
Name of a
Request
Returns:
None: Request
Returns a
Request by its name, or
null
if not found.
function evaluate(context) {
// find a request by its name
var request = context.getRequestByName("My API (2)");
if (null !== request) {
// return its URL (for example)
return request.url;
}
return null;
}
getRequestGroupByName
getRequestGroupByName
Returns:
None: RequestGroup
Returns a
RequestGroup by its name, or
null
if not found.
function evaluate(context) {
// find a request by its name
var requestGroup = context.getRequestGroupByName("My Group");
if (null !== request) {
// return its URL (for example)
return request.url;
}
return null;
}
getRootRequestTreeItems
getRootRequestTreeItems
getRootRequests
getRootRequests
Returns:
None: Array
Returns all requests at the root (with no parent group), as an array of Request objects.
getRootGroups
getRootGroups
Returns:
None: Array
Returns all groups at the root (with no parent group), as an array of RequestGroup objects.
getAllRequestTreeItems
getAllRequestTreeItems
Returns:
None: Array
Returns all items (either request or group) in the document, as an array of Request and RequestGroup objects.
getAllRequests
getAllRequests
Returns:
None: Array
Returns all requests in the document, as an array of Request objects.
getAllGroups
getAllGroups
Returns:
None: Array
Returns all groups in the document, as an array of RequestGroup objects.
getEnvironmentDomainByName
getEnvironmentDomainByName
getEnvironmentVariableByName
getEnvironmentVariableByName
getRequestById
getRequestById
Argument:
id: string: None
UUID of a
Request
Returns:
None: Request
Returns an
Request by its id or
null
getRequestGroupById
getRequestGroupById
Returns:
None: RequestGroup
Returns an
RequestGroup by its unique identifier or
null
getEnvironmentDomainById
getEnvironmentDomainById
Returns:
None: EnvironmentDomain
Returns an
EnvironmentDomain by its unique identifier or
null
getEnvironmentVariableById
getEnvironmentVariableById
Returns:
None: EnvironmentVariable
Returns an
EnvironmentVariable by its unique identifier or
null
getEnvironmentById
getEnvironmentById
Returns:
None: Environment
Returns an
Environment by its unique identifier or
null
createRequest
createRequest
Argument: name: string: None
Name of new request
Argument: method: string: None
HTTP method for this new request
Argument: url: DynamicString: None
The url of this new request
Argument: description: string: None
The text description of this new request
Argument: order: integer: None
The order of the request in the root item (orders starts at 0).
Returns:
None: Request
Returns the new
Request
The new request will be added to the end to the document tree (or at the specified order
) at the top level. This can be later moved to a new location by adding the request to a RequestGroup object.
function import(context, items, options) {
// create a new request
var request = context.createRequest("Users", "GET", "http://api.example.com/users");
// set more attributes
request.setHeader("Accept", "application/json");
}
createRequestGroup
createRequestGroup
Argument: name: string: None
Name of new group
The new group will be added to the end to the document tree at the top level. This can be later moved to a new location by adding the request to a RequestGroup object.
function import(context, items, options) {
// create the request group giving its name
var group = context.createRequestGroup('My Group');
// create a new request
var request = context.createRequest("Users", "GET", "http://api.example.com/users");
// add request to group
group.appendChild(request);
}
createEnvironmentDomain
createEnvironmentDomain
Argument: name: string: None
Name of new domain