Code Examples
Learn how to use our API with examples in different programming languages.
JavaScript (Fetch API)
// Get list of wallpapers
async function getWallpapers() {
try {
const response = await fetch('https://api.wallaza.com/v1/wallpapers', {
headers: {
'Authorization': 'Bearer YOUR_API_KEY'
}
});
const data = await response.json();
console.log(data);
} catch (error) {
console.error('Error:', error);
}
}
// Search wallpapers
async function searchWallpapers(query) {
try {
const response = await fetch(`https://api.wallaza.com/v1/search?q=${query}`, {
headers: {
'Authorization': 'Bearer YOUR_API_KEY'
}
});
const data = await response.json();
console.log(data);
} catch (error) {
console.error('Error:', error);
}
}
PHP (cURL)
// Get list of wallpapers
function getWallpapers() {
$ch = curl_init();
curl_setopt_array($ch, [
CURLOPT_URL => "https://api.wallaza.com/v1/wallpapers",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
"Authorization: Bearer YOUR_API_KEY",
"Content-Type: application/json"
]
]);
$response = curl_exec($ch);
$data = json_decode($response, true);
curl_close($ch);
return $data;
}
// Search wallpapers
function searchWallpapers($query) {
$ch = curl_init();
curl_setopt_array($ch, [
CURLOPT_URL => "https://api.wallaza.com/v1/search?q=" . urlencode($query),
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
"Authorization: Bearer YOUR_API_KEY",
"Content-Type: application/json"
]
]);
$response = curl_exec($ch);
$data = json_decode($response, true);
curl_close($ch);
return $data;
}
Python (requests)
import requests
# Get list of wallpapers
def get_wallpapers():
headers = {
'Authorization': 'Bearer YOUR_API_KEY'
}
response = requests.get('https://api.wallaza.com/v1/wallpapers', headers=headers)
return response.json()
# Search wallpapers
def search_wallpapers(query):
headers = {
'Authorization': 'Bearer YOUR_API_KEY'
}
params = {
'q': query
}
response = requests.get('https://api.wallaza.com/v1/search',
headers=headers,
params=params)
return response.json()
Node.js (axios)
const axios = require('axios');
const api = axios.create({
baseURL: 'https://api.wallaza.com/v1',
headers: {
'Authorization': 'Bearer YOUR_API_KEY'
}
});
// Get list of wallpapers
async function getWallpapers() {
try {
const response = await api.get('/wallpapers');
return response.data;
} catch (error) {
console.error('Error:', error.response.data);
throw error;
}
}
// Search wallpapers
async function searchWallpapers(query) {
try {
const response = await api.get('/search', {
params: { q: query }
});
return response.data;
} catch (error) {
console.error('Error:', error.response.data);
throw error;
}
}