Skip to content

BookHive API: A Django-based API for managing book collections with features for user authentication and CRUD operations. Built with Django Ninja and Pydantic, using PostgreSQL and deployed on Render. πŸš€πŸ“š

License

Notifications You must be signed in to change notification settings

Mannuel25/BookHive

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

31 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ“š BookHive API

Overview πŸ“‹

BookHive is a powerful API designed to simplify the management of your book collection. With this API, you can seamlessly:

  • Create, Update, and Retrieve book records πŸ“š
  • Filter books based on various attributes πŸ”
  • Manage user authentication and authorization securely πŸ”

Key Features ⭐

  • User Permissions: Users can only modify or delete books that they own. Admins have full access to manage all books, ensuring that each user can only interact with their own records. πŸ”’
  • Advanced Filtering: Easily search and filter books based on title, author, publication date, and more, providing a tailored experience for managing your collection. πŸ”
  • JWT Authentication: Secure access with JSON Web Tokens (JWT) for user authentication. Refresh tokens and secure login mechanisms keep your data safe. πŸ”‘ Built with Django, Django Ninja, and Pydantic, BookHive leverages PostgreSQL for robust data management and is deployed on Render for seamless scalability. πŸš€

Technologies Used πŸ› οΈ

  • Django: πŸ•ΈοΈ Web framework for building the API.
  • Django Ninja: ⚑ Fast API framework for Django.
  • Pydantic: πŸ” Data validation and settings management.
  • PostgreSQL: πŸ—„οΈ Relational database for storing data.
  • Render: 🌐 Deployment platform for hosting the API.

Project Setup πŸ—οΈ

Prerequisites

  • Python 3.6+
  • PostgreSQL
  • pip (Python package installer)

Installation

  1. Clone the Repository

    git clone https://github.com/Mannuel25/bookhive.git
    cd bookhive
  2. Create a virtual environment

    python -m venv .\venv
    
  3. Activate the virtual environment

    venv\scripts\activate
    

    Note: Upon activating the virtual environment if this error shows up:

    venv\scripts\activate : File ..\venv\scripts\Activate.ps1 cannot be loaded because running scripts is 
    disabled on this system. For more information, see about_Execution_Policies at http://go.microsoft.com/fwlink/?LinkID=135170.
    

    Run this command:

    Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Unrestricted 
    

    Then run the command to activate the virtual environment : venv\scripts\activate

  4. Install Dependencies

    pip install -r requirements.txt
  5. Configure the Database

    Update DATABASES settings in bookhiveConfig/settings.py to match your PostgreSQL configuration.

  6. Make Migrations

    python manage.py makemigrations
  7. Apply Migrations

    python manage.py migrate
  8. Create a Superuser (Optional)

    python manage.py createsuperuser
  9. Run the Development Server

    python manage.py runserver

API Documentation πŸ“–

Explore the API using the interactive documentation:

Authentication πŸ”’

JWT Authentication

  • Generate Token: POST /api/token/ with email and password πŸ”‘
  • Refresh Token: POST /api/token/refresh/ with refresh_token πŸ”„

Example Request for Token Generation

curl -X POST "https://bookhiveapi.onrender.com/api/user_mgt/login" -H "Content-Type: application/json" -d '{"email": "user@example.com", "password": "yourpassword"}'

Example Request for Token Refresh

curl -X POST "https://bookhiveapi.onrender.com/api/token/refresh" -H "Content-Type: application/json" -d '{"refresh_token": "your_refresh_token"}'

Endpoints πŸ“‘

Books πŸ“š

  • List Books: GET /api/books/ - List all books.
  • Create Book: POST /api/books/ - Create a new book.
  • Retrieve Book: GET /api/books/{id}/ - Retrieve a specific book.
  • Update Book: PUT /api/books/{id}/ - Update a specific book.
  • Delete Book: DELETE /api/books/{id}/ - Delete a specific book.

Users πŸ‘€

  • User Signup: POST /api/users/signup/ - Create a new user.
  • User Login: POST /api/users/login/ - Login a user.
  • Update User: PATCH /api/users/{id}/ - Update user information.
  • Retrieve User: GET /api/users/{id}/ - Retrieve a specific user's details.

Testing πŸ§ͺ

Run tests using the following command:

python manage.py test

Error Handling 🚨

Errors are returned in the following format:

{
    "message": "Error message"
}

License πŸ“œ

This project is licensed under an MIT License.

About

BookHive API: A Django-based API for managing book collections with features for user authentication and CRUD operations. Built with Django Ninja and Pydantic, using PostgreSQL and deployed on Render. πŸš€πŸ“š

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published