Response Object Members

Explore the response object members for RESTlets in SuiteScript 2.1, including content and content type properties.

·2 min read·View Oracle Docs

The response object members of RESTlets in SuiteScript allow developers to handle HTTP responses effectively. This guide covers the properties available in the restlet.Response object and their usage in scripting.

What Are Response Object Members?

Response object members provide key information about the HTTP response generated by a RESTlet script. These members are accessible through the restlet.Response object, primarily utilized in RESTlet scripts.

Properties of the Response Object

Member NameReturn TypeDescription
Response.contentstringThe content of the RESTlet HTTP response.
Response.contentTypestringThe Content-Type header of the RESTlet HTTP response.

Both properties are read-only and play a crucial role in defining what the client receives after executing a RESTlet function.

Example Implementation

Here’s a basic example demonstrating how to use the response object in a RESTlet script:

suitescript
1/**
2 * @NApiVersion 2.1
3 * @NScriptType RESTlet
4 */
5define(['N/scriptTypes/restlet'],
6 function(restlet) {
7
8 const get = function () {
9 const htmlResponse = restlet.createResponse({
10 content: '<h1>Hello World</h1>',
11 contentType: 'text/html'
12 });
13
14 log.debug({
15 title: 'Response Content-Type header: ',
16 details: htmlResponse.contentType
17 });
18
19 return htmlResponse;
20 };
21 return { get: get };
22});

This example showcases how to create a simple HTML response with an appropriate content type using restlet.createResponse(options).

Who This Affects

  • Developers: Anyone creating or maintaining RESTlet scripts in NetSuite.
  • Administrators: Those managing SuiteScript implementations and ensuring best practices.

Source: This article is based on Oracle's official NetSuite documentation.

Key Takeaways

  • Response object members are essential for crafting HTTP responses in RESTlets.
  • Both content and contentType are read-only properties critical for defining response content.
  • The example provided illustrates how to implement a basic RESTlet response effective in real-world scripting.

Frequently Asked Questions (4)

What members are available in the restlet.Response object in SuiteScript?
The restlet.Response object in SuiteScript has two members: 'Response.content', which contains the content of the RESTlet HTTP response, and 'Response.contentType', which specifies the Content-Type header of the response.
Are the properties of the restlet.Response object read-only?
Yes, both the 'content' and 'contentType' properties of the restlet.Response object are read-only.
Can I customize the Content-Type of a RESTlet HTTP response in SuiteScript?
Yes, you can specify the Content-Type by setting the 'contentType' property when you create the response using restlet.createResponse().
Is it possible to modify the response content after the Response object has been created?
No, since the 'Response.content' property is read-only, it cannot be modified after the Response object is created.
Source: Response Object Members Oracle NetSuite Help Center. This article was generated from official Oracle documentation and enriched with additional context and best practices.

Was this article helpful?

More in REST Web Services

View all REST Web Services articles →