Documentation Home -  API Home

request

The request object represents the incoming request from the user's web browser. It provides access to the details of the URL used to access your site (including the page parameters), any submitted form data, the headers provided by the browser, cookie details submitted by the browser, and a session id that allows you to track a single user across multiple requests.

Typical use of the request object is in creating pages that must display a form or handle the submitted form data as appropriate. An example page script might read as follows:

function display() {
   if( request.method === 'POST' ) {
      // Process submitted form data
      var id = request.getParameter('id');
      var content = request.getParameter('content');
      database.save('content',content);

      // Redirect to a page displaying stored form data
      renderer.redirect('/complete?id=' + id);
   } else {
      // Assume this is a GET request and display the form
      renderer.display();
   }
}

Properties

request.method

property
stringIdentifies the HTTP method verb used to invoke the page

Identifies the HTTP method verb used to invoke the path. Typically the value is 'GET' or 'POST'.

request.url

property
stringThe domain relative url used to invoke the page

Identifies the URL relative to the domain that was used to invoke the path.

For example:

For the above points the url property will have a value of /pathtest/page/foo when executing the scripts for the page even though neither /pathtest nor foo are part of the page context path.

request.appName

property
stringThe name of the application

The name of the application assigned when the application context was first created. For the root application context (/) this is always the string ROOT

request.appContext

property
stringThe context path of the application

Identifies the context path of the application that the page belongs to

For example:

For the above points the appContext property will have a value of /pathtest which is the path given to the application when it was created. The root application context (i.e. the path of the default application) is always /

request.pagePath

property
stringThe context path of the page relative to the application context

Identifies the context path of the page relative to the application.

For example:

For the above points the pagePath property will have a value of /page which is the path given to the page when it was created.

Note that the path components subsequent in the url to the page context but which do not map to any actual pages (i.e. /foo in the above example) will not be included in this value.

request.pageContent

property
stringProvides access to the raw page content

This value property provides access to the unprocessed page template content - that is any values of the form ${foo} will not be expanded against script variables as would be the case when the page renderer displays this value.

Note that the page content is also un-escaped; if rendered in the browser all tags will perform their normal operations. If you want to display the page contents literally (for example within a <pre>...</pre> block) you will need at a minimum to escape any < and & characters that occur in the content before they are rendered by the browser.

request.sessionId

property
stringA string value that can be used to identify a user within a browsing session.

A value that will remain consistent and unique for the duration of the user's browsing session. Because Chrome Server does not provide a dynamic "session" container the easiest way to retain information over multiple requests during a single browsing session is to use this value as a key for values stored in the database. For example:

// Obtain a database for the session key
var key = request.sessionId;
var userSessionDb = database.open(key);

// Store some session-specific information
var name = request.getParameter('name');
userSessionDb.save('name',name);
     

A typical value for the sessionId property is the string '0CE36B264B17F8A553493DF0E39417D0'.

Functions

request.getMethod()

function
Returns
stringRetrieves the HTTP method used to invoke the page

See the equivalent method property.

request.getUrl()

function
Returns
stringThe domain relative url used to invoke the page

See the equivalent url property.

request.getAppName()

function
Returns
stringThe name of the application

See the equivalent appName property.

request.getPagePath()

function
Returns
stringThe context path of the page relative to the application context

See the equivalent pagePath property.

request.getPageContent()

function
Returns
stringProvides access to the raw page content

See the equivalent pageContent property.

request.getSessionId()

function
Returns
stringA string value that can be used to identify a user within a browsing session.

See the equivalent sessionId property.

request.getParameters(name)

function
Parameters
namestringThe name of the parameters to retrieve
Returns
string[]Retrieve an array of any parameter values identified by the given key name

Retrieves the request parameters for the given key. If no parameters match the key, the returned value will be null, not an empty array.

In view of this, code to access parameter lists should normally be wrapped in a condition block thus:

var names = request.getParameters('names');
if( names ) {
   saveNames(request.sessionId,names);
}
     

Parameters can be GET parameters or POSTed form parameters. Where both are used the array will contain both sets of values.

request.getParameter(name)

function
Parameters
namestringThe name of the parameters to retrieve
Returns
stringConvenience method to retrieve a single named parameter value

Retrieves a single named parameter value by its key.

This behaves much as for the getParameters(name) method, but returns a single string value rather than an array of strings.

Where multiple parameter values are supplied for the given key, the first will be returned.

Where no parameter values are supplied for the given key, the null value will be returned.

Otherwise the single string value corresponding to the key will be returned.

request.getCookie(name)

function
Parameters
namestringThe name of the parameters to retrieve
Returns
stringRetrieves the named cookie values

Retrieves the named cookie values stored by the user's browser.

Cookies are simple named strings of information that can be stored in the user's browser between reuqests. They are described in internet standards document RFC2109. Cookie values can be deleted by the user at will, but subject to this they will survive between multiple browsing sessions. This differs from the sessionId value, so they can be used in a similar manner to define longer-term database keys, or they can be used to retain string data directly in the user's browser.

Cookies can be created using the response object's addCookie(name,value) method.

request.listParameters()

function
Returns
string[]Retrieves a list of the parameter key names

Retrieves an array of all of the parameter key names supplied. If no parameters have been supplied, this returns null, not an empty array.

By facilitating discovery of key names this method allows for the automated processing of dynamically created forms.

request.getHeaders(name)

function
Parameters
namestringThe name of the parameters to retrieve
Returns
string[]The array of header values retrieved for the given key

Retrieves an array of the header strings submitted by the browser for the given key name.

Note that an array is returned even if there is only a single header with the given name.

The following illustrates a typical usage to retrieve the user agent string submitted by most browsers:

var useragents = request.getHeaders('User-Agent');
if( useragents ) {
   var useragent = useragents[0];
   database.save('latestUserAgent',useragent);
}

Note: If no headers exist for the given key, an empty array is returned. This differs from the behaviour of most of the other get methods which generally return a null value instead.

request.listHeaders()

function
Returns
string[]Retrieves a list of the parameter key names

Retrieves an array of all of the header key names supplied in the request.

In principle if no headers are submitted with the incoming request this method will return null rather than an empty array. This would not normally arise, however, as the HTTP specification requires compliant user agents (browsers) to submit some standard headers.