Skip to content

Tedel12/library-api

Repository files navigation

Library Management API

A complete REST API for managing a small library: authors, categories, books, borrowings, and users.

This project was built as a Laravel exercise to master modern ecosystem concepts (Eloquent, API Resources, Sanctum, Services, Events, Policies, Tests, etc.).

Main Features

  • Full CRUD for authors, books, and categories
  • Borrowing management (borrow / return a book)
  • Advanced filtering on books (available, by author, by category, published)
  • Token-based authentication with Laravel Sanctum (register, login, logout)
  • Custom validation + standardized error responses
  • Custom cast for prices (cents → dollars)
  • Enum for book status
  • Eloquent query scopes + many-to-many relationships
  • Service layer (BorrowingService) + database transactions
  • Trait for logging model create/update/delete events
  • Broadcastable event when a book is borrowed
  • Policy to allow only the borrower to return their book
  • Custom pagination format
  • Artisan command library:stats
  • Feature & unit tests

Technologies / Stack

  • PHP 8.1+
  • Laravel 10.x
  • Laravel Sanctum (token authentication)
  • MySQL / MariaDB (or SQLite for testing)
  • Eloquent ORM
  • API Resources + Form Requests
  • PHPUnit + Laravel testing suite

Installation

  1. Clone the project
git clone https://github.com/Tedel12/library-api.git
cd library-api
  1. Install PHP dependencies
composer install
  1. Copy the environment file
cp .env.example .env
  1. Generate application key
php artisan key:generate
  1. Configure your database in .env

    • Set DB_CONNECTION=mysql (or sqlite for quick testing)
    • Fill in DB_HOST, DB_PORT, DB_DATABASE, DB_USERNAME, DB_PASSWORD
  2. Run migrations (create tables)

php artisan migrate
  1. Start the local development server
php artisan serve

The API will be available at:
http://127.0.0.1:8000/api/v1

You can now test endpoints with tools like Postman, Insomnia or curl.

Quick test endpoints

  • Register a user: POST /api/v1/auth/register
  • Login: POST /api/v1/auth/login
  • Get books: GET /api/v1/books (with Bearer token in Authorization header)

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors