Hi Guys,
After integrating Google Apps Script with many API's, including our own, we noticed URL Fetch sometimes gets a little bit complex and too verbose, specially when connecting with more complex endpoints, so we came up with a thin library on top of the URL Fetch that simplified all our integrations and we use pretty much on all projects that requires external connections. The idea is simply an fluent HttpRequest builder on top of URL Fetch, so:
Instead of:
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);
We do like:
var response = UrlFetchApp.newRequest('https://httpbin.org/post')
.setMethod('post')
.setHeader('token', 'xxx')
.addParam('key', 'yyy')
.setContentType('application/json')
.setPayload(JSON.stringify(data))
.fetch()
Having an HttpRequest object abstraction also help on making complex API connection logic much simpler.
We published it as a library here:
https://github.com/bkper/http-request-app
But we believe it could help lot more developers if it someday included as a native feature, so, we submitted a feature request that was already filled as an internal issue by the Google team:
https://issuetracker.google.com/issues/156446909
If you think that makes sense, It would be great if you star this issue, soo it would show Google more support and help them prioritize it.
Many thanks!
Mael