Users
The Users resource provides access to user account information including personal details, contact information, and company data.
Base URL
bash
https://api.jsonplaceholder.dev
bash
http://localhost:3000
Schema
typescript
interface User {
id: number
name: string
username: string
email: string
address: {
street: string
suite: string
city: string
zipcode: string
geo: {
lat: string
lng: string
}
}
phone: string
website: string
company: {
name: string
catchPhrase: string
bs: string
}
}
Endpoints
Get All Users
bash
GET /users
Response:
json
[
{
"id": 1,
"name": "Leanne Graham",
"username": "Bret",
"email": "[email protected]",
"address": {
"street": "Kulas Light",
"suite": "Apt. 556",
"city": "Gwenborough",
"zipcode": "92998-3874",
"geo": {
"lat": "-37.3159",
"lng": "81.1496"
}
},
"phone": "1-770-736-8031",
"website": "bret.org",
"company": {
"name": "Romaguera-Crona",
"catchPhrase": "Multi-layered client-server neural-net",
"bs": "harness real-time e-markets"
}
}
// ... 9 more users
]
Get Single User
bash
GET /users/{id}
Parameters:
id
(number) - User ID
Response:
json
{
"id": 1,
"name": "Leanne Graham",
"username": "Bret",
"email": "[email protected]",
"address": {
"street": "Kulas Light",
"suite": "Apt. 556",
"city": "Gwenborough",
"zipcode": "92998-3874",
"geo": {
"lat": "-37.3159",
"lng": "81.1496"
}
},
"phone": "1-770-736-8031",
"website": "bret.org",
"company": {
"name": "Romaguera-Crona",
"catchPhrase": "Multi-layered client-server neural-net",
"bs": "harness real-time e-markets"
}
}
Get User's Posts
bash
GET /users/{id}/posts
Parameters:
id
(number) - User ID
Response:
json
[
{
"userId": 1,
"id": 1,
"title": "sunt aut facere repellat provident occaecati excepturi optio reprehenderit",
"body": "quia et suscipit\nsuscipit recusandae consequuntur expedita et cum\nreprehenderit molestiae ut ut quas totam\nnostrum rerum est autem sunt rem eveniet architecto"
}
// ... more posts by this user
]
Get User's Albums
bash
GET /users/{id}/albums
Parameters:
id
(number) - User ID
Response:
json
[
{
"userId": 1,
"id": 1,
"title": "quidem molestiae enim"
}
// ... more albums by this user
]
Get User's Todos
bash
GET /users/{id}/todos
Parameters:
id
(number) - User ID
Response:
json
[
{
"userId": 1,
"id": 1,
"title": "delectus aut autem",
"completed": false
}
// ... more todos by this user
]
Create User
bash
POST /users
Request Body:
json
{
"name": "John Doe",
"username": "johndoe",
"email": "[email protected]",
"address": {
"street": "123 Main St",
"suite": "Suite 100",
"city": "New York",
"zipcode": "10001",
"geo": {
"lat": "40.7128",
"lng": "-74.0060"
}
},
"phone": "1-555-123-4567",
"website": "johndoe.com",
"company": {
"name": "Acme Corp",
"catchPhrase": "Innovative solutions for tomorrow",
"bs": "synergize cutting-edge technologies"
}
}
Response: 201 Created
json
{
"id": 11,
"name": "John Doe",
"username": "johndoe",
"email": "[email protected]",
"address": {
"street": "123 Main St",
"suite": "Suite 100",
"city": "New York",
"zipcode": "10001",
"geo": {
"lat": "40.7128",
"lng": "-74.0060"
}
},
"phone": "1-555-123-4567",
"website": "johndoe.com",
"company": {
"name": "Acme Corp",
"catchPhrase": "Innovative solutions for tomorrow",
"bs": "synergize cutting-edge technologies"
}
}
Update User (Full Replace)
bash
PUT /users/{id}
Parameters:
id
(number) - User ID
Request Body: Complete user object (same as POST)
Response: 200 OK
- Updated user object
Update User (Partial)
bash
PATCH /users/{id}
Parameters:
id
(number) - User ID
Request Body: Partial user object
json
{
"email": "[email protected]",
"phone": "1-555-999-8888"
}
Response: 200 OK
- Updated user object
Delete User
bash
DELETE /users/{id}
Parameters:
id
(number) - User ID
Response: 200 OK
json
{}
Examples
javascript
// Get all users
const users = await fetch('http://localhost:3000/users')
.then(res => res.json());
// Get user by ID
const user = await fetch('http://localhost:3000/users/1')
.then(res => res.json());
// Create new user
const newUser = await fetch('http://localhost:3000/users', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
name: 'Jane Doe',
username: 'janedoe',
email: '[email protected]'
})
}).then(res => res.json());
bash
# Get all users
curl http://localhost:3000/users
# Get user by ID
curl http://localhost:3000/users/1
# Create new user
curl -X POST http://localhost:3000/users \
-H "Content-Type: application/json" \
-d '{
"name": "Jane Doe",
"username": "janedoe",
"email": "[email protected]"
}'
python
import requests
# Get all users
users = requests.get('http://localhost:3000/users').json()
# Get user by ID
user = requests.get('http://localhost:3000/users/1').json()
# Create new user
new_user = requests.post('http://localhost:3000/users', json={
'name': 'Jane Doe',
'username': 'janedoe',
'email': '[email protected]'
}).json()