Simple Google Apps Script UrlFetchApp wrapper supporting message authentication with KaleoJWT
KaleoSoftware/KaleoJWT: Super simple, portable JWT implementation that supports only SHA256 algo
- request()
- requestJSON()
- clone this repo
- clasp init & clasp push
- deploy this as Library and memo Library ID from Project settings
- add Library with memoed ID from Script Editor
const client = GasHttpClient.createClient(UrlFetchApp, 'https://example.com')
client.opts({
method: 'post',
payload: {
thank: 'you',
very: 'mutch',
exp: new Date('2017-07-22').getTime()
},
withJWT: {
'secret': 'abc',
'headerField': 'X-GAS-JWT',
}
})
const response = client.requestJSON('/post')
Note: requestJSON()
add header Accept: application/json
and Content-Type: application/json
automatically.
You can use opts()
, headers()
and buildParam()
or buildParamJSON()
for tesing of building HTTP request, without deploying to Google Apps Script to do real HTTP request.