Retrieves the requested information from the defined URL or incoming client request
request.getMethod();
get
, post
, put
, delete
, option
Retrieves a single header from incoming client request, not case sensitive
request.getHeader('Content-Type');
application/json
Retrieves all header values from incoming client request
var headers = request.getHeaders();
headers['content-type'] = "application/json"
- jsonObject
Returns full path of URL, excluding current user and application name
request.getPath();
/resourceName/path
Returns requested path segment for URL
request.getPathSegment(1);
testApp
from /demoUser/testApp/resourceName/path
Returns full URL path including current user and application name
request.getFullPath();
/demoUser/testApp/resourceName/path
Retrieves the complete URL with Query Parameters
request.getFullUrl();
/demoUser/testApp/resourceName/path?q=Searched
Returns returns http or https
request.getProtocol();
https
Returns true or false depending on secure state
request.isSecure();
true
, false
Retrieves specified query parameters
URL: /demoUser/testApp/resourceName/path?q=Searched
request.getQueryParam('q');
Searched
Retrieves all query parameters
URL: /demoUser/testApp/resourceName/path?q=Searched
request.getQueryParams();
{q: "Searched"}
Retrieves specified post parameters
request.getPostParam('user');
testUser
Retrieves all Post parameters
POST Data: "test=User"
request.getPostParams();
{test: "User"}
Returns raw content data
request.getBody()
"{test:"Body"}"
-- Note: returns string
Returns the body content of XML or JSON parsed in object form rather than string
Body: {test:"Body"}
request.getBodyParsed();
{test:"Body"}
Note: return is JSON Object
Returns application name
request.getAppName();
testApp
Retrieves User name
request.getUser();
demoUser
Returns content type header with simplified value
request.getSimpleType();
json
- inferred from application/json
Verifies content type against simplified value
request.isType('json');
true
, false
Defines a current header with a new value
response.setHeader('X-Type', 'Yes');
Header: X-Type: Yes
Adds or replaces all current header values with a new values
response.setHeaders({'X-Type': 'Test', 'X-Reason': 'Why'});
Defines body data based on an object or string and converts to json or xml if optional type provided
response.setBody({test: "MyTest"}, 'json');
Header: Content-Type: application/json
Body: {test:"MyTest"}
Defines body data based on an object or string and converts to XML. Root element supported
response.setXMLBody({test:"MyTest"}, 'root');
Header: Content-Type: application/xml
Body: <root><test>MyTest</test></root>
Defines the simple type value for the application based on the data type
response.setSimpleType('json');
Header: Content-Type: application/json
Defines the status code that is sent in response to incoming client request
response.setStatusCode(204);
Header: HTTP/1.1 204 No Content
Used to redirect to an outside service or potentially an application
response.setRedirect('http://google.com');
Headers:
HTTP/1.1 301 Moved Permanently
Location: hhttp://google.com
Used to pause the response by X seconds
response.setPause(5);
Response takes 5 seconds to return to client