https://github.com/gera2ld/json-server.py
Fake REST API with zero coding
https://github.com/gera2ld/json-server.py
Last synced: over 1 year ago
JSON representation
Fake REST API with zero coding
- Host: GitHub
- URL: https://github.com/gera2ld/json-server.py
- Owner: gera2ld
- Created: 2019-06-29T18:09:06.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2022-10-11T12:05:17.000Z (almost 4 years ago)
- Last Synced: 2025-04-15T06:42:57.214Z (over 1 year ago)
- Language: Python
- Size: 24.4 KB
- Stars: 23
- Watchers: 3
- Forks: 9
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# json-server.py
[](https://pypi.org/project/json-server.py/)
Fake REST API with zero coding.
This project is heavily inspired by [json-server](https://github.com/typicode/json-server) in JavaScript.
Requires Python 3.6+.
## Installation
It's highly recommended to install with [pipx](https://pipxproject.github.io/pipx/).
```sh
$ pipx install json-server.py
```
Or install with pip at your own risk:
```sh
$ pip3 install json-server.py
```
## Get Started
Create a `db.json` file with following content:
```json
{
"posts": []
}
```
Start a server:
```sh
$ json-server db.json
```
Create a post:
```sh
$ curl -H 'content-type: application/json' -d '{"content":"blablabla"}' http://localhost:3000/posts
```
List all posts:
```sh
$ curl http://localhost:3000/posts
```
## Usage
```
Usage: json-server [OPTIONS] [FILENAME]
Start a JSON server.
FILENAME refers to the JSON file where your data is stored. `db.json` will
be used if not specified.
Options:
--version Show the version and exit.
-b, --bind TEXT Set address to bind, default as `:3000`
--help Show this message and exit.
```
**Note:**
- Collections must be contained in your data file before starting the server, otherwise the server cannot decide the type of resources.
### Examples
```sh
# Start with default config
$ json-server
# Listen on port 3000
$ json-server -b :3000
# Specify a json file
$ json-server db.json
```