This is a backend API for a bookstore, built with Go, Gorilla Mux for routing, and GORM for MySQL database interaction.
- Create a new book
- Retrieve all books
- Retrieve a book by its ID
- Update a book by its ID
- Delete a book by its ID
- Go 1.16+
- MySQL
- Git
-
Clone the repository:
git clone https://github.com/your-username/go-bookstore-backend.git cd go-bookstore-backend -
Install dependencies:
go mod tidy
-
Set up MySQL database:
- Create a database in MySQL.
- Update the database connection details in your application configuration (e.g.,
config/config.go).
-
Run the application:
go run main.go
The following routes are available in the API:
-
Create a new book
- URL:
/book/ - Method:
POST - Description: Creates a new book in the bookstore.
- URL:
-
Retrieve all books
- URL:
/book/ - Method:
GET - Description: Retrieves all books in the bookstore.
- URL:
-
Retrieve a book by ID
- URL:
/book/{bookId} - Method:
GET - Description: Retrieves a book by its ID.
- URL:
-
Update a book by ID
- URL:
/book/{bookId} - Method:
PUT - Description: Updates a book by its ID.
- URL:
-
Delete a book by ID
- URL:
/book/{bookId} - Method:
DELETE - Description: Deletes a book by its ID.
- URL:
curl -X POST http://localhost:8080/book/ -d '{
"Title": "The Catcher in the Rye",
"Author": "J.D. Salinger",
"Publisher": "Little, Brown and Company"
}'curl http://localhost:8080/book/curl http://localhost:8080/book/1curl -X PUT http://localhost:8080/book/1 -d '{
"Title": "The Catcher in the Rye",
"Author": "Jerome David Salinger",
"Publisher": "Little, Brown and Company"
}'curl -X DELETE http://localhost:8080/book/1- Gorilla Mux: A powerful URL router and dispatcher for Golang.
- GORM: The fantastic ORM library for Golang.
- MySQL: The world's most popular open-source database.
This project is licensed under the MIT License. See the LICENSE file for details.