Serverscript Response APIs


Send Response

Use this method to write content to response either as base64 string or as binary.

Syntax: $s.sendResponse(blob, contentType, fileName, isText, contentDisposition)

Parameters:

  • blob: (studioblob) The value that is to send in response.
  • contentType: (string) Type of content that is to send in response.
  • fileName: (string) The name of the content file that is to send in response.
  • isText: (boolean) The value to detect whether to send the content as base64 string or as binary.
  • contentDisposition: (boolean) The value to detect whether to directly download or render the content.

Exception: Throws error if there is any issue in writing content to response object.

Set Status

Use this method to set the HTTP response code.

Syntax: $s.setStatus(code)

Parameter:

  • code: The HTTP response code to help user aware of whether service call is success or failure.

Set Data

Use this method to set the response data that need to be sent as data or JSON object or JSON array.

Syntax: $s.setData(data)

Parameters:

  • data: (string / JSON object / JSON array) The output to send to the user.

Exception: Throws error if there is any issue in writing data to response object.

Set Message

Use this method to set the HTTP response message.

Syntax: $s.setMessage(message)

Parameters:

  • message: (string) The content to help user know what is the response of service call.

Exception: Throws error if there is any issue in writing data to response object.