Skip to content

brandaogabriel7/books-api

Repository files navigation

Books API

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.

Table of contents

Setup

Pre-requisites

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.

Start the application development environment

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.

Seed the database

To seed the database with some books, run the following command:

make seed-db

Postman collection

I created a Postman collection with all the requests you can make to the API. It's available here.

Stack

This project was built using the following technologies and tools:

Data enrichment

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.

Cache

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.

Tests

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

Useful commands

Besides the commands mentioned above, I created some other useful commands to help you work with the project:

  • make rebuid: Rebuild the application development environment
  • make migrate: Run the Django migrations
  • make logs: Show the application logs
    • make logs-web: Show the Django logs
    • make logs-db: Show the PostgreSQL logs
    • make logs-redis: Show the Redis logs
  • make shell-web: Access the Django container shell
  • make shell-db: Access the PostgreSQL container shell
  • make shell-redis: Access the Redis container shell
  • make format: Format the code using black
  • 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 environment
  • make 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)

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published