Skip to content

Instantly share code, notes, and snippets.

@yoav-lavi
Created April 20, 2019 20:26
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save yoav-lavi/11e6b9e8e5b807ff20ddbb7d9d515229 to your computer and use it in GitHub Desktop.
Save yoav-lavi/11e6b9e8e5b807ff20ddbb7d9d515229 to your computer and use it in GitHub Desktop.
request module for Scriptable
// Variables used by Scriptable.
// These must be at the very top of the file. Do not edit.
// icon-color: green; icon-glyph: file-code;
module.exports = {
post: async ({ url, body, headers = {} }) => {
const request = new Request(url);
request.body = JSON.stringify(body);
request.method = methods.post;
request.headers = {
...defaultHeaders,
...headers
};
return await request.loadJSON();
},
put: async ({ url, body, headers = {} }) => {
const request = new Request(url);
request.body = JSON.stringify(body);
request.method = methods.put;
request.headers = {
...defaultHeaders,
...headers
};
return await request.loadJSON();
},
get: async ({ url, headers = {} }) => {
const request = new Request(url);
request.method = methods.get;
request.headers = {
...defaultHeaders,
...headers
};
return await request.loadJSON();
}
};
const defaultHeaders = {
Accept: "application/json",
"Content-Type": "application/json"
}
const methods = {
get: "GET",
post: "POST",
put: "PUT"
};
@totoLab
Copy link

totoLab commented Jul 26, 2022

Is this still relevant in making requests? I'm trying to get data from https://blockchain.info/rawaddr/$address but all I can get are errors and empty objects.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment