Name | simple-json-server JSON |
Version |
0.1.0
JSON |
| download |
home_page | None |
Summary | A zero-dependency, lightweight REST API server based on a simple JSON file. |
upload_time | 2025-08-03 09:36:14 |
maintainer | None |
docs_url | None |
author | None |
requires_python | >=3.9 |
license | MIT License
Copyright (c) 2025 10mohi6
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
|
keywords |
json-server
mock
api
rest
http-server
prototype
|
VCS |
 |
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# Simple JSON Server
[](https://badge.fury.io/py/simple-json-server)
[](https://github.com/10mohi6/simple-json-server/actions/workflows/publish-to-pypi.yml)
[](https://codecov.io/gh/10mohi6/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.
- **RESTful API:** Automatically generates a full REST API from a `db.json` file.
- **CRUD Operations:** Supports `GET`, `POST`, `PUT`, `PATCH`, and `DELETE` methods.
- **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:** Serves static files from the `public` directory.
## Installation
You can install the package from PyPI:
```bash
pip install simple-json-server
```
## Usage
1. **Create a `db.json` file:**
In your project directory, create a `db.json` file. The keys will be treated as API resources.
```json
{
"posts": [
{ "id": "1", "title": "json-server", "views": 100, "authorId": "1" },
{ "id": "2", "title": "python-flask", "views": 200, "authorId": "1" }
],
"authors": [
{ "id": "1", "name": "Alice" }
],
"comments": [
{ "id": "1", "text": "comment 1", "postId": "1" }
]
}
```
2. **Start the server:**
Run the following command in the directory containing your `db.json` file:
```bash
simple-json-server
```
The server will be running at `http://127.0.0.1:5000`.
## 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) or `GET /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 parent `author` resource).
- `GET /authors/1?_embed=posts` (Include the children `posts` resources).
- **Cascading Delete:** `DELETE /posts/1?_dependent=comments` (Delete post 1 and all its associated comments).
## Static File Serving
Create a `public` folder in the same directory and place your static files (e.g., `index.html`, `style.css`) inside. The server will automatically serve them.
- `http://127.0.0.1:5000/index.html`
## Development
To contribute to development, clone the repository and install the testing dependencies.
1. **Clone the repository:**
```bash
git clone https://github.com/10mohi6/simple-json-server.git
cd simple-json-server
```
2. **Install dev dependencies:**
It's recommended to use `uv` for managing the environment.
```bash
uv pip install -e .[dev]
```
3. **Run tests:**
To run tests and see the coverage report in the terminal:
```bash
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.
Raw data
{
"_id": null,
"home_page": null,
"name": "simple-json-server",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.9",
"maintainer_email": null,
"keywords": "json-server, mock, api, rest, http-server, prototype",
"author": null,
"author_email": "10mohi6 <10.mohi.6.y@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/3c/95/aac81cf92b317d53ec017318f64b30477e71c227bf56c0ab83c3d60ece40/simple_json_server-0.1.0.tar.gz",
"platform": null,
"description": "# Simple JSON Server\n\n[](https://badge.fury.io/py/simple-json-server)\n[](https://github.com/10mohi6/simple-json-server/actions/workflows/publish-to-pypi.yml)\n[](https://codecov.io/gh/10mohi6/simple-json-server)\n\nA 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.\n\nInspired by `json-server`.\n\n## Features\n\n- **Zero Dependencies:** Runs with just a standard Python installation.\n- **RESTful API:** Automatically generates a full REST API from a `db.json` file.\n- **CRUD Operations:** Supports `GET`, `POST`, `PUT`, `PATCH`, and `DELETE` methods.\n- **Advanced Querying:** Filter, sort, and paginate your responses.\n- **Full-text Search:** Perform a simple text search across all fields in a resource.\n- **Relationships:** Supports both parent (`_expand`) and child (`_embed`) relationships.\n- **Cascading Deletes:** Delete dependent resources automatically using `_dependent`.\n- **Static File Serving:** Serves static files from the `public` directory.\n\n## Installation\n\nYou can install the package from PyPI:\n\n```bash\npip install simple-json-server\n```\n\n## Usage\n\n1. **Create a `db.json` file:**\n In your project directory, create a `db.json` file. The keys will be treated as API resources.\n\n ```json\n {\n \"posts\": [\n { \"id\": \"1\", \"title\": \"json-server\", \"views\": 100, \"authorId\": \"1\" },\n { \"id\": \"2\", \"title\": \"python-flask\", \"views\": 200, \"authorId\": \"1\" }\n ],\n \"authors\": [\n { \"id\": \"1\", \"name\": \"Alice\" }\n ],\n \"comments\": [\n { \"id\": \"1\", \"text\": \"comment 1\", \"postId\": \"1\" }\n ]\n }\n ```\n\n2. **Start the server:**\n Run the following command in the directory containing your `db.json` file:\n ```bash\n simple-json-server\n ```\n\n The server will be running at `http://127.0.0.1:5000`.\n\n## API Endpoints\n\nBased on the `db.json` example above, the following endpoints are available:\n\n### Query Parameters\n\n- **Sort:** `GET /posts?_sort=-views` (Sort by views, descending) or `GET /posts?_sort=title` (Sort by title, ascending).\n- **Filter:** `GET /posts?views_gte=200` (Get posts with views >= 200). Operators: `_ne`, `_lt`, `_lte`, `_gt`, `_gte`.\n- **Paginate:**\n - `GET /posts?_page=1&_per_page=10` (Page-based pagination)\n - `GET /posts?_start=0&_end=10` (Slice from index 0 to 10)\n - `GET /posts?_start=10&_limit=5` (Slice 5 items starting from index 10)\n- **Full-text Search:** `GET /posts?_q=python` (Search for \"python\" in any field).\n- **Relationships:**\n - `GET /posts/1?_expand=author` (Include the parent `author` resource).\n - `GET /authors/1?_embed=posts` (Include the children `posts` resources).\n- **Cascading Delete:** `DELETE /posts/1?_dependent=comments` (Delete post 1 and all its associated comments).\n\n## Static File Serving\n\nCreate a `public` folder in the same directory and place your static files (e.g., `index.html`, `style.css`) inside. The server will automatically serve them.\n\n- `http://127.0.0.1:5000/index.html`\n\n## Development\n\nTo contribute to development, clone the repository and install the testing dependencies.\n\n1. **Clone the repository:**\n ```bash\n git clone https://github.com/10mohi6/simple-json-server.git\n cd simple-json-server\n ```\n\n2. **Install dev dependencies:**\n It's recommended to use `uv` for managing the environment.\n ```bash\n uv pip install -e .[dev]\n ```\n\n3. **Run tests:**\n To run tests and see the coverage report in the terminal:\n ```bash\n uv run pytest --cov=simple_json_server --cov-report=term-missing\n ```\n\n## Publishing to PyPI\n\nThis project is automatically published to PyPI via GitHub Actions. A new version is released whenever a push is made to the `main` branch.\n",
"bugtrack_url": null,
"license": "MIT License\n \n Copyright (c) 2025 10mohi6\n \n Permission is hereby granted, free of charge, to any person obtaining a copy\n of this software and associated documentation files (the \"Software\"), to deal\n in the Software without restriction, including without limitation the rights\n to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n copies of the Software, and to permit persons to whom the Software is\n furnished to do so, subject to the following conditions:\n \n The above copyright notice and this permission notice shall be included in all\n copies or substantial portions of the Software.\n \n THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n SOFTWARE.\n ",
"summary": "A zero-dependency, lightweight REST API server based on a simple JSON file.",
"version": "0.1.0",
"project_urls": {
"Bug Tracker": "https://github.com/10mohi6/simple-json-server/issues",
"Homepage": "https://github.com/10mohi6/simple-json-server"
},
"split_keywords": [
"json-server",
" mock",
" api",
" rest",
" http-server",
" prototype"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "61956ba16298faab9bf548a6d92e46d05959a7cf6d4febb3df1b0e19ee3126eb",
"md5": "4231a095a4972a306740d92f3fb23549",
"sha256": "ec21eac0cc8eb12d42bfefe85bf1c0e05121b14fe0cede3c23f78f3d9494a526"
},
"downloads": -1,
"filename": "simple_json_server-0.1.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "4231a095a4972a306740d92f3fb23549",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.9",
"size": 8669,
"upload_time": "2025-08-03T09:36:13",
"upload_time_iso_8601": "2025-08-03T09:36:13.708394Z",
"url": "https://files.pythonhosted.org/packages/61/95/6ba16298faab9bf548a6d92e46d05959a7cf6d4febb3df1b0e19ee3126eb/simple_json_server-0.1.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "3c95aac81cf92b317d53ec017318f64b30477e71c227bf56c0ab83c3d60ece40",
"md5": "b797f20af8fd2d3095c77f8ef8eb3bc3",
"sha256": "3bd9afd0c12f9f3d90cb925f65606b2fe4b1f390b8e933372e9687cf42b30720"
},
"downloads": -1,
"filename": "simple_json_server-0.1.0.tar.gz",
"has_sig": false,
"md5_digest": "b797f20af8fd2d3095c77f8ef8eb3bc3",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9",
"size": 12239,
"upload_time": "2025-08-03T09:36:14",
"upload_time_iso_8601": "2025-08-03T09:36:14.969637Z",
"url": "https://files.pythonhosted.org/packages/3c/95/aac81cf92b317d53ec017318f64b30477e71c227bf56c0ab83c3d60ece40/simple_json_server-0.1.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-08-03 09:36:14",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "10mohi6",
"github_project": "simple-json-server",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "simple-json-server"
}