This is a RESTful API built with Go, Gorilla Mux router, and GORM (an ORM library for Golang). It provides functionality to manage books, including creating, retrieving, updating, and deleting book records. The API interacts with a database (configured using GORM) to store and retrieve book data.
- Get all books
- Get a book by ID
- Create a new book
- Delete a book by ID
- Update a book by ID
- Go
- Gorilla Mux (for routing)
- GORM (ORM library for database interaction)
- Clone the repository:
https://github.com/Shreyank031/go-bookstore.git
- Navigate to the project directory:
cd go-bookstore
- Download the project dependencies:
go mod download
- Configure the database connection by modifying the
config.Connect()
function in thepkg/config
package. Set the appropriate database connection string and other parameters based on your database setup.
- Start the server:
go run main.go
- Endpoint:
/books
- Method:
GET
- Description: Retrieves a list of all books.
- Endpoint:
/books
- Method:
POST
- Description: Creates a new book.
- Request Body:
{ "name": "Book Name", "author": "Author Name", "publication": "Publication Name" }
- Endpoint:
/books/{bookId}
- Method:
GET
- Description: Retrieves a book by its ID.
- Path Parameter: bookId (the ID of the book)
- Endpoint:
/books/{bookId}
- Method:
PUT
- Description: Updates a book by its ID.
- Path Parameter: bookId (the ID of the book)
- Request Body:
{
"name": "Updated Book Name",
"author": "Updated Author Name",
"publication": "Updated Publication Name"
}
- Endpoint:
/books/{bookId}
- Method:
DELETE
- Description: Deletes a book by its ID.
- Path Parameter: bookId (the ID of the book)