|\/|. _| _ . _ |_ _|_ | .|_ _ _ _
| ||(_|| ||(_|| | | |_||_)| (_|| \/
_| /
A comprehensive Rust web application for managing a library. This project is designed to demonstrate the capabilities of Rust in building efficient, safe web applications. It features library management functionalities including listing, adding, and retrieving book and authors details. The system also includes health checking and configuration management, ensuring a robust and customizable solution.
-
Prerequisites:
- Rust and Cargo (Rust's package manager). Visit the official Rust installation guide for instructions.
- PostgreSQL database. Ensure it is running and accessible.
-
Database Setup:
- Ensure Docker is installed and running on your system.
- Run the
init_db.sh
script to automatically set up the PostgreSQL database:chmod +x init_db.sh ./init_db.sh
This script checks for necessary dependencies (
psql
andsqlx
), sets up environment variables for database credentials, launches a PostgreSQL Docker container if needed, and runs database migrations to prepare themidnight_library
database. -
Project Setup:
- Clone the repository and navigate into the project directory.
- Build the project:
cargo build
- Run the application:
cargo run
After setting up the project, you can start interacting with the book management system. The application exposes endpoints for book and author operations and health checks. Use a tool like curl
or Postman to interact with the API.
-
Add an Author:
curl -X POST http://localhost:8080/books -d '{"name": "Herman Melville", "nationality": "American"}' # { "author_id": "e457c912-5a04-4bfc-abeb-5a0e2fe91a72", "message": "Author created successfully!" }
-
List Books:
curl http://localhost:8080/books #[ # { # "author": "Eiichiro Oda", # "created_at": "2024-03-10T10:22:58.244130Z", # "genre": "Shounen", # "id": "a56de2a8-61d3-43f4-b66b-b454c2b54589", # "title": "One Piece" # }, # { # "author": "Akira Toriyama", # "created_at": "2024-03-10T14:28:44.178201Z", # "genre": "Shounen", # "id": "82648e74-3fb4-4fe2-a4a2-5f6db5d20d3b", # "title": "Dragon Ball" # }, #]
-
Show details of an Author:
curl http://localhost:8080/authors/a56de2a8-61d3-43f4-b66b-b454c2b54589 #{ # "created_at": "2024-03-10T10:22:58.244130Z", # "id": "a56de2a8-61d3-43f4-b66b-b454c2b54589", # "name": "Eiichiro Oda", # "nationality": "Japanese" #}
-
Delete a Book:
curl -X POST http://localhost:8080/authors/delete -d '{"id": "f6eed69c-d93a-48ff-b80b-dfdf4df061fa"}' # { "message": "Book deleted successfully!" }
-
Health Check:
curl http://localhost:8080/health_check
- Book Management: Add, list, show details and retrieve books.
- Author Management: Add, list, show details and retrieve authors.
- Health Check Endpoint: Verify the application status.
- Configuration Management: Customize application settings.
We welcome contributions! Please feel free to fork the repository, make your changes, and submit a pull request.
- Fork the Repository: Click on the 'Fork' button at the top right of the page.
- Clone Your Fork:
git clone https://github.com/renatodinizc/midnight_library.git
- Create a New Branch:
git checkout -b new-feature
- Make Your Changes: Implement your feature or fix.
- Commit Your Changes:
git commit -am 'Add some feature'
- Push to the Branch:
git push origin new-feature
- Submit a Pull Request: Open a pull request from your fork to the main project.
This project is licensed under the MIT License - see the LICENSE file for details.