Imágenes
Direcciones
- /mock/categories
Seven categories. Each one has a cover picture.
- /mock/categories/electronics
The category, its cover, and a picture on every product.
- /mock/img/640x480
A placeholder. Any size from 16 to 2000, written as width x height.
- /mock/products?category=groceries
Products in one category, with a price and a picture.
- /mock/users
Ten people. Add ?q=oakland to search.
- /mock/posts?userId=1
Posts. Filter with userId.
- /mock/comments?postId=1
Comments. Filter with postId.
- /mock/products?status=500
The same product list, with HTTP 500.
- /mock/users/1?delay=2000
One person, after two seconds.
{
"id": 1,
"slug": "electronics",
"name": "Electronics",
"width": 1200,
"height": 630,
"image": "/mock/img/1200x630",
"count": 3,
"products": [
{
"id": 1,
"name": "Pocket phone",
"price": 429,
"category": "electronics",
"width": 400,
"height": 400,
"image": "/mock/img/400x400"
},
{
"id": 2,
"name": "Studio headphones",
"price": 89,
"category": "electronics",
"width": 800,
"height": 600,
"image": "/mock/img/800x600"
},
{
"id": 3,
"name": "Compact keyboard",
"price": 74,
"category": "electronics",
"width": 1200,
"height": 480,
"image": "/mock/img/1200x480"
}
]
}Cómo llamarlo
No key. Any site can call these. A normal read is cached for a day. A write is not.
Listas y un registro
Lists are /mock/users, /mock/posts, /mock/comments, /mock/products, and /mock/categories. One record adds the id: /mock/users/1. A category also accepts its slug, as in /mock/categories/electronics.
Filtros
userId, postId, and category keep the matching records. q searches the fields. limit is at most 100. offset skips that many records. A list answers with data, total, limit, and offset.
Imágenes
/mock/img/640x480 returns an SVG. Width and height run from 16 to 2000. status and delay do not apply to pictures.
Escrituras
POST /mock/products with a JSON body. The same JSON comes back with HTTP 201, and the list does not change. PUT /mock/users/1 returns the body you sent. DELETE /mock/users/1 returns that body, or deleted and the id when you send none. The next read still has the original record. The body is 100000 characters or fewer.
Fallos
status sets the HTTP status and still returns the same JSON. Use an integer from 200 to 599. 204, 205, and 304 are refused, because they cannot carry JSON. delay waits that many milliseconds, up to 10000, then returns the same JSON. Both can be used together: /mock/products?status=503&delay=1500.
A missing collection or record is 404. status and delay do not change that. A simulated response is not cached.
