HanamiAPI is a robust and scalable API designed to manage user authentication, posts, and access control for a content management system. Built with ASP.NET Core, Entity Framework, and JWT for secure authentication, this project aims to provide a solid foundation for web applications requiring user management and content publishing features.
- HanamiAPI
Hanami API is a robust and scalable web service that allows users to manage posts. It is built with a clean architecture to ensure ease of maintenance and use.
- CRUD operations for posts
- RESTful endpoints
- Database migration management
- Dependency injection
- Containerization with Docker
- User Authentication and Authorization: Secure registration, login, and logout functionalities with JWT-based authentication.
- Role-Based Access Control: Manage different user roles and permissions to ensure secure access to resources.
- Asynchronous Processing: Improved performance and reliability with asynchronous operations.
- Entity Framework Integration: Utilize Entity Framework for efficient database management and migrations.
- Backend: ASP.NET Core, Entity Framework Core
- Authentication: JWT (JSON Web Tokens)
- Database: SQL Server (or any EF Core compatible database)
- DevOps: Docker for containerization, GitHub Actions for CI/CD
- SQLite (Database)
- Swagger (API Documentation)
Before you begin, ensure you have the following installed:
-
Open the NuGet Package Manager in Visual Studio:
- Right-click on your project in the Solution Explorer.
- Select "Manage NuGet Packages...".
-
Install the following packages:
Microsoft.EntityFrameworkCore.Sqlite
Microsoft.EntityFrameworkCore.SqlServer
Microsoft.EntityFrameworkCore.Tools
Swashbuckle.AspNetCore
-
Open the Package Manager Console:
- Go to "Tools" > "NuGet Package Manager" > "Package Manager Console".
-
Execute the following commands:
Install-Package Microsoft.EntityFrameworkCore.Sqlite -Version 8.0.5 Install-Package Microsoft.EntityFrameworkCore.SqlServer -Version 8.0.5 Install-Package Microsoft.EntityFrameworkCore.Tools -Version 8.0.5 Install-Package Swashbuckle.AspNetCore -Version 6.6.2
-
Clone the repository:
git clone https://github.com/your-username/hanami-api.git cd hanami-api
-
Install the dependencies:
dotnet restore
Ensure you have an appsettings.json
file in the root of the project with the following content:
{
"ConnectionStrings": {
"DefaultConnection": "Data Source=app.db"
},
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}
-
Apply the database migrations:
dotnet ef database update
-
Run the application:
dotnet run
-
Access the API documentation at
http://localhost:8080/swagger
.
To ensure changes to the app.db
file are not included in future commits, execute the following command:
git update-index --assume-unchanged app.db
This command makes Git ignore future changes to the app.db
file in your local repository.
-
URL:
/api/posts
-
Method:
POST
-
Request Body:
{ "title": "Post Title", "content": "Post content" }
-
Response:
{ "id": 1, "title": "Post Title", "content": "Post content", "createdAt": "2024-05-27T12:34:56Z" }
-
URL:
/api/posts
-
Method:
GET
-
Response:
[ { "id": 1, "title": "Post Title", "content": "Post content", "createdAt": "2024-05-27T12:34:56Z" } ]
-
URL:
/api/posts/{id}
-
Method:
GET
-
Response:
{ "id": 1, "title": "Post Title", "content": "Post content", "createdAt": "2024-05-27T12:34:56Z" }
-
URL:
/api/posts/{id}
-
Method:
PUT
-
Request Body:
{ "title": "Updated Title", "content": "Updated content" }
-
Response:
{ "id": 1, "title": "Updated Title", "content": "Updated content", "createdAt": "2024-05-27T12:34:56Z", "updatedAt": "2024-05-27T12:45:00Z" }
- URL:
/api/posts/{id}
- Method:
DELETE
- Response:
204 No Content
To add a new migration:
dotnet ef migrations add MigrationName
To update the database:
dotnet ef database update
Contributions are welcome! Please follow these steps:
- Fork the repository.
- Create a new branch (
git checkout -b feature/YourFeature
). - Make your changes.
- Commit your changes (
git commit -m "Add some feature"
). - Push to the branch (
git push origin feature/YourFeature
). - Create a new Pull Request.
This project is licensed under the MIT License. See the LICENSE file for more details.