This is a simple book management system implemented in Go. It provides basic CRUD (Create, Read, Update, Delete) operations for books.
- Get a list of all book
- Get details of a specific book
- Add a new book
- Update an existing book
- Delete a book
This project uses the following external dependencies:
- httprouter - A lightweight HTTP request router.
- gorm - A powerful ORM library for Go.
- MySQL dialect for GORM - MySQL database driver for GORM.
To run the application locally, follow these steps:
- Make sure you have Go installed on your system. You can download it from the official website:
https://golang.org/
- Clone this repository to your local machine or download the source code:
https://github.com/aron-helu/Book_Management-Go.git
- Open a terminal or command prompt and navigate to the project's root directory:
cd Book_Management-Go
-
Set up the MySQL database and update the database connection details in the code if necessary.
-
Run the following command to start the API server:
go run main.go
The server will start running on http://localhost:8000.
- URL:
/book
- Method:
GET
- Description:
Retrieves a list of all books
. - Response:
Returns a JSON array containing book objects.
- URL:
/book/:id
- Method:
GET
- Description:
Retrieves details of a specific book
- Parameters:
id (string)
The ID of the book.
- Response:
Returns a JSON object representing the book
- URL:
/book
- Method:
POST
- Description:
Adds a new book to the collection.
- Request Body:
Expects a JSON object representing the book.
- Response:
Returns the newly created book as a JSON object.
- URL:
/book/:id
- Method:
PUT
- Description:
Updates an existing book.
- Parameters:
id (string):
The ID of the book.
- Request Body:
Expects a JSON object representing the updated book.
- Response:
Returns the updated book as a JSON object.
- URL:
/book/:id
- Method:
DELETE
- Description:
Deletes a book from the collection.
- Parameters:
id (string):
The ID of the book.
- Response:
Returns the updated book collection as a JSON array.
Here's an example of how you can use cURL to interact with the book API:
- Get all books:
curl http://localhost:8000/book
- Get a specific book:
curl http://localhost:8000/book/1
- Add a new book:
curl -X POST -H "Content-Type: application/json" -d '{
"isbn": "123456",
"title": "New book",
"director": {
"firstname": "Jane",
"lastname": "Doe"
}
}' http://localhost:8000/book
- Update a book:
curl -X PUT -H "Content-Type: application/json" -d '{
"isbn": "654321",
"title": "Updated book",
"director": {
"firstname": "John",
"lastname": "Smith"
}
}' http://localhost:8000/book/1
- Delete a book:
curl -X DELETE http://localhost:8000/book/1
Feel free to explore and interact with the book API using different HTTP clients or tools.
👤 Aaron Abraham
Contributions, issues, and feature requests are welcome!
Feel free to check the issues page.
Give a ⭐️ if you like this project!
This project is MIT licensed.