Created
April 20, 2019 20:26
-
-
Save yoav-lavi/11e6b9e8e5b807ff20ddbb7d9d515229 to your computer and use it in GitHub Desktop.
request module for Scriptable
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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" | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.