JSMA response

Overview

The JSMA response allows to manipulate the response that will be sent to the client

What can JSMA response do for me?

You could use the JSMA response to manipulate the response that will be sent to the client

Index

Usage

writing data

Here is an example on how to write data to a JSMA response:

...
var mimeType = request.parameter("mimetype");
var fileId = request.parameter("id");  
var file = files.findById(fileId);

if (file !== null)
{
  response.sendFile(file, mimeType);    
}
...

reading data

Here is an example on how to read data from a JSMA response :

... 
response.header
...

Methods

The JSMA file response the following methods:

header[] response.header

Returns the header of the response

Example

... 
response.header
...

response.sendError(code, [message])

Sets the status code of the response to the given error code

Example

... 
var file = files.findByUuid(request.parameter('id'));

if (file === null) {
  response.sendError(404);
  return;  
}
...

Parameter code (required)

Parameter message (optional)

response.sendFile(file, [mime])

Sets a JSMA file to be sent as the response body.

Example

... 
var mimeType = request.parameter("mimetype");
var fileId = request.parameter("id");
var file = files.findById(fileId);

if (file !== null)
{
response.sendFile(file, mimeType);
}
...

Parameter file (required)

Parameter mime (optional)

response.sendRedirect(target, [temp])

Sends a redirect response to the client

Example

... 
response.sendRedirect(target, [temp])
...

Parameter target (required)

Parameter temp (optional)

response.setHeader(key, value)

Sets a key/value pair in the response headers.

Example

... 
response.setHeader(key, value)
...

Parameter key (required)

Parameter value (required)