CRUD operations on bookstore database with authors and books.
Endpoints for authors:
- GET
/authors
- GET
/authors/{id}
- POST
/authors
- PATCH
/authors/{id}
- DELETE
/authors/{id}
Endpoints for books:
- GET
/books/?author_id={author_id}
(optional filter author_id ) - GET
/books/{id}
- POST
/books
- PATCH
/books/{id}
- DELETE
/books/{id}
python +3.9
Follow this instructions to run locally.
-
Clone this repository
-
Create a python virtual environment:
python -m venv .venv
- Activate the virtual environment:
source .venv/bin/activate
- Update pip
pip install --upgrade pip
- Install Python library dependencies:
pip install -r requirements.txt
- Before start the application set the following environment variable:
export DATABASE_URL='sqlite:///./prod.db'
- Start the application
uvicorn app.main:app --reload
To run the application with a specific database start it using:
DATABASE_URL='sqlite:///./database_name.db' uvicorn app.main:app --reload
- Open the http://127.0.0.1:8000 url in the browser
The application can be run within a docker container:
Prerequisite: Docker version 20.10+
- Build the image
docker build -t bookstore_image .
- Run the container
docker run -d --name bookstore_api -p 8000:8000 bookstore_image
To run all tests, execute from the root directory of the repository:
DATABASE_URL="sqlite:///./test.db" pytest -vvv
To check the coverage with a nice html view:
-
DATABASE_URL="sqlite:///./test.db" coverage run -m pytest -v
-
coverage html
-
Open the generated html report (
/bookstore/htmlcov/index.html
) in the browser
- Angela Checa - Trjegul84