Photos
The Photos resource represents individual photos within albums. Each photo belongs to an album and includes URLs for both full-size and thumbnail images.
Base URL
bash
https://api.jsonplaceholder.dev
bash
http://localhost:3000
Schema
typescript
interface Photo {
id: number
albumId: number
title: string
url: string
thumbnailUrl: string
}
Endpoints
Get All Photos
bash
GET /photos
Response:
json
[
{
"albumId": 1,
"id": 1,
"title": "accusamus beatae ad facilis cum similique qui sunt",
"url": "https://via.placeholder.com/600/92c952",
"thumbnailUrl": "https://via.placeholder.com/150/92c952"
}
// ... 4999 more photos
]
Get Photos by Album
bash
GET /photos?albumId={albumId}
Parameters:
albumId
(number, query) - Filter photos by album ID
Response:
json
[
{
"albumId": 1,
"id": 1,
"title": "accusamus beatae ad facilis cum similique qui sunt",
"url": "https://via.placeholder.com/600/92c952",
"thumbnailUrl": "https://via.placeholder.com/150/92c952"
}
// ... more photos in album 1
]
Get Single Photo
bash
GET /photos/{id}
Parameters:
id
(number) - Photo ID
Response:
json
{
"albumId": 1,
"id": 1,
"title": "accusamus beatae ad facilis cum similique qui sunt",
"url": "https://via.placeholder.com/600/92c952",
"thumbnailUrl": "https://via.placeholder.com/150/92c952"
}
Create Photo
bash
POST /photos
Request Body:
json
{
"albumId": 1,
"title": "Beautiful sunset photo",
"url": "https://via.placeholder.com/600/sunset",
"thumbnailUrl": "https://via.placeholder.com/150/sunset"
}
Response: 201 Created
json
{
"id": 5001,
"albumId": 1,
"title": "Beautiful sunset photo",
"url": "https://via.placeholder.com/600/sunset",
"thumbnailUrl": "https://via.placeholder.com/150/sunset"
}
Update Photo (Full Replace)
bash
PUT /photos/{id}
Parameters:
id
(number) - Photo ID
Request Body:
json
{
"albumId": 1,
"title": "Updated photo title",
"url": "https://via.placeholder.com/600/updated",
"thumbnailUrl": "https://via.placeholder.com/150/updated"
}
Response: 200 OK
json
{
"id": 1,
"albumId": 1,
"title": "Updated photo title",
"url": "https://via.placeholder.com/600/updated",
"thumbnailUrl": "https://via.placeholder.com/150/updated"
}
Update Photo (Partial)
bash
PATCH /photos/{id}
Parameters:
id
(number) - Photo ID
Request Body: Partial photo object
json
{
"title": "New photo title"
}
Response: 200 OK
- Updated photo object
Delete Photo
bash
DELETE /photos/{id}
Parameters:
id
(number) - Photo ID
Response: 200 OK
json
{}
Examples
javascript
// Get all photos (warning: this returns 5000 photos!)
const photos = await fetch('http://localhost:3000/photos')
.then(res => res.json());
// Get photos by album (more manageable)
const albumPhotos = await fetch('http://localhost:3000/photos?albumId=1')
.then(res => res.json());
// Get single photo
const photo = await fetch('http://localhost:3000/photos/1')
.then(res => res.json());
// Create new photo
const newPhoto = await fetch('http://localhost:3000/photos', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
albumId: 1,
title: 'Morning landscape',
url: 'https://via.placeholder.com/600/landscape',
thumbnailUrl: 'https://via.placeholder.com/150/landscape'
})
}).then(res => res.json());
// Update photo title
const updatedPhoto = await fetch('http://localhost:3000/photos/1', {
method: 'PATCH',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
title: 'Updated landscape photo'
})
}).then(res => res.json());
bash
# Get photos by album (recommended over getting all photos)
curl http://localhost:3000/photos?albumId=1
# Get single photo
curl http://localhost:3000/photos/1
# Create new photo
curl -X POST http://localhost:3000/photos \
-H "Content-Type: application/json" \
-d '{
"albumId": 1,
"title": "Morning landscape",
"url": "https://via.placeholder.com/600/landscape",
"thumbnailUrl": "https://via.placeholder.com/150/landscape"
}'
# Update photo title
curl -X PATCH http://localhost:3000/photos/1 \
-H "Content-Type: application/json" \
-d '{"title": "Updated landscape photo"}'
# Delete photo
curl -X DELETE http://localhost:3000/photos/1
python
import requests
# Get photos by album (recommended)
album_photos = requests.get('http://localhost:3000/photos?albumId=1').json()
# Get single photo
photo = requests.get('http://localhost:3000/photos/1').json()
# Create new photo
new_photo = requests.post('http://localhost:3000/photos', json={
'albumId': 1,
'title': 'Morning landscape',
'url': 'https://via.placeholder.com/600/landscape',
'thumbnailUrl': 'https://via.placeholder.com/150/landscape'
}).json()
# Update photo title
updated_photo = requests.patch('http://localhost:3000/photos/1', json={
'title': 'Updated landscape photo'
}).json()
# Delete photo
requests.delete('http://localhost:3000/photos/1')
Performance Note
Large Dataset
The photos resource contains 5,000 items. When fetching all photos (GET /photos
), consider:
- Using pagination in your application
- Filtering by album (
?albumId=1
) to reduce payload size - Implementing client-side caching for better performance
Image URLs
All photo URLs use the placeholder service via.placeholder.com
:
- Full size:
https://via.placeholder.com/600/{color}
- Thumbnail:
https://via.placeholder.com/150/{color}
The colors are randomly generated hex values for variety.