-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
59 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,59 @@ | ||
# rest-api-sqlite | ||
REST API service to get costumers invoices payment using Fast API and SQLite | ||
# Documentation | ||
|
||
This project retrieve and update customers invoices payments by using REST APIs. | ||
|
||
It was built using Python 3.9, [FastAPI](https://fastapi.tiangolo.com/), [pytest](https://docs.pytest.org/en/7.0.x/), and [uvicorn](https://www.uvicorn.org/) as ASGI implementation server. Please find more details in `pyproject.toml` | ||
|
||
The following SQLite [database](https://raw.githubusercontent.com/lerocha/chinook-database/master/ChinookDatabase/DataSources/Chinook_Sqlite.sql) is used to get customers and invoice payments data. The DB was filled using the `db/Chinook_Sqlite.sql` script. | ||
|
||
## Requirements | ||
|
||
Python 3.9+ | ||
|
||
You need to have [**Poetry**](https://python-poetry.org/docs/) installed, as Python packaging manager. | ||
|
||
## Installation | ||
|
||
Once poetry is installed, to create the virtual environment and install all the Python packages listed in the `pyproject.toml` file, you need to run | ||
|
||
```bash | ||
poetry install | ||
``` | ||
|
||
Then, activate the virtual environment running | ||
|
||
```bash | ||
poetry shell | ||
``` | ||
|
||
When you need to deactivate the venv, just run `exit` | ||
|
||
## How to run | ||
|
||
You can use Uvicorn with hot realod by running | ||
|
||
``` | ||
uvicorn rest_api_sqlite.service:app --host 0.0.0.0 --port 80 --reload | ||
``` | ||
|
||
Or you can use Docker as well: | ||
|
||
``` | ||
docker build -t rest_api_sqlite . | ||
docker run --name rest_api_sqlite_container -p 80:80 rest_api_sqlite | ||
``` | ||
|
||
The API `/invoices` retrieve all the customers' data and invoices payments, sorted by `total_paid` amount in descending order: invoices can be filtered for a specific time periods using start and end dates (optional) | ||
|
||
``` | ||
curl -X 'GET' \ | ||
'http://0.0.0.0:80/invoices?start=2011-01-01&end=2011-06-01' \ | ||
-H 'accept: application/json' \ | ||
-H 'Content-Type: application/json' | ||
``` | ||
|
||
## Test | ||
|
||
Run app test with: | ||
|
||
pytest -s src/test/test_main.py |