This is a straightforward blog API.
- Authentication and authorization using JWT tokens
- API endpoints for registering and logging in users
- API endpoints for retrieving, creating, updating and deleting posts
- API endpoints for retrieving, creating and deleting comments
- Clean architecture
- Unit tests for the application
This is a solution for a blog application, structured into several projects:
- Blog.Core: Contains the core business logic, DTOs, entities, interfaces, and services.
- Blog.Infrastructure: Contains the infrastructure logic, including the database context and repositories.
- Blog.UnitTests: Contains unit tests for the application.
- Blog.Api: The API project for the application.
To set up the project locally, follow these steps:
- Clone the repository:
git clone https://github.com/littlemoonstones/SimpleBlogApi.git
- Navigate to the project directory:
cd SimpleBlogApi
- Add your JWT Key
dotnet user-secrets set "Jwt:Key" "your-key"
- Restore the .NET packages:
dotnet restore
- Build the project:
dotnet build
- Run the application
dotnet run --project Blog.Api
dotnet test
The Blog Web API has the following endpoints:
This endpoint is used to register a new user.
UserName
: string (required)Email
: string (required)Password
: string (required)
200 OK
: User registration was successful. Returns a message indicating the user was created successfully.400 Bad Request
: User registration failed. This could be due to invalid input or the password not meeting the requirements. Returns a list of error descriptions.
This endpoint is used to log in a user.
Email
: string (required)Password
: string (required)
200 OK
: User login was successful. Returns a JWT token.400 Bad Request
: User login failed. This could be due to invalid input or incorrect email/password. Returns an error message.
This endpoint is used to log out a user. Requires user to be authenticated.
200 OK
: User logout was successful.401 Unauthorized
: User is not authenticated.
Creates a new post.
PostRequestDto
object:Title
: string (required)Content
: string (required)
200 OK
: Returns the created post as aPostResponseDto
object.400 Bad Request
: If the model state is not valid or an exception occurs.403 Forbidden
: If an unauthorized access exception occurs.
Fetches a post by its ID.
id
: GUID of the post.
200 OK
: Returns the requested post as aPostResponseDto
object.400 Bad Request
: If an exception occurs.404 Not Found
: If the post or its author does not exist.
Deletes a post by its ID.
id
: GUID of the post.
204 No Content
: If the post is successfully deleted.400 Bad Request
: If an exception occurs.403 Forbidden
: If an unauthorized access exception occurs.404 Not Found
: If the post does not exist.
Updates a post by its ID.
id
: GUID of the post.
PostRequestDto
object:Title
: string (required)Content
: string (required)
200 OK
: Returns the updated post as aPostResponseDto
object.400 Bad Request
: If the model state is not valid or an exception occurs.403 Forbidden
: If an unauthorized access exception occurs.404 Not Found
: If the post does not exist.
Please note that the POST
, DELETE
, and PUT
endpoints require authorization.
Fetches comments by the post ID.
postId
: GUID of the post.
200 OK
: Returns the requested comments as a list ofCommentResponseDto
objects.400 Bad Request
: If an exception occurs.
Creates a new comment for a post.
postId
: GUID of the post.
CommentRequestDto
object:Content
: string (required)
200 OK
: Returns the created comment as aCommentResponseDto
object.400 Bad Request
: If the model state is not valid or an exception occurs.403 Forbidden
: If an unauthorized access exception occurs.404 Not Found
: If the post does not exist.
Deletes a comment by its ID.
postId
: GUID of the post.commentId
: GUID of the comment.
204 No Content
: If the comment is successfully deleted.400 Bad Request
: If an exception occurs.403 Forbidden
: If an unauthorized access exception occurs.404 Not Found
: If the comment does not exist.
Please note that the POST
and DELETE
endpoints require authorization.
This project is licensed under the MIT License. Feel free to customize it further based on your specific project details and preferences.