Chapter 11. Content Service

HtmlService can be used to render HTML content in response to HTTP requests to a published Apps Script web app. In this case, the Apps Script service is acting as web server. In addition to the web apps HTML capability, Apps Script can also serve up data as JSON (or JSONP), as well as XML and other formats. This allows you to create Apps Script apps that act as if they were a REST API, serving up processed data in response to query requests.

The Content Service

Just as with HtmlService, ContentService apps must be published as a web app, contain a doGet or doPost function to handle requests, and return results processed not by the HtmlService class, but by ContentService.

Where to Use the Content Service

It is possible to convert any script (even a container-bound one) into a published web app that can serve data through ContentService in response to HTTP queries, or content as HTML pages through HtmlService. These important capabilities mean that you can make visible the full power of scripting, and the data it can access, for consumption by a browser or some cooperating process.

The ContentService class can be used to expose Apps data such as spreadsheet content, calendar data, and JDBC database queries—in fact, anything processed with Apps Script can be published.

The Execution API was released recently, and you should consider it as an alternative when planning to use ContentService to create a private API to execute Apps Script functions. You ...

Get Going GAS now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.