Skip to content

Repository files navigation

Library Management API

This project is a Django-based RESTful API for managing a library system. It includes functionality for managing books, user authentication, and borrowing and returning books.

Features

User Management

  • User Registration: New users can create accounts
  • JWT Authentication: Secure login system with access and refresh tokens
  • Logout Functionality: Token invalidation for secure user logout

Book Management

  • Book Catalog: Comprehensive listing of all library books
  • Administrative Controls: Restricted access for book addition, updates, and deletion
  • Detailed Views: In-depth information for individual books

Borrowing System

  • Book Borrowing: Users can check out available books
  • Returns Processing: Streamlined book return system
  • Borrowing History: Personal borrowing record tracking

Installation

  1. Clone the Repository

    git clone https://github.com/yourusername/Library-Management-API.git
    cd library-management-api
  2. Set Up Virtual Environment

    python3 -m venv .venv
    # On Unix/macOSsource .venv/bin/activate
    # On Windows
    .venv\Scripts\activate
  3. Install Dependencies

    pip install -r requirements.txt
  4. Database Setup

    python manage.py makemigrations
    python manage.py migrate
  5. Create Administrator Account

    python manage.py createsuperuser
  6. Launch Development Server

    python manage.py runserver

API Documentation

Authentication Endpoints

EndpointMethodDescriptionAccess
/api/register/POSTCreate new user accountPublic
/api/login/POSTObtain JWT tokensPublic
/api/logout/POSTInvalidate refresh tokenAuthenticated

a)Register

Endpoint : api/register/
Method : POST - Register User
Data : JSON - { "name": "string", "password": "password" }

b)Login

Endpoint : api/login/
Method : POST - User Login
Data : JSON - { "name": "string", "password": "password" }

c)Logout

Endpoint : api/logout/
Headers - Key : Authorization
Value : Bearer "Your Access Token"

Book Management Endpoints

EndpointMethodDescriptionAccess
/api/books/GETList all booksAuthenticated
/api/books/create/POSTAdd new bookAdmin
/api/books/<id>/GETView book detailsAuthenticated
/api/books/<id>/PUTUpdate bookAdmin
/api/books/<id>/DELETERemove bookAdmin

Borrowing Endpoints

EndpointMethodDescriptionAccess
/api/borrow/POSTBorrow a bookAuthenticated
/api/return/POSTReturn a bookAuthenticated
/api/my-borrows/GETView borrowing historyAuthenticated

a) Borrow

Endpoint : api/borrow/
Method : POST Data : JSON - { "book_id" : id }
Headers - Key : Authorization
Value : Bearer "Your Access Token"
Output -
{
"id": 1,
"borrowed_at": "2024-12-20T07:04:51.039021Z",
"returned_at": null,
"user": 2,
"book": 1
}

b) My-Borrows

Endpoint : api/my-borrows/
Method : GET Headers - Key : Authorization
Value : Bearer "Your Access Token"
Output -
[
{
"id": 1,
"borrowed_at": "2024-12-20T07:04:51.039021Z",
"returned_at": null,
"user": 2,
"book": 1
}
]

b) Return

Endpoint : api/return/
Method : POST Data : JSON - { "borrow_id" : id }
Headers - Key : Authorization
Value : Bearer "Your Access Token"
Output -
{
"id": 1,
"borrowed_at": "2024-12-20T07:04:51.039021Z",
"returned_at": "2024-12-20T07:16:29.167763Z",
"user": 2,
"book": 1
}

About

This project is a Django REST Framework-based API for managing a library system. It includes features such as user authentication, book management, and borrowing functionality.

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages