O'Reilly logo

Going GAS by Bruce Mcpherson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required