This project is an API for handling books built with Django. It provides CRUD operations for the book
resource, an enrichment service that fetches book info using its ISBN code (either 10 or 13), and a cache layer to avoid too many requests to the 3rd party API.
In order to run this project, you need to have the following tools installed:
I set up docker-compose for this project, so you don't need to install anything else. Also, I created a Makefile with some useful commands to help you run the project.
To start the application development environment, run the following command:
make up
That will start the Django application, the PostgreSQL database, and the Redis cache. The application will be available at http://localhost:8000
.
To seed the database with some books, run the following command:
make seed-db
I created a Postman collection with all the requests you can make to the API. It's available here.
This project was built using the following technologies and tools:
- Django
- Django REST framework
- PostgreSQL
- Redis
- Docker
- Docker Compose
- Make
- Pytest
- Github Actions
I designed the app to use the Open Library API to fetch book information using its ISBN code. The API provides a lot of information about books, such as title, author, number of pages, publish date, and more.
Whenever you create or update a book, the app will try to fetch its information from the Open Library API using the ISBN code. If no ISBN code is provided, the app will not try to fetch the information.
I used Redis to cache the book information fetched from the Open Library API. The cache layer is used to avoid too many requests to the 3rd party API, which could lead to rate limiting.
The cache is set to expire after 2 hours. The book data is not information that I need updates in real time so I don't need the TTL to be lower than that. On the other hand, I might cache books that are not frequently accessed for a long time, so I don't want the TTL to be too high, either.
I wrote some unit and integration tests to ensure the app works as expected. You can run the tests by running the following command:
make test
Besides the commands mentioned above, I created some other useful commands to help you work with the project:
make rebuid
: Rebuild the application development environmentmake migrate
: Run the Django migrationsmake logs
: Show the application logsmake logs-web
: Show the Django logsmake logs-db
: Show the PostgreSQL logsmake logs-redis
: Show the Redis logs
make shell-web
: Access the Django container shellmake shell-db
: Access the PostgreSQL container shellmake shell-redis
: Access the Redis container shellmake format
: Format the code usingblack
make up-prod
: Start the application production environment (the Docker image is optimized for production and there's no volume mounted for the code)make rebuild-prod
: Rebuild the application production environmentmake down
: Stop all services (works for both development and production environments)make clean
: Stop all services and remove all volumes (works for both development and production environments)