A RESTful backend service built with Go and Gin framework using MongoDB.
src/
├── controllers/ # HTTP request handlers and routing
├── services/ # Business logic layer
├── repositories/ # Data access layer
├── entities/ # Domain models
└── dto/ # Data Transfer Objects
- Go 1.21 or higher
- MongoDB running locally or remotely
-
Install dependencies:
go mod download
-
Update
.envfile with your MongoDB connection string:MONGODB_CONNECTION_STRING=mongodb://localhost:27017/archivist SERVER_PORT=8080The connection string format includes the database name in the path.
-
Start MongoDB (if running locally):
mongod
go run main.goThe server will start on http://localhost:8080
- GET
/health - Returns the health status of the service and MongoDB connection
- POST
/blogs - Request Body:
{ "title": "My First Blog", "content": "This is the content of my blog post" } - Response: Returns the created blog with ID and timestamps
- GET
/blogs - Returns a list of all blogs sorted by creation date (newest first)
- GET
/blogs/:id - Returns a specific blog by its ID
- PUT
/blogs/:id - Request Body (all fields optional):
{ "title": "Updated Title", "content": "Updated content" } - Returns the updated blog
- DELETE
/blogs/:id - Deletes a blog by its ID
- Response:
{"message": "blog deleted successfully"}
- GET
/blogs/search?q=query - Performs case-insensitive search on blog titles and content
- Example:
GET /blogs/search?q=programming
src/controllers/- HTTP handlers for incoming requestssrc/services/- Business logic implementationsrc/repositories/- MongoDB data access layersrc/entities/- Domain models (Blog)src/dto/- Data Transfer Objects for API responses