Request

Request API.

Holds request (input) information for the script.

Methods

Request has the following parameters:

Method

Description

keys()

Lists provided URL parameter names.

get(name)

Gets URL parameter with specified name.name string.

has(name)

Signals whether URL parameter with specified name exists in request.name string.

body()

Returns request body or null for GET requests.

mimeType()

Returns body mimetype or null for GET requests.

header(name)

Returns the first value of the specified header, if exists

object()

Returns parsed request body object for requests with body mime types of "application/x-www-form-urlencoded" or "application/json"

Properties

Request has the following properties:

Property

Description

headers

JSON object – provides header values

params

JSON object – provides URL parameters.

user

JSON object – provides information about the logged user.

method

String – name of request method (GET or POST).

Example

Let's say we have added following requests parameters:
Db_id = 51bf5ec1975a2d55263801cd, collection = books.
And we added the request body data string: "some useful information".
Your URL will look like this:

https://api.<appery.domain>/rest/1/code/<scriptGUID>/exec?Db_id=51bf5ec1975a2d55263801cd&collection=books
// Echo service: replies with specified parameters
var responseBody = {},
    requestParams = {},
    paramKeys = Apperyio.request.keys(); // returns array of request parameters ["Db_id", "collection"]
 
for (var key = 0; key < paramKeys.length; key++) {
    requestParams[paramKeys[key]] = Apperyio.request.get(paramKeys[key]); // returns value of request parameter by its name
 
}
 
responseBody.requestBody = Apperyio.request.body(); // responseBody.requestBody now contains "some useful information"
responseBody.requestParams = requestParams; // responseBody.requestParams now contains object { "DB_id": "51bf5ec1975a2d55263801cd", "collection": "books" }
responseBody.method = method; // responseBody.method now contains string "GET" or "POST".
 
Apperyio.response.success(responseBody, "application/json");