Skip to content

Instantly share code, notes, and snippets.

@philschmid
Last active June 2, 2021 11:43
Show Gist options
  • Select an option

  • Save philschmid/06d93e81b05b9cc5f8d25b17573d0ca4 to your computer and use it in GitHub Desktop.

Select an option

Save philschmid/06d93e81b05b9cc5f8d25b17573d0ca4 to your computer and use it in GitHub Desktop.
const API_URL = "https:/{URL}/api/{TASK}"
async function query(payload) {
const body = JSON.stringify(payload)
try {
const response = await fetch(API_URL, {
method: 'post',
body
})
return response.json();
} catch (errr) {
console.error(errr)
}
}
import json
import requests
API_URL = "https:/{URL}/api/{TASK}"
def query(payload=''):
body = {"input":payload}
response = requests.request("POST", API_URL, data= json.dumps(body))
try:
response.raise_for_status()
except requests.exceptions.HTTPError:
return "Error:"+" ".join(response.json()['error'])
return response.json()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment