Fluent interface for Google Apps Script Url Fetch Service, to simplify HttpRequest building and 3rd party API integrations.
UrlFetchApp:
var options = {
'method' : 'post',
'header' : {
'token' : 'xxx'
}
'contentType': 'application/json',
'payload' : JSON.stringify(data)
};
var response = UrlFetchApp.fetch('https://httpbin.org/post?key=yyy', options);
HttpRequestApp:
var response = HttpRequestApp.newRequest('https://httpbin.org/post')
.setMethod('post')
.setHeader('token', 'xxx')
.addParam('key', 'yyy')
.setContentType('application/json')
.setPayload(JSON.stringify(data))
.fetch()
There is an open feature request to include it as a native feature in the URL Fetch Service. Please start this issue if you think it makes sense.
This library is already published as an Apps Script, making it easy to include in your project.
To add it to your script, do the following in the Apps Script code editor:
- Click on the menu item "Resources > Libraries..."
- In the "Add a Library" text box, enter the Script ID "1Iqaz0dbrlOXp9D2giO0DS6CDW_Q4IrgfhTJyYqxknww_OmFVF_4NQVR_" and click the "Select" button.
- Choose a version in the dropdown box (usually best to pick the latest version).
- Click the "Save" button.
You can also copy the ts
code on /src folder or the executable compiled script.
npm i -S @bkper/http-request-app-types
or
yarn add --dev @bkper/http-request-app-types
{
"compilerOptions": {
"typeRoots" : ["node_modules/@bkper", "node_modules/@types" ]
}
}
Learn more about @types, typeRoots and types