Skip to content

przemekp95/library-api

Repository files navigation

Books & Authors API

Recruitment task implemented as a Laravel REST API for managing books and browsing authors.

Contract

This README is the source of truth for the application behavior.

API Endpoints

Books

All /api/books endpoints require Sanctum authentication.

  • GET /api/books - paginated list of books with eager-loaded authors
  • GET /api/books/{id} - single book with authors
  • POST /api/books - create a book
  • PUT /api/books/{id} - update a book
  • DELETE /api/books/{id} - delete a book

Authors

All /api/authors endpoints are public and read-only.

  • GET /api/authors - paginated list of authors with eager-loaded books
  • GET /api/authors/{id} - single author with books
  • GET /api/authors?search=title - filter authors by related book title

Write operations for authors are intentionally not exposed over HTTP.

Derived Data

  • authors.last_book_title stores the title of the most recently attached book for a given author
  • the value is refreshed asynchronously after book create, update, and delete operations

Features

  • Laravel 12, PHP 8.3+
  • many-to-many authors <-> books relationship
  • FormRequest validation for book writes
  • Sanctum-protected book endpoints
  • public, read-only author endpoints
  • search by related book title using whereHas
  • queue job that refreshes last_book_title
  • feature test suite
  • GitHub Actions CI workflow
  • Artisan command: php artisan app:create-author

Getting Started

Prerequisites

  • PHP 8.3+
  • Composer
  • SQLite 3 (default) or MySQL 8.0+

This project is API-only. Node.js is not required to install, run, or test the API.

Installation

git clone https://github.com/przemekp95/library-api.git
cd library-api
composer setup
php artisan serve

Manual setup is also available if you prefer:

composer install
cp .env.example .env
touch database/database.sqlite
php artisan key:generate
php artisan migrate --seed

Authentication

Use a Sanctum personal access token for /api/books requests:

  1. Create a user.
  2. Generate a personal access token.
  3. Send Authorization: Bearer {token}.

Testing

php artisan test
composer audit

License

MIT

About

Library API project

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages