This README file provides instructions on how to set up and run the project, along with explanations about the code structure and implementation details.
- PHP >= 11
- Composer
- PgSQL database
-
Clone the repository to your local machine:
git clone https://github.com/asfiaaiman/Library-Management-System-API.git
-
Navigate to the project directory:
cd project-name
-
Install PHP dependencies using Composer:
composer install
-
Copy 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:DB_CONNECTION=pgsql DB_HOST=127.0.0.1 DB_PORT=5432 DB_DATABASE=LMS_API DB_USERNAME=postgres DB_PASSWORD=
-
Run database migrations to create the necessary tables:
php artisan migrate
-
(Optional) Seed the database with sample data:
php artisan db:seed
-
Serve the application locally:
php artisan serve
-
Access the application in your web browser at
http://127.0.0.1:8000/
.
-
Services Classes have been used to include main business logics
-
Controllers use Resource and Collection to test the API
-
JSON responses have been used to see the response of an endpoint
- Books:
- List all books: GET http://127.0.0.1:8000/api/v1/books
- Create a new book: POST http://127.0.0.1:8000/api/v1/books
- Update a book: PUT http://127.0.0.1:8000/api/v1/books/{id}
- Delete a book: DELETE http://127.0.0.1:8000/api/v1/books/{id}
- Authors:
- List all authors: GET http://127.0.0.1:8000/api/v1/authors
- Create a new author: POST http://127.0.0.1:8000/api/v1/authors
- Update an author: PUT http://127.0.0.1:8000/api/v1/authors/{id}
- Delete an author: DELETE http://127.0.0.1:8000/api/v1/authors/{id}
- Patrons:
- List all patrons: GET http://127.0.0.1:8000/api/v1/patrons
- Create a new patron: POST http://127.0.0.1:8000/api/v1/patrons
- Update a patron: PUT http://127.0.0.1:8000/api/v1/patrons/{id}
- Delete a patron: DELETE http://127.0.0.1:8000/api/v1/patrons/{id}
- Book Search:
- Search for books: GET http://127.0.0.1:8000/api/v1/books/search?keyword={keyword}
Replace {keyword} with the search term or keyword.
- Fetch Books by Author:
- List books by author: GET http://127.0.0.1:8000/api/v1/authors/{author}/books
Replace {author} with the ID or slug of the author.
- Borrow Book:
- Borrow a book for a patron: POST http://127.0.0.1:8000/api/v1/patrons/{patronId}/books/{bookId}/borrow
Replace {patronId} with the ID of the patron and {bookId} with the ID of the book.
- Return Book:
- Return a borrowed book: POST http://127.0.0.1:8000/api/v1/patrons/{patronId}/books/{bookId}/return
Replace {patronId} with the ID of the patron and {bookId} with the ID of the book.
These endpoints follow the structure of the provided Laravel routes and are prefixed with /api/v1/ as specified in the routes/api.php file. Adjust the base URL (http://127.0.0.1:8000/) based on your actual development environment.
- The API versioning is implemented using URL-based versioning in the
routes/api.php
file. - Each API version has its own route group prefixed with the version number (e.g.,
/v1
). - Middleware such as throttle rate limiting (
throttle:3,10
) is applied to specific routes or route groups to control the rate of incoming requests.
- Caching is implemented using Laravel's caching mechanisms (
Cache::remember
) in service classes and controllers. - Frequently accessed data, such as book listings, is cached to optimize response times and reduce database queries.
- Modify the
.env
file to suit your local development environment, including database settings, cache driver, and other configuration options. - Use appropriate namespace and controller names based on your actual project structure.
- Refer to Laravel's official documentation for more information on Laravel installation, configuration, and best practices.