Skip to content

Instantly share code, notes, and snippets.

@ideiudicibus
Created April 5, 2016 12:22
Show Gist options
  • Save ideiudicibus/15612f9f75e3940193e008a1b047cb43 to your computer and use it in GitHub Desktop.
Save ideiudicibus/15612f9f75e3940193e008a1b047cb43 to your computer and use it in GitHub Desktop.
function doGet(e) {
if(typeof e !== 'undefined')
return ContentService.createTextOutput(JSON.stringify(e.parameter));
}
function doPost(e) {
if(typeof e !== 'undefined')
return ContentService.createTextOutput(JSON.stringify(e.parameter));
}
function testPOST() {
var url = ScriptApp.getService().getUrl();
var payload =
{
"name" : "labnol",
"blog" : "ctrlq",
"type" : "post",
};
var options =
{
"method" : "POST",
"payload" : payload,
"followRedirects" : true,
"muteHttpExceptions": true
};
var result = UrlFetchApp.fetch(url, options);
if (result.getResponseCode() == 200) {
var params = JSON.parse(result.getContentText());
Logger.log(params.name);
Logger.log(params.blog);
}
}
function testGET() {
var queryString = "?name=labnol&blog=ctrlq&type=get";
var url = ScriptApp.getService().getUrl() + queryString;
var options =
{
"method" : "GET",
"followRedirects" : true,
"muteHttpExceptions": true
};
var result = UrlFetchApp.fetch(url, options);
if (result.getResponseCode() == 200) {
var params = JSON.parse(result.getContentText());
Logger.log(params.name);
Logger.log(params.blog);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment