Skip to content

ndigitals04/book-tracker

Repository files navigation

📚 Book Tracker API

A Laravel-powered RESTful API that allows authenticated users to manage their personal list of books. Users can register, log in, and perform full CRUD operations on their books with optional status filtering.


🧰 Features

  • ✅ Sanctum-based API authentication
  • ✅ Register, login, and logout
  • ✅ Create, read, update, and delete books
  • ✅ Filter books by reading/completed status
  • ✅ Users can only access their own books
  • ✅ Eloquent accessor for human-readable status

⚙️ Tech Stack

  • PHP 8+
  • Laravel 12.2
  • MySQL or MariaDB
  • Laravel Sanctum

📁 Project Setup

1. Clone the Repository

git clone https://github.com/your-username/book-tracker.git
cd book-tracker

2. Install Dependencies

composer install

3. Create Environment File

Copy the ".env.example" file content into .env

4. Configure .env

Update your .env file with local DB credentials:

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=book_tracker
DB_USERNAME=root
DB_PASSWORD=your_db_password

5. Generate Application Key

php artisan key:generate

6. Run Migrations

php artisan migrate

7. Start Local Server

php artisan serve

🔐 Authentication Endpoints

👉 Register

POST /api/register

{
  "name": "John Doe",
  "email": "john@example.com",
  "password": "password",
  "password_confirmation": "password"
}

👉 Login

POST /api/login

{
  "email": "john@example.com",
  "password": "password"
}

Response:

{
  "token": "your_access_token"
}

👉 Logout

POST /api/logout

Header:

Authorization: Bearer your_access_token

📚 Book CRUD Endpoints

All endpoints below require the Authorization header: Authorization: Bearer {access_token}

📌 Create Book

POST /api/books

{
  "title": "Atomic Habits",
  "author": "James Clear",
  "status": "reading"
}

📌 List All Books (of Logged-in User)

GET /api/books

📌 Filter by Status

GET /api/books?status=completed
GET /api/books?status=reading

📌 Update Book

PUT /api/books/{id}

{
  "title": "Updated Title",
  "author": "Updated Author",
  "status": "completed"
}

📌 Delete Book

DELETE /api/books/{id}

About

A Book Tracker API built with PHP and Laravel

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages