This is my first go application!
Welcome to the Book Management API! This API provides a simple way to manage a collection of books. With endpoints for viewing, creating, checking in, and checking out books, it allows you to perform basic operations on a book collection.
- Method:
GET
- Endpoint:
/books
- Description: Retrieves a list of all books in the collection.
- Response: A JSON array of book objects with
ID
,Title
,Author
, andQuantity
fields.
- Method:
GET
- Endpoint:
/books/:id
- Description: Retrieves a single book by its unique ID.
- URL Parameter:
id
(string): The ID of the book to retrieve.
- Response:
- Success: A JSON object representing the book with fields
ID
,Title
,Author
, andQuantity
. - Error: A JSON object with an error message if the book is not found.
- Success: A JSON object representing the book with fields
- Method:
POST
- Endpoint:
/books
- Description: Adds a new book to the collection.
- Request Body: A JSON object with the fields
ID
,Title
,Author
, andQuantity
. - Response:
- Success: A JSON object representing the newly created book.
- Error: A JSON object with an error message if the book cannot be created.
- Method:
POST
- Endpoint:
/checkin
- Description: Increases the quantity of a book by 1 (i.e., checking in a book).
- Query Parameter:
id
(string): The ID of the book to check in.
- Response:
- Success: A JSON object representing the updated book with increased quantity.
- Error:
- If the
id
parameter is missing, a JSON object with an error message. - If the book is not found, a JSON object with an error message.
- If the book is not available (quantity <= 0), a JSON object with an error message.
- If the
- Method:
POST
- Endpoint:
/checkout
- Description: Decreases the quantity of a book by 1 (i.e., checking out a book).
- Query Parameter:
id
(string): The ID of the book to check out.
- Response:
- Success: A JSON object representing the updated book with decreased quantity.
- Error:
- If the
id
parameter is missing, a JSON object with an error message. - If the book is not found, a JSON object with an error message.
- If the
curl -X GET http://localhost:8080/books
curl -X GET http://localhost:8080/books/1
curl -X POST http://localhost:8080/books -H "Content-Type: application/json" -d '{"ID": "11", "Title": "New Book", "Author": "Author Name", "Quantity": 5}'
curl -X POST http://localhost:8080/checkin?id=1
curl -X POST http://localhost:8080/checkout?id=1
To start the server, run the following command in your terminal:
go run main.go
The server will start on localhost:8080
. Make sure you have the Gin package installed in your Go environment.
Enjoy managing your book collection with this API! 📚