Status: 200 | Response type: json
Output:{
response: "Hello",
}
Status: 400 | Response type: json
Output:{
"error": "missing x query"
}
Status: 500 | Response type: json
Output:{
error: "Something unexpected happened"
}
Status: 429 | Response type: json
Output:{
"error": "Too many requests, please try again later."
}
const fetch = require('node-fetch')
fetch('https://some-random-api.ml/chatbot?message=hello')
.then(res => res.json())
.then(json => {
console.log(json)
});
import requests
def fetch():
#making a GET request to the endpoint.
resp = requests.get("https://some-random-api.ml/chatbot?message=hello")
#checking if resp has a healthy status code.
if 300 > resp.status_code >= 200:
content = resp.json() #We have a dict now.
else:
content = f"Recieved a bad status code of {resp.status_code}."
print(content)
fetch())