While running your first Hello World on Scriptable can already be pretty exciting, you'll likely want to allow scripts to do a bit more advanced, like talking to another service via HTTP(S).
In this brief guide, you'll quickly learn how to extend what your scripts can do, including how to:
- Make Outbound HTTP requests using our custom, configurable fetch() implementation
- Add your own client and more to the script's global context
- Allow pre-authenticated HTTP calls without having to expose your access tokens directly to scripts of course
Outbound HTTP requests via fetch()
By default, scripts can use fetch() to talk to any HTTP endpoints.
Extending your script's global context
To make it easier for users to access your own or other product's APIs, you'll likely want to inject a pre-configured client into the global scope of your script's global context.
As you might have noticed, you can also provide some static data to your script's global context, simply by setting the property global on your request options.
Configure pre-authenticated HTTP calls for specific domains
On top of providing your own custom client or helper functions to your script's global context, you can also make requests to be "magically" authenticated without risking the authentication token being extracted by a malicious script.
Here's the above example, but with extra fetchCredentials configured for api.jsonbin.io.