This project is a simple Todo API built with ASP.NET Core, featuring JWT Authentication, Entity Framework Core, and PostgreSQL.
- CRUD operations for managing Todo items
- JWT Authentication to secure the API
- Entity Framework Core for data access
- PostgreSQL as the database provider
- ASP.NET Core Identity for user authentication
git clone https://github.com/yourusername/todo-api.git
cd todo-api
Make sure you have the necessary NuGet packages installed:
dotnet restore
Create a PostgreSQL database and configure the connection string in appsettings.json
:
{
"ConnectionStrings": {
"DefaultConnection": "Host=localhost;Database=your_database_name;Username=your_username;Password=your_password"
}
}
Run the following commands to create the database tables:
dotnet ef migrations add InitialCreate
dotnet ef database update
Set the following environment variables for JWT authentication:
export JWT_KEY="YourSecureKey123456!"
export JWT_ISSUER="YourIssuer"
export JWT_AUDIENCE="YourAudience"
dotnet run
The application will be running on http://localhost:5000
(or a different port if configured).
Method | Endpoint | Description |
---|---|---|
GET | /api/Todo | Get all Todo items |
GET | /api/Todo/{id} | Get a Todo item by ID |
POST | /api/Todo | Create a new Todo item |
PUT | /api/Todo/{id} | Update a Todo item |
DELETE | /api/Todo/{id} | Delete a Todo item |
The API uses JWT Authentication. To access the protected routes, a valid JWT token must be provided in the Authorization
header:
Authorization: Bearer <your_jwt_token>
To generate a JWT token, implement an authentication endpoint (e.g., /api/auth/login
) in your API, or use a pre-existing user management system with ASP.NET Core Identity.
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
This project is licensed under the MIT License.