This is a simple and user-friendly REST API for managing a library's book collection. The API provides endpoints to perform various operations, such as retrieving all books, fetching a particular book by ISBN or author, updating existing book information, creating new books, and deleting books from the library. Implemented in Go with GoFr framework and MongoDB, the system showcases CRUD operations, and seamless database integration.
http://localhost:2121/metrics
http://localhost:8000/.well-known/health-check
-
Clone the repository:
git clone https://github.com/yashaswi-kohli/BasicAPI-with-GoFr cd BasicAPI-with-GoFr
-
Download Dependencies:
go mod download
-
Verify Dependencies:
cat go.sum
-
Run Project
go run main.go
-
Open Server
http://localhost:8000/books
This will show all the books present in your database.
-
Get all Books
-
Endpoint:
GET /books
-
Description:
- Retrieves a list of all books.
-
Response:
-
-
Get all Books of a Author
-
Endpoint:
GET /books/author/AUTHOR
-
Description:
AUTHOR
: Obtains a list of all books with the author's name.
-
Response:
-
-
Get a book
-
Endpoint:
GET /books/isbn/ISBN
-
Description:
- Retrieves a book with the isbn.
ISBN
: It is the unique identifier for the book.
-
Response:
-
Add a new book
-
Endpoint:
POST /books
-
Description:
- Create a Book and add to database
-
Response:
-
To update the book
-
Endpoint:
-
PUT /books/ISBN
-
Description:
- Update the existing book in the database
-
Response:
-
-
To delete the book
-
Endpoint:
-
DELETE /books/ISBN
-
Description:
- Delete the book in the database, if it exist
-
Response:
-
The project utilizes a MongoDB database to store books. For MongoDB you can use both Atlas or Compass
Go to website, make a cluster and set up a database, then copy the Database link. Then go to mongo folder and there in mongo.go file paste the link in connectionString and fillUP the dbName and collectionName.
First install Compass make a database and collection and remember the name, Then install mongosh, if it is already then run it in terminal by typing
mongosh
Copy the link from 'Connecting to:' and then go to mongo folder and there in mongo.go file paste the link in connectionString and fillUP the dbName and collectionName.
- Now simply run the following command in your terminal to run the application:
go run cmd/main.go