Based on json-server
There is a couple of environment variables that can be set if you want to over-ride the defaults
Name | Description | Default |
---|---|---|
SERVER_NAME | Prefix for the docker conatiner | mock-json-server |
SERVER_PORT | Exposed port for the sever | 3000 |
SERVER_PREFIX | Prefix for the urls | v1 |
If you want to change these, copy the .env.example file to .env and set the values
cp .env.example .env
Once your environment is set, bring up the container like you would any docker-compose poroject;
docker-compose build
docker-compose up -d
and
docker-compose down
when you are done.
Your data is stored in json files located in the app/data
folder.
Example:
[
{ "id": 1, "name": "wibble", "age": "20" },
{ "id": 2, "name": "wabble", "age": "30" },
{ "id": 3, "name": "wubble", "age": "40" }
]
This setup works by automatically reading all the json files in the data folder.
You can add/edit them without bringing down the container.
N.B. These files are more of a seed in concept.
If you use a POST
route, the new data will not show up in the file.
To see the whole database at any time just hit up the database endpoint.
GET /db
For more information see the json-server docs
As per the standard json-server, routes are automatically created based on the names of the data files.
So a data file called posts.json
, will have the endpoints;
GET /posts
GET /posts/1
POST /posts
PUT /posts/1
PATCH /posts/1
DELETE /posts/1
They are also available using the environment prefix variable.
GET /v1/posts
GET /v1/posts/1
POST /v1/posts
PUT /v1/posts/1
PATCH /v1/posts/1
DELETE /v1/posts/1
You can add your own custom routes in the data/routes.js
file.
See the main json-server documentation for more details.