Making Your First Request
Let’s walk through making your first API call to API Cheap. We’ll use a simple example to get you started.
Prerequisites
Before you begin, make sure you have:
- ✅ Created an account
- ✅ Generated an API key
- ✅ A tool to make HTTP requests (curl, Postman, or code)
Example: Weather API
Let’s fetch weather data for a city using our weather endpoint:
Using cURL
curl -X GET \
"https://api.apicheap.com/v1/weather?city=london" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json"
Using JavaScript (Fetch)
const apiKey = 'YOUR_API_KEY';
const city = 'london';
async function getWeather() {
try {
const response = await fetch(`https://api.apicheap.com/v1/weather?city=${city}`, {
method: 'GET',
headers: {
'Authorization': `Bearer ${apiKey}`,
'Content-Type': 'application/json'
}
});
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const data = await response.json();
console.log('Weather data:', data);
return data;
} catch (error) {
console.error('Error fetching weather:', error);
}
}
getWeather();
Expected Response
A successful request will return:
{
"status": "success",
"data": {
"city": "London",
"country": "UK",
"temperature": 15,
"description": "Partly cloudy",
"humidity": 65,
"wind_speed": 12,
"timestamp": "2024-01-15T14:30:00Z"
},
"usage": {
"credits_used": 1,
"remaining_credits": 999
}
}
Next Steps
Great! You’ve made your first API call. Now you can:
- Explore more endpoints in our API Reference
- Learn about advanced features in our Guides
- Monitor your usage in the Dashboard