RESTAPIResponse - setContentType(String contentType)

Assign a value to the Content-Type header in the web service response.

You must set a response content type before writing the response. The content type is set automatically for string responses, based on the request Accept header value.

Setting an invalid content type causes the response to default to JSON. Failing to set a content type results in a status code 500 error when sending a binary response.

See the W3 Content-Type header documentation for more information about this header.

Table 1. Parameters
Name Type Description
contentType String The content type of the response body, such as application/json.
Table 2. Returns
Type Description
void

responseBuilder.setContentType('application/json');