This repository contains a minimal API implementation using ASP.NET Core, featuring endpoints for managing coupons and user authentication. The project demonstrates CRUD operations for coupons and user management functionalities including login, registration, token refresh, and token revocation.
- CRUD Operations: Create, Retrieve, Update, and Delete coupons.
- Validation: Uses FluentValidation for input validation.
- Authorization: Requires authorization for all coupon-related endpoints.
- Login: Authenticate users and issue access tokens.
- Registration: Register new users with unique email addresses.
- Token Refresh: Refresh access tokens using valid refresh tokens.
- Token Revocation: Revoke refresh tokens to invalidate them.
- URL:
/api/getCoupons
- Method:
GET
- Authorization: Required (
AdminOnly
) - Responses:
200 OK
: Returns a list of all coupons.401 Unauthorized
: If the user is not authorized.
- URL:
/api/getCouponById/{id:int}
- Method:
GET
- Authorization: Required
- Responses:
200 OK
: Returns the coupon with the specified ID.401 Unauthorized
: If the user is not authorized.
- URL:
/api/createCoupon
- Method:
POST
- Authorization: Required
- Request Body:
CouponCreateDTO
(JSON) - Responses:
201 Created
: Coupon created successfully.400 Bad Request
: Validation error or duplicate coupon name.401 Unauthorized
: If the user is not authorized.404 Not Found
: If the resource is not found.
- URL:
/api/updateCoupon
- Method:
PUT
- Authorization: Required
- Request Body:
CouponUpdateDTO
(JSON) - Responses:
200 OK
: Coupon updated successfully.400 Bad Request
: Validation error.404 Not Found
: Coupon not found.401 Unauthorized
: If the user is not authorized.
- URL:
/api/deleteCoupon/{id:int}
- Method:
DELETE
- Authorization: Required
- Responses:
204 No Content
: Coupon deleted successfully.404 Not Found
: Coupon not found.401 Unauthorized
: If the user is not authorized.
- URL:
/api/login
- Method:
POST
- Request Body:
LoginRequestDto
(JSON) - Responses:
200 OK
: Returns an access token if login is successful.400 Bad Request
: If validation fails or credentials are incorrect.401 Unauthorized
: If authentication is not authorized.
- URL:
/api/register
- Method:
POST
- Request Body:
RegistrationRequestDto
(JSON) - Responses:
201 Created
: Returns user information if registration is successful.400 Bad Request
: If the email already exists or registration fails.
- URL:
/api/refreshToken
- Method:
POST
- Request Body:
TokenDto
(JSON) - Responses:
200 OK
: Returns a new access token if the refresh token is valid.400 Bad Request
: If the refresh token is invalid or validation fails.
- URL:
/api/revokeRefreshToken
- Method:
POST
- Request Body:
TokenDto
(JSON) - Responses:
200 OK
: Indicates that the refresh token has been revoked successfully.400 Bad Request
: If validation fails.
- Run the application using your preferred method (e.g., Visual Studio or CLI).
- Make HTTP requests to the endpoints using tools like Postman or CURL.
- Ensure authorization headers are provided for endpoints requiring authentication.
-
Clone the repository:
git clone https://github.com/yourusername/MinimalAPIDemo.git
-
Navigate to the project directory:
cd MinimalAPIDemo
-
Install dependencies using .NET CLI:
dotnet restore
-
Build the project:
dotnet build
-
Run the application:
dotnet run
Contributions are welcome! Please fork the repository and submit a pull request with your changes. Ensure that your code adheres to the project's coding standards and includes appropriate tests.
This project is licensed under the MIT License - see the LICENSE file for details.
Feel free to customize the URL and repository details to fit your actual project. This README provides a comprehensive overview of the available endpoints and their usage.