module
0.0.0-20241203182205-4c4df356b93d
Repository: https://github.com/takeso-user/blog-backend.git
Documentation: pkg.go.dev
# README
Blog Backend Application
Overview
This is a backend application for a blog platform. It is built using Go and the Gin framework. The application provides APIs for user authentication, managing posts, and handling comments.
API Documentation
Authentication
-
Register a new user
- Endpoint:
POST /auth/register
- Request Body:
{ "username": "string", "password": "string" }
- Response:
{ "message": "User registered successfully" }
- Endpoint:
-
Login
- Endpoint:
POST /auth/login
- Request Body:
{ "username": "string", "password": "string" }
- Response:
{ "token": "jwt_token" }
- Endpoint:
-
Get all users
- Endpoint:
GET /auth/users
- Response:
[ { "id": "string", "username": "string" } ]
- Endpoint:
Posts
-
Create a new post
- Endpoint:
POST /api/posts
- Request Body:
{ "title": "string", "content": "string" }
- Response:
{ "id": "string", "title": "string", "content": "string", "author": "string" }
- Endpoint:
-
Get all posts
- Endpoint:
GET /api/posts
- Response:
[ { "id": "string", "title": "string", "content": "string", "author": "string" } ]
- Endpoint:
-
Get a post by ID
- Endpoint:
GET /api/posts/:id
- Response:
{ "id": "string", "title": "string", "content": "string", "author": "string" }
- Endpoint:
-
Update a post
- Endpoint:
PATCH /api/posts/:id
- Request Body:
{ "title": "string", "content": "string" }
- Response:
{ "id": "string", "title": "string", "content": "string", "author": "string" }
- Endpoint:
-
Delete a post
- Endpoint:
DELETE /api/posts/:id
- Response:
{ "message": "Post deleted successfully" }
- Endpoint:
Comments
-
Add a comment to a post
- Endpoint:
POST /api/posts/:id/comments
- Request Body:
{ "content": "string" }
- Response:
{ "id": "string", "content": "string", "author": "string", "postId": "string" }
- Endpoint:
-
Get all comments for a post
- Endpoint:
GET /api/posts/:id/comments
- Response:
[ { "id": "string", "content": "string", "author": "string", "postId": "string" } ]
- Endpoint:
-
Get all comments
- Endpoint:
GET /api/posts/comments
- Response:
[ { "id": "string", "content": "string", "author": "string", "postId": "string" } ]
- Endpoint:
-
Update a comment
- Endpoint:
PATCH /api/posts/comments/:commentID
- Request Body:
{ "content": "string" }
- Response:
{ "id": "string", "content": "string", "author": "string", "postId": "string" }
- Endpoint:
-
Delete a comment
- Endpoint:
DELETE /api/posts/comments/:commentID
- Response:
{ "message": "Comment deleted successfully" }
- Endpoint:
Running the Application in a Container
Prerequisites
- Docker
- Docker Compose
Steps
- Clone the repository:
git clone https://github.com/Takeso-user/blog-backend.git cd blog-backend
- Create a .env file:
cp .env.example .env
- Ubdare the .env file with your values
MONGO_DATABASE=blog JWT_SECRET=your_jwt_secret MONGO_USER=admin MONGO_PASSWORD=adminpassword
- Build and run the containers:
docker-compose up --build
- Access the application at
http://localhost:8080
orhttp://localhost:8888
for Docker
Conclusion
This documentation provides an overview of the blog backend application, its API endpoints, and instructions on how to run the application in a Docker container using Docker Compose.