1
2
mirror of https://github.com/vimagick/dockerfiles synced 2024-06-28 17:51:24 +00:00
dockerfiles/json-server/README.md

57 lines
1.1 KiB
Markdown
Raw Normal View History

2016-05-09 02:28:37 +00:00
json-server
===========
![](https://badge.imagelayers.io/vimagick/json-server:latest.svg)
Get a full fake REST API with zero coding in less than 30 seconds (seriously) with [json-server][1].
2016-05-09 03:21:31 +00:00
## docker-compose.yml
```yaml
2021-10-11 11:29:24 +00:00
version: "3.8"
services:
json-server:
image: vimagick/json-server
command: -H 0.0.0.0 -p 3000 -w db.json
init: true
ports:
- "3000:3000"
volumes:
- ./data:/data
restart: unless-stopped
2016-05-09 03:21:31 +00:00
```
2021-10-11 11:29:24 +00:00
>> :warning: `init: true` is required. [read more][2]
## data/db.json
2016-05-09 03:21:31 +00:00
```json
{
"posts": [
{ "id": 1, "title": "json-server", "author": "typicode" }
],
"comments": [
{ "id": 1, "body": "some comment", "postId": 1 }
],
"profile": { "name": "typicode" }
}
```
## up and running
```bash
docker-compose up -d
pip install httpie
http GET :3000/posts
http POST :3000/posts id:=2 title=hello author=world
http PUT :3000/posts/2 title=Hello author=World
http PATCH :3000/posts/2 title=HELLO
http DELETE :3000/posts/2
http GET :3000/db
```
2016-05-09 02:28:37 +00:00
[1]: https://github.com/typicode/json-server
2021-10-11 11:29:24 +00:00
[2]: https://developpaper.com/avoid-running-nodejs-as-pid-1-under-the-docker-image/