1
0
mirror of https://github.com/vimagick/dockerfiles.git synced 2024-12-23 01:39:27 +02:00
dockerfiles/json-server/README.md

77 lines
1.3 KiB
Markdown
Raw Normal View History

2016-05-09 04:28:37 +02: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 05:21:31 +02:00
## docker-compose.yml
```yaml
2021-10-11 13:29:24 +02:00
version: "3.8"
services:
json-server:
image: vimagick/json-server
2024-02-06 16:02:53 +02:00
command: -h 0.0.0.0 -p 3000 -s ./public db.json
2021-10-11 13:29:24 +02:00
init: true
ports:
- "3000:3000"
volumes:
- ./data:/data
restart: unless-stopped
2016-05-09 05:21:31 +02:00
```
2021-10-11 13:29:24 +02:00
>> :warning: `init: true` is required. [read more][2]
## data/db.json
2016-05-09 05:21:31 +02:00
```json
{
"posts": [
2024-02-06 16:02:53 +02:00
{
"id": "1",
"title": "a title",
"views": 100
},
{
"id": "2",
"title": "another title",
"views": 200
}
2016-05-09 05:21:31 +02:00
],
"comments": [
2024-02-06 16:02:53 +02:00
{
"id": "1",
"text": "a comment about post 1",
"postId": "1"
},
{
"id": "2",
"text": "another comment about post 1",
"postId": "1"
}
2016-05-09 05:21:31 +02:00
],
2024-02-06 16:02:53 +02:00
"profile": {
"name": "typicode"
}
2016-05-09 05:21:31 +02:00
}
```
## up and running
```bash
docker-compose up -d
pip install httpie
http GET :3000/posts
2024-02-06 16:02:53 +02:00
http POST :3000/posts id:=3 title=hello author=world
http PUT :3000/posts/3 title=Hello author=World
http PATCH :3000/posts/3 title=HELLO
http DELETE :3000/posts/3
2016-05-09 05:21:31 +02:00
http GET :3000/db
```
2016-05-09 04:28:37 +02:00
[1]: https://github.com/typicode/json-server
2021-10-11 13:29:24 +02:00
[2]: https://developpaper.com/avoid-running-nodejs-as-pid-1-under-the-docker-image/