An API key is required to use the API programmatically. The key expires in 365 days. It is unique for every user. For example you can make a cURL request as follows to fetch a random fact:
curl -X GET https://cat.asid.dev/api/random/ -H "Authorization: Bearer YOUR_TOKEN_HERE" -H "Content-Type: application/json"
Here is an example using JavaScript:
const url = "https://cat.asid.dev/api/random/";
const token = "YOUR_TOKEN_HERE";
fetch(url, {
method: "GET",
headers: {
"Authorization": `Bearer ${token}`,
"Content-Type": "application/json"
}
})
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error("Error:", error));
Note that this will return a JSON response object. To parse the fact use:
data.fact