Skip to content

Repository files navigation

Book Manager

Rest API using FastAPI framework that provides users with a book' data CRUD. There are four main apps:

  • user: it contains models and data serialization for users data
  • book: it contains models and data serialization for book data
  • api: an app containing all endpoints logic, routing, database, and main setup of the project
  • tests: app containing unit tests for all users and books endpoints

Installation and Execution

The first step is to clone the repository to the local environment using:

git clone https://github.com/FilipeKN4/book_manager.git

The next step is, inside the root folder of the project, run the command:

docker-compose up --build

This command will generate the Docker image of the project, with all the necessary dependencies, ensuring the same environment for everyone who uses the project. The --build argument is required only in the first execution. For the next time, it's possible to use only:

docker-compose up

The project will be running locally on http://localhost:8000/.

Environment Variables

Before using the project properly, configuring the environment variables is needed. For that, it's necessary to create a .env file in the root of the project containing the variables as the example below:

DATABASE_URL=sqlite:///./sql_books.db
SECRET_KEY=your-secret-key
DEBUG=True
API_V1_STR=/api/v1
ALGORITHM=HS256
ACCESS_TOKEN_EXPIRE_MINUTES=30
SUPERUSER_USERNAME=your-admin-username
SUPERUSER_EMAIL=your-admin-email@example.com
SUPERUSER_PASSWORD=example-password

Tests

The tests are using the Pytest framework. For running then, it's possible to use the following command:

docker exec -it book_manager_fastapi pytest

Usage

An initial database version, with some book data, was maintained in the repository to make it easier to test. The database also has an initial superuser created with the following credentials:

email: admin@mail.com
password: password123

If you want to use a fresh database it's possible to create an initial superuser using the command:

docker exec -it book_manager_fastapi python3 -m book_manager.init

In this case, the user will have the credentials provided for the environment variables: SUPERUSER_USERNAME, SUPERUSER_EMAIL, and SUPERUSER_PASSWORD.

After running the project, it's possible to use the Swagger UI (Interative Docs) or ReDoc interface (Interative Docs).

About

Rest API using FastAPI framework that provides users with a book' data CRUD

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages