This is the HereInAfter Library API, a RESTful API for managing a library's book collection. It allows publishers to perform CRUD operations on books, get user tokens for authentication, and more.
- CRUD operations for managing books.
- User authentication with bearer tokens.
- Endpoint to get user tokens based on user ID (for testing purposes only).
- Manual pagination for better control over data retrieval.
- Laravel: A PHP web application framework used for backend development.
- MySQL: A relational database management system for storing book and user data.
- Composer: A dependency manager for PHP used for installing project dependencies.
- Artisan: Laravel's command-line tool for various tasks, including migrations and serving the application.
- Type: Many-to-Many
- Method:
$this->belongsToMany(Author::class);
- Type: Belongs To Many
- Method:
$this->belongsToMany(Publisher::class);
- Type: Many-to-Many
- Method:
$this->belongsToMany(Book::class);
- Type: Belongs To Many
- Method:
$this->belongsToMany(Book::class);
Test description does not contain all the information so I've coded it by assuming following things:
- User is already registered (seeding)
- A user can be a publisher
- User will use its authentication token to make changes as a publisher
- Authors are termed as seperate resource and are not user of the application
To run this project locally, follow the steps below:
-
Clone the repository:
git clone https://github.com/abrarprogrammer/hereinafter-library.git
-
Navigate to the project directory:
cd hereinafter-library
-
Install dependencies:
composer install
-
Create a copy of the
.env.example
file and rename it to.env
:cp .env.example .env
-
Generate an application key:
php artisan key:generate
-
Configure your database settings in the
.env
file. -
Run database migrations:
php artisan migrate
-
Seed the database:
php artisan db:seed
-
Start the development server:
php artisan serve
-
The API will be available at
http://127.0.0.1:8000
by default.
Get the user token for authentication.
- URL:
http://127.0.0.1:8000/api/test/get-token/{user_id}
- Method:
GET
- Status:
200 OK
- Body:
<token>
Add a new book to the library.
- URL:
http://127.0.0.1:8000/api/book
- Method:
POST
- Authorization: Bearer Token
- Token:
<token>
- Body: form-data
name
: Book nameauthor_ids
: 5,7
- Status:
201 Created
Modify details of a book in the library.
- URL:
http://127.0.0.1:8000/api/book/{book_id}
- Method:
PUT
- Authorization: Bearer Token
- Token:
<token>
- Query Params:
name
: Updated book name
- Status:
200 OK
- Body: JSON representation of the modified book
Delete a book from the library.
- URL:
http://127.0.0.1:8000/api/book/{book_id}
- Method:
DELETE
- Authorization: Bearer Token
- Token:
<token>
- Status:
204 No Content