Response Object Members
Explore the response object members for RESTlets in SuiteScript 2.1, including content and content type properties.
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 Name | Return Type | Description |
|---|---|---|
Response.content | string | The content of the RESTlet HTTP response. |
Response.contentType | string | The 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:
1/**2 * @NApiVersion 2.13 * @NScriptType RESTlet4 */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.contentType17 });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
contentandcontentTypeare 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?
Are the properties of the restlet.Response object read-only?
Can I customize the Content-Type of a RESTlet HTTP response in SuiteScript?
Is it possible to modify the response content after the Response object has been created?
Was this article helpful?
More in REST Web Services
- New Attach and Detach Operations in REST Web Services NetSuite
NetSuite 2026.1 introduces new attach and detach operations in REST web services to manage record relationships efficiently.
- NetSuite Tool Permissions: Visibility and Access Essentials
Explore NetSuite MCP Standard Tools permissions affecting tool visibility.
Advertising
Reach REST Web Services Professionals
Put your product in front of NetSuite experts who work with REST Web Services every day.
Sponsor This Category