A zero-dependency, lightweight REST API server based on a simple JSON file.
Project description
Simple JSON Server
A zero-dependency, lightweight REST API server based on a simple JSON file, built with Python's standard http.server module. This project provides a quick and easy way to set up a mock API for frontend development, prototyping, or any scenario where a real backend is not yet available.
Inspired by json-server.
Features
- Zero Dependencies: Runs with just a standard Python installation.
- Web Admin Interface: A browser-based UI to view, add, edit, and delete data and resources.
- RESTful API: Automatically generates a full REST API from a
db.jsonfile. - CRUD Operations: Supports
GET,POST,PUT,PATCH, andDELETEmethods. - Advanced Querying: Filter, sort, and paginate your responses.
- Full-text Search: Perform a simple text search across all fields in a resource.
- Relationships: Supports both parent (
_expand) and child (_embed) relationships. - Cascading Deletes: Delete dependent resources automatically using
_dependent. - Static File Serving: The admin UI is bundled with the package. You can also serve your own static files from a
publicdirectory.
Installation
You can install the package from PyPI:
pip install simple-json-server
Usage
-
Create a
db.jsonfile (optional): In your project directory, create adb.jsonfile. The keys will be treated as API resources. If you don't create one, the server will start with an empty database.{ "posts": [ { "id": "1", "title": "json-server", "views": 100, "authorId": "1" } ], "authors": [ { "id": "1", "name": "Alice" } ] }
-
Start the server: Run the following command in your project directory:
simple-json-server
The server will be running at
http://127.0.0.1:5000.
Command-Line Options
You can customize the server's behavior with the following options:
-
Port: Run on a different port.
simple-json-server --port 8080
-
Host: Make the server accessible on your local network.
simple-json-server --host 0.0.0.0
-
Database File: Use a different database file.
simple-json-server --file my_api_data.json
Admin Interface
An admin UI is bundled with the server to easily manage your data.
- URL:
http://127.0.0.1:5000/admin.html
Features:
- Resource Management: Add, rename, and delete resources (e.g.,
posts,users) directly from the UI. - Data Management: View, add, edit, and delete individual data entries within a resource using a JSON editor.
- Query Tester: A simple interface to test your API endpoints with different query parameters.
API Endpoints
Based on the db.json example above, the following endpoints are available:
Query Parameters
- Sort:
GET /posts?_sort=-views(Sort by views, descending) orGET /posts?_sort=title(Sort by title, ascending). - Filter:
GET /posts?views_gte=200(Get posts with views >= 200). Operators:_ne,_lt,_lte,_gt,_gte. - Paginate:
GET /posts?_page=1&_per_page=10(Page-based pagination)GET /posts?_start=0&_end=10(Slice from index 0 to 10)GET /posts?_start=10&_limit=5(Slice 5 items starting from index 10)
- Full-text Search:
GET /posts?_q=python(Search for "python" in any field). - Relationships:
GET /posts/1?_expand=author(Include the parentauthorresource).GET /authors/1?_embed=posts(Include the childrenpostsresources).
- Cascading Delete:
DELETE /posts/1?_dependent=comments(Delete post 1 and all its associated comments).
Static File Serving
If you create a public folder in the directory where you run the server, it will be used to serve your own static files, overriding the bundled admin UI if there are name conflicts (e.g., index.html).
Development
To contribute to development, clone the repository and install the testing dependencies.
-
Clone the repository:
git clone https://github.com/10mohi6/simple-json-server.git cd simple-json-server
-
Install dev dependencies: It's recommended to use
uvfor managing the environment.uv pip install -e .[dev]
-
Run tests: To run tests and see the coverage report in the terminal:
uv run pytest --cov=simple_json_server --cov-report=term-missing
Publishing to PyPI
This project is automatically published to PyPI via GitHub Actions. A new version is released whenever a push is made to the main branch.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file simple_json_server-0.2.0.tar.gz.
File metadata
- Download URL: simple_json_server-0.2.0.tar.gz
- Upload date:
- Size: 18.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
90480e134658021ee0082a809679cca39705ff0f5d7100dc20472f83901de594
|
|
| MD5 |
335a66c473e1e65a20289b59a06a5a36
|
|
| BLAKE2b-256 |
76613be592634b83c648967578310c69f218c972e943ff32180f980bd2aaf8e2
|
File details
Details for the file simple_json_server-0.2.0-py3-none-any.whl.
File metadata
- Download URL: simple_json_server-0.2.0-py3-none-any.whl
- Upload date:
- Size: 14.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
40d437015b2409a2e781c9a51e6caeb14bdbd8caf320eb6fc8ddd9945a404852
|
|
| MD5 |
a79686c1c9425439835080e987beb7ea
|
|
| BLAKE2b-256 |
a8e8e98825b2640416b34b7ff4f66fce9e6e34e7203014d4751ce8a233cab889
|