A RESTful API for managing a simple blogging platform built with .NET 8, following clean architecture principles and best practices.
- Create and retrieve blog posts
- Add comments to blog posts
- Clean Architecture implementation
- Docker support
- PostgreSQL database
- Swagger documentation
- Docker and Docker Compose
- .NET 8 SDK (for local development)
- Make (optional, for using Makefile commands)
- Clone the repository:
git clone <repository-url>
cd blog-api
- Build the application:
make build
- Run the application:
make run
The API will be available at http://localhost:8080
and Swagger documentation at http://localhost:8080/swagger
.
The application requires configuration for database connection and JWT authentication. Sensitive information is not included in the version control.
- Create a
appsettings.Development.json
file in the root directory (if it doesn't already exist). This file will override the defaultappsettings.json
during development. - Add the database connection string to the
appsettings.Development.json
file, replacing the placeholders with your actual values:
{
"ConnectionStrings": {
"PgSqlConnection": "Server=localhost;Port=5432;Database=blogdb;User ID=your-user-ID;Password=your-password;Pooling=true;"
}
}
Note: Ensure your PostgreSQL server is running and accessible at the specified address and port.
Add the JWT configuration to the appsettings.Development.json file, replacing the placeholder with a strong, secure signing key:
JSON
{
"JWT": {
"SigningKey": "your-strong-signing-key"
}
}
Note: Choose a long, random string for the signing key. Avoid using easily guessable values.
The API provides a simple way to generate a JWT token.
To obtain a JWT token, send a GET request to:
GET /api/v1/auth/token
Response
{
"message": "Token generated successfully",
"data": "your-jwt-token"
}
Once you receive the token, include it in the Authorization header as a Bearer token in all API requests:
GET /api/v1/posts
Authorization: Bearer your-jwt-token
To test authenticated endpoints via Swagger:
- Open http://localhost:8080/swagger.
- Click Authorize (lock icon).
- Enter your token as:
Bearer your-jwt-token
- Click Authorize and close the modal.
Now, you can send authenticated requests through Swagger.
GET /api/v1/posts
POST /api/v1/posts
GET /api/v1/posts/{id}
POST /api/v1/posts/{id}/comments
- Improve authentication with register and login endpoints
- Create unit tests for the services and controllers
- Update the Swagger documentation with more configurations
- Create projects for the layers replacing the folders structure
- Implement cache in the get endpoints based on the API's scalability
- Improve the logging and tracing
- Implement production monitoring to detect issues and performance bottlenecks