Skip to content

Fetching from the API

The RESTasaurus API can be accessed using various tools and programming languages. Below are examples for common use cases.

https://restasaurus.onrender.com/api/v1
Terminal window
# Get all dinosaurs (first page)
curl https://restasaurus.onrender.com/api/v1/dinosaurs?page=1
# Get dinosaur by name
curl https://restasaurus.onrender.com/api/v1/dinosaurs?name=Tyrannosaurus
# Get dinosaurs by diet
curl https://restasaurus.onrender.com/api/v1/dinosaurs?diet=Carnivore
// Using fetch
async function fetchDinosaurs() {
try {
const response = await fetch(
'https://restasaurus.onrender.com/api/v1/dinosaurs?page=1'
);
if (!response.ok) {
throw new Error(`Failed to fetch dinosaurs with status: ${response.status}`);
}
const data = await response.json();
console.log('Successfully fetched dinosaurs');
return data;
} catch (error) {
console.error('Failed to fetch dinosaurs:', error);
throw error;
}
}
// Using axios
import axios from 'axios';
async function fetchDinosaurs() {
try {
const response = await axios.get(
'https://restasaurus.onrender.com/api/v1/dinosaurs?page=1'
);
console.log('Successfully fetched dinosaurs');
return response.data;
} catch (error) {
console.error('Failed to fetch dinosaurs:', error.message);
throw error;
}
}
import requests
# Using requests
def fetch_dinosaurs():
try:
response = requests.get('https://restasaurus.onrender.com/api/v1/dinosaurs?page=1')
response.raise_for_status()
print('Successfully fetched dinosaurs')
return response.json()
except requests.exceptions.RequestException as error:
print(f'Failed to fetch dinosaurs: {error}')
raise

If you need to ensure the API is responsive before making requests, you can “warm it up” by pinging the /dinosaurs?page=1 endpoint:

Terminal window
# Warm up the API and ensure it is running before making other requests
curl https://restasaurus.onrender.com/api/v1/dinosaurs?page=1

This will trigger the service to wake up, ensuring subsequent requests are faster.