Welcome to the Book Management API! This API allows you to manage a collection of books, including operations like viewing all books, accessing a single book, updating, creating, and deleting books. The API is built using the Laravel framework and follows RESTful principles for seamless interaction.
Endpoint: GET /api/books
This endpoint retrieves a list of all books available in the database.
Endpoint: GET /api/books/{id}
This endpoint retrieves details of a single book identified by its unique id
.
Endpoint: POST /api/books
This endpoint allows you to create a new book by providing the book details in the request body.
Request Body:
{
"name": "Book Title",
"author": "Author Name",
"publish_date": "YYYY-MM-DD"
}
Endpoint: PUT /api/books/{id}
This endpoint allows you to update the details of an existing book identified by its unique id
.
Request Body:
{
"name": "Updated Book Title",
"author": "Updated Author Name",
"publish_date": "YYYY-MM-DD"
}
Endpoint: DELETE /api/books/{id}
This endpoint allows you to delete a book based on its unique id
.
Request:
GET /api/books
Response:
[
{
"id": 1,
"name": "Book 1",
"author": "Author A",
"publish_date": "2023-09-15"
},
{
"id": 2,
"name": "Book 2",
"author": "Author B",
"publish_date": "2023-08-20"
}
]
Request:
POST /api/books
Request Body:
{
"name": "New Book",
"author": "New Author",
"publish_date": "2023-10-10"
}
Response:
{
"id": 3,
"name": "New Book",
"author": "New Author",
"publish_date": "2023-10-10"
}
-
Clone this repository to your local machine.
-
Install dependencies using Composer:
composer install
-
Configure your database settings in the
.env
file. -
Run database migrations to set up the required tables:
php artisan migrate
-
Run database seeder to set populate the table:
php artisan db:seed --class=BookSeeder
-
Start the Laravel development server:
php artisan serve
-
You can now use Postman or any API testing tool to interact with the API at
http://127.0.0.1:8000/api
.
To run the API tests, use the following command:
php artisan test
This will execute the test suite and provide feedback on the functionality and integrity of the API.