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.
- ✅ 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
- PHP 8+
- Laravel 12.2
- MySQL or MariaDB
- Laravel Sanctum
git clone https://github.com/your-username/book-tracker.git
cd book-trackercomposer install
Copy the ".env.example" file content into .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
php artisan key:generate
php artisan migrate
php artisan serve
POST /api/register
{
"name": "John Doe",
"email": "john@example.com",
"password": "password",
"password_confirmation": "password"
}
POST /api/login
{
"email": "john@example.com",
"password": "password"
}
Response:
{
"token": "your_access_token"
}
POST /api/logout
Header:
Authorization: Bearer your_access_token
All endpoints below require the Authorization header: Authorization: Bearer {access_token}
POST /api/books
{
"title": "Atomic Habits",
"author": "James Clear",
"status": "reading"
}
GET /api/books
GET /api/books?status=completed
GET /api/books?status=reading
PUT /api/books/{id}
{
"title": "Updated Title",
"author": "Updated Author",
"status": "completed"
}
DELETE /api/books/{id}