This is a RESTful CRUD API for managing books in a bookstore, built in Golang using the Gin web framework and integrated with MongoDB using the mgm ODM package.
- Create, Read, Update, and Delete books using RESTful API endpoints
- MongoDB integration using the mgm ODM package
- Hooks for Creating and Updating books
- Validation for the book model
- Logging using the Zap package
- Configurations using YAML files
- Support for environment variables
To run this project, you will need to add the following environment variables to your .env file
DB_NAME
MONGODB_URI
LOG_PATH
Clone the project
git clone https://github.com/snehil-sinha/bookstore.git
Go to the project directory
cd bookstore
Install dependencies
go mod download
The service configuration needs to be specified as a YAML file
env: development # allowed values: development production
port: 8080
bind: 0.0.0.0
Start the server
go run main.go
Note: You can alternatively build the project to generate a binary executable file called goBookStore and use it to start the server
go build
Link to the postman API doc: https://documenter.getpostman.com/view/25819993/2s93CLrtDN
The following endpoints are available:
GET /health
: Health check endpoint.GET /api/v1/books
: Get all books.GET /api/v1/books/:id
: Get a specific book by ID.POST /api/v1/books
: Create a new book.PUT /api/v1/books/:id
: Update an existing book by ID.DELETE /api/v1/books/:id
: Delete an existing book by ID.
Exploring backend with Golang...