Response interface

A JavaScript object implementing the Response interface represents an HTTP response.

Construction

Constructed by the Platform when a plugin handles a request, available through the response property of the Exchange object.

Interface

property headers

JavaScript Object for the response headers, acting as a dictionary.

property statusCode

The HTTP status code for the result. Use the constants defined in the HTTP constants.

property body

The body of the response. Set to a String.

Alternatively, set this property to BinaryData (eg generated files) or File objects. In these cases, appropriate headers will be added for the Content-Type and the download filename.

property kind

As an alternative to setting the Content-Type, set this property to the kind of response. Possible values are html, javascript, css, json, text, xml, xls, csv, tsv and yaml.

All Content-Type headers will include the UTF-8 charset option.

function redirect(url)

Sets this response to a HTTP redirect.

function setBackLink(url, text)

The standard HTML ‘chrome’ for a page includes an option link in the top left, which is used as a link back to the previous page. Use this to set the url path and, optionally, the text if you don’t want it to read “Back”.

This may more easily be set with the backLink and backLinkText keys in the view for the Exchange’s render() function.

function useStaticResource(resourceName)

When using the standard HTML ‘chrome’, include a static JavaScript or CSS resource from the plugin’s static directory. This will output a <script> or <link> tag based on the extension of the file.

The resource name is the filename, without any path, for example, "example.js".

If you need to include a static resource in a response which is not being generated by your plugin, use the std:plugin:resources() template function, and render the template, discarding the HTML it returns.

function setExpiry(seconds)

Set the expiry time of the response, specified as seconds into the future. This will set the Cache-Control and Expires headers of the response.