Bookly is a RESTful API built with FastAPI for managing a collection of books. It provides endpoints to perform CRUD (Create, Read, Update, Delete) operations on book resources. The API also includes additional features like greeting users and retrieving request headers.
- Get All Books: Retrieve a list of all books in the collection.
- Get Book by ID: Retrieve details of a specific book using its unique ID.
- Create Book: Add a new book to the collection.
- Update Book: Modify the details of an existing book.
- Delete Book: Remove a book from the collection.
- Greet User: A simple endpoint to greet users by name and age.
- Get Headers: Retrieve request headers for debugging or informational purposes.
- Python 3.12 or higher
- FastAPI
- Uvicorn (for running the server)
- A database (if persistence is required; currently, the project uses an in-memory list)
-
Clone the repository:
git clone <repository-url> cd bookly
-
Create a virtual environment and activate it:
python3.12 -m venv .env source .env/bin/activate -
Install dependencies:
pip install -r requirements.txt
-
Run the application:
uvicorn src.__init__:app --reload
The API will be available at
http://127.0.0.1:8000.
Create a .env file in the root directory to configure environment variables. Example:
PORT=8000
DEBUG=TrueInteractive API documentation is available at:
- Swagger UI:
http://127.0.0.1:8000/docs - ReDoc:
http://127.0.0.1:8000/redoc
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/v1.0/books |
Retrieve all books. |
| GET | /api/v1.0/books/{id} |
Retrieve a book by its ID. |
| POST | /api/v1.0/books |
Create a new book. |
| PATCH | /api/v1.0/books/{id} |
Update an existing book. |
| DELETE | /api/v1.0/books/{id} |
Delete a book by its ID. |
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/v1.0/greet/{name} |
Greet a user by name and age. |
| GET | /api/v1.0/get_headers |
Retrieve request headers. |
curl http://127.0.0.1:8000/api/v1.0/bookscurl -X POST http://127.0.0.1:8000/api/v1.0/books \
-H "Content-Type: application/json" \
-d '{
"title": "The Great Gatsby",
"author": "F. Scott Fitzgerald",
"genre": "Classic"
}'curl -X PATCH http://127.0.0.1:8000/api/v1.0/books/1 \
-H "Content-Type: application/json" \
-d '{
"genre": "Tragedy"
}'curl -X DELETE http://127.0.0.1:8000/api/v1.0/books/1bookly/
├── src/
│ ├── __init__.py # FastAPI app initialization
│ ├── books/
│ │ ├── routes.py # Book-related API routes
│ │ ├── books.py # Book models and in-memory data
├── .env/ # Virtual environment
├── README.md # Project documentation
├── requirements.txt # Python dependencies
Contributions are welcome! Please follow these steps:
- Fork the repository.
- Create a new branch for your feature or bug fix.
- Commit your changes and push them to your fork.
- Submit a pull request.
This project is licensed under the MIT License. See the LICENSE file for details.
For support or inquiries, contact:
- Name: Bookly API Support
- Email: charisadu@bookly.com
- Website: Bookly Support