File size: 1,161 Bytes
dcb1716
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
BASE_URL=http://localhost:3000

# List (first 5)
curl -s "$BASE_URL/api/users?_limit=5"

# Get by id
curl -s "$BASE_URL/api/users/1"

# Filter by username
curl -s "$BASE_URL/api/users?username=Bret"

# Search
curl -s "$BASE_URL/api/users?q=Leanne"

# Paginate
curl -s "$BASE_URL/api/users?_page=1&_limit=3"

# Sort by name desc
curl -s "$BASE_URL/api/users?_sort=name&_order=desc"

# Create
curl -s -X POST "$BASE_URL/api/users" \
  -H "Content-Type: application/json" \
  -d '{"name":"Test User","username":"testuser","email":"test@example.com"}'

# Update (partial)
curl -s -X PATCH "$BASE_URL/api/users/1" \
  -H "Content-Type: application/json" \
  -d '{"email":"new@example.com"}'

# Replace (full)
curl -s -X PUT "$BASE_URL/api/users/1" \
  -H "Content-Type: application/json" \
  -d '{"name":"Leanne Graham","username":"Bret","email":"Sincere@april.biz","phone":"1-770-736-8031 x56442","website":"hildegard.org"}'

# Delete
curl -s -X DELETE "$BASE_URL/api/users/1"

# Nested: user's posts
curl -s "$BASE_URL/api/users/1/posts"

# Nested: user's albums
curl -s "$BASE_URL/api/users/1/albums"

# Nested: user's todos
curl -s "$BASE_URL/api/users/1/todos"