Docker container for json-server - a fake REST API for devs
5.6K
Docker container for https://github.com/typicode/json-server - a fake REST API for devs
This is useful for simulating a real REST server with a full REST interface.
You can define a list of COLLECTIONS that will be accepted in REST calls at http://localhost:3000/[COLLECTION] in ENV parameters (see below).
After POST, data will be recorded to /data/db.json, so it can be persistent.
See more info at https://github.com/typicode/json-server
version: '3.7'
services:
json-server:
image: flaviostutz/json-server
ports:
- "3000:3000"
environment:
- COLLECTIONS=cars,houses
Run docker-compose up
Post data to collection
curl -X POST http://localhost:3000/cars -d '{"name":"great car", "type":"1", "year":"2001"}'
List data from collection
curl http://localhost:3000/cars
To use your own json data, extend this container (FROM flaviostutz/json-server) and place your own db.json file at /data/db.json (see /example
Good tutorial on json-server usage at https://medium.com/codingthesmartway-com-blog/create-a-rest-api-with-json-server-36da8680136d
COLLECTIONS - comma separated list of accepted collections in REST API. ex: 'cars,person,events' will make curl -X POST http://localhost:3000/cars -d {"name":"Fusca"} acceptable
RESPONSE_DELAY_MS - time of delay in responses to simulate lag
Content type
Image
Digest
Size
44.1 MB
Last updated
over 6 years ago
docker pull flaviostutz/json-server