Metadata-Version: 2.3
Name: yet-another-json-server
Version: 0.26.1
Summary: A REST API for JSON content with zero coding.
License: Apache-2.0
Author: Adriano Vieira
Author-email: adriano.svieira@gmail.com
Requires-Python: >=3.13,<4
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.13
Requires-Dist: fastapi[standard] (>=0.116.1,<0.117.0)
Requires-Dist: pandas (>=2.3.1,<2.4.0)
Requires-Dist: python-dotenv (>=1.1.1,<1.2.0)
Requires-Dist: python-multipart (>=0.0.20,<0.1.0)
Requires-Dist: strawberry-graphql[debug-server] (>=0.278.1,<0.279.0)
Requires-Dist: unidecode (>=1.4.0,<1.5.0)
Project-URL: Bug Tracker, https://gitlab.com/adrianovieira/ya-json-server/-/issues
Project-URL: Documentation, https://gitlab.com/adrianovieira/ya-json-server
Project-URL: Repository, https://gitlab.com/adrianovieira/ya-json-server
Description-Content-Type: text/markdown

# Yet Another JSON Server

[![image](https://gitlab.com/adrianovieira/ya-json-server/badges/main/pipeline.svg)](https://gitlab.com/adrianovieira/ya-json-server/-/pipelines)
[![image](https://gitlab.com/adrianovieira/ya-json-server/badges/main/coverage.svg?job=job::tests::api&key_text=coverage)](https://gitlab.com/adrianovieira/ya-json-server/-/jobs/artifacts/main/browse?job=job::tests::api)

## Introduction

A REST API for JSON content with zero coding.

Technologies::

- Python 3.13+
- FastAPI 0.116+

> _The projects [json-server](https://github.com/typicode/json-server) and_
_[Python JSON Server](https://github.com/ganmahmud/python-json-server) inspires this one._

## Getting started

This project has two options to have your data available for the API.  
1. Create a JSON file with your resources data.  
    So, use the docker image and define the file as volume for the API.
2. Upload a CSV file into the API which will converte it to a JSON file, and 
    the file name is used as the _resource_ name.  
  For awhile, this option will updata the JSON file as a whole.

**JSON file simple sample data structures**:  
(e.g.: `my-db-data.json`)  

Case with one "resources" (`posts`).  
```json
{
    "posts": [
    {
      "id": 1,
      "title": "Yet Another JSON Server",
      "author": "Adriano Vieira"
    }
  ]
}
```  
        
or

<details open>
<summary>
<i>Multiple "resources" (`posts`, `comments`, `products`, and `stoke-exchange`).</i>
👈🏽
</summary>

```json
{
  "posts": [ {"id": 1, "title": "Yet Another JSON Server", "author": "Adriano Vieira" } ],
  "comments": [ {"id": 1, "body": "some comment", "postId": 1 } ],
  "products": [
    {
      "productId": 375,
      "title": "Dress",
      "brand": "Adidas",
      "price": 40,
      "reviewScore": 1.0431592108,
      "color": "Black",
      "size": "XL",
      "image": "http://products.net/img/"
    }
  ],
  "stoke-exchange": [
    {
      "company": "Chuchu e Melão S/A",
      "city": "Belo Horizonte",
      "ceoUserId": "99273502-9448-4197-abc4-422d4c792264",
      "state": "Minas Gerais",
      "id": 17,
      "country": "Brasil",
      "postcode": 40256,
      "idProduct": 19,
      "priceTag": "45,593,820",
      "shareValue": "617.00"
    }
  ]
}
```
</details>

<br />

**For those examples**:
- **the "*resources*"**: `posts`, `comments`, `products`, and `stoke-exchange` are the
_resources_ enpoints that you would make requests on the API.
- **the "*requests*"**: `posts/1`, `comments/1`, `products/375`, and
`stoke-exchange/99273502-9448-4197-abc4-422d4c792264` will get a valid responses data.
  - But the requests: `stoke-exchange/17` and `stoke-exchange/19` will get error 
  response   
(_read the [OpenAPI Document](https://gitlab.com/adrianovieira/ya-json-server/-/blob/main/docs/openapi.json) for details_).

### API operation

You can use it as Python module or containerized.

#### Module

Install the JSON server by:

```
pip install yet-another-json-server
```

After this, you can run:

```
ya-json-server
```

Setup::
via environment variables:
- `APP_JSON_FILENAME`: optional, defaults to `data/db.json`.
- `APP_PORT`: optional, defaults to `8000`.

#### Container

You can use the docker image from the project, e.g.:

```shell
docker run --rm -it -p 80:8000 -v ./my-db-data.json:/home/worker/data/db.json \
  registry.gitlab.com/adrianovieira/ya-json-server:v1.0
```

This way, you can access the documentation for the running API at
http://api.localhost/docs, such as:

.Read it on link:docs/openapi.json[OpenAPI Document] description.
[align="center"]
image::docs/api.png[OpenAPI Document, 480]

### Making requests

Check the link:docs/openapi.json[OpenAPI Document] to read the full
description for each endpoint.


| endpoints              | summary                                    |
| ---------------------- | ------------------------------------------ |
| `GET /`                | Get list of resources.                     |
| `GET /{resource}`      | Get all the data of the resource.          |
| `GET /{resource}/{id}` | Get the resource ID data.                  |
| `PUT /upload`          | Update DB JSON file from CSV file content. |
| `...`                  |

Check the
[OpenAPI Document](https://gitlab.com/adrianovieira/ya-json-server/-/blob/main/docs/openapi.json)
to read the full description for each endpoint.

You also can access the documentation for the running API at
http://api.localhost/docs

## License

> Apache License 2.0

