Why It's Great
The Unsplash API provides access to the world's most generous community of photographers. It's the engine behind thousands of apps, providing high-quality, royalty-free images for:
- Poster Apps: Create stunning print-on-demand products.
- Photo Editors: Offer a vast library of stock photos to users.
- Wallpaper Apps: Access millions of high-res backgrounds.
- UI Mockups: Populate your designs with beautiful, real-world imagery.
Quick Start
- Create Account: Sign up at unsplash.com/developers.
- Get API Key: Create a new application to get your Access Key.
- Fetch Photos: Use simple HTTP requests.
Example (JavaScript)
const url = 'https://api.unsplash.com/photos/random?client_id=YOUR_ACCESS_KEY';
async function fetchImage() {
try {
const response = await fetch(url);
const data = await response.json();
console.log('Image URL:', data.urls.regular);
console.log('Photographer:', data.user.name);
} catch (error) {
console.error('Error fetching image:', error);
}
}
fetchImage();
Example (HTTP)
GET /search/photos?query=nature
Host: api.unsplash.com
Authorization: Client-ID YOUR_ACCESS_KEY
The API returns a JSON response containing image URLs (raw, full, regular, small), photographer details, and download links.