A RESTful API built with ASP.NET Core (.NET 10.0) for managing user records with JWT authentication, request/response logging, and standardized error handling.
- π JWT Authentication - Secure API endpoints with JSON Web Tokens
- π₯ User CRUD Operations - Create, Read, Update, and Delete user records
- β Input Validation - Name validation requiring at least 3 words
- π Request/Response Logging - Custom middleware for logging all API requests
- π‘οΈ Global Exception Handling - Standardized error responses across all endpoints
- π OpenAPI/Swagger Documentation - Interactive API documentation with Swagger UI
- π Minimal API - Built with .NET Minimal API architecture
- .NET 10.0
- ASP.NET Core
- JWT Bearer Authentication
- Swashbuckle.AspNetCore - OpenAPI/Swagger documentation
- C#
- .NET 10.0 SDK
- A code editor (Visual Studio, VS Code, or Rider)
- Clone the repository:
git clone https://github.com/jrigo23/UserManagementAPI.git
cd UserManagementAPI- Restore dependencies:
dotnet restore- Build the project:
dotnet build- Run the application:
dotnet runThe API will start and be available at https://localhost:5001 (or the port specified in your launch settings).
The API includes interactive Swagger/OpenAPI documentation that is automatically generated and available when you run the application.
Once the application is running, navigate to:
- Swagger UI:
http://localhost:5048/orhttp://localhost:5048/index.html - OpenAPI JSON:
http://localhost:5048/swagger/v1/swagger.json
The Swagger UI provides:
- π Complete API documentation with descriptions for all endpoints
- π§ͺ Interactive testing - try out API calls directly from the browser
- π JWT authentication support - use the "Authorize" button to add your JWT token
- π Request/response examples and schemas
- π·οΈ Organized endpoints by tags (Authentication, Users)
- Call the
/api/auth/loginendpoint with the default credentials (username:admin, password:password123) - Copy the JWT token from the response
- Click the "Authorize" button at the top of the Swagger UI
- Paste the token in the "Value" field
- Click "Authorize" and then "Close"
- You can now test authenticated endpoints
POST /api/auth/loginRequest Body:
{
"username": "admin",
"password": "password123"
}Response:
{
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"expiresAt": "2026-01-31T12:00:00Z",
"message": "Login successful"
}GET /api/users
Authorization: Bearer {token}GET /api/users/{id}
Authorization: Bearer {token}POST /api/users
Authorization: Bearer {token}
Content-Type: application/json
{
"name": "John Michael Doe",
"status": "Active"
}Validation Rules:
- Name must contain at least 3 words
- New users are initially created with "Inactive" status
PUT /api/users/{id}
Authorization: Bearer {token}
Content-Type: application/json
{
"name": "Jane Marie Smith",
"status": "Active"
}Validation Rules:
- Name must contain at least 3 words
DELETE /api/users/{id}
Authorization: Bearer {token}- Call the
/api/auth/loginendpoint with valid credentials - Receive a JWT token in the response
- Include the token in the
Authorizationheader for all subsequent requests:Authorization: Bearer {your-token-here}
UserManagementAPI/
βββ Middleware/
β βββ RequestResponseLoggingMiddleware.cs
βββ Properties/
β βββ launchSettings.json
βββ bin/
βββ obj/
βββ Program.cs # Main application entry point
βββ UserManagementAPI.csproj # Project configuration
βββ UserManagementAPI.sln # Solution file
βββ UserManagementAPI.http # HTTP test requests
βββ appsettings.json # Application configuration
βββ appsettings.Development.json # Development configuration
βββ test-api.ps1 # PowerShell test script
βββ TEST_VALIDATION_REPORT.md # Testing documentation
All errors return a standardized JSON response:
{
"statusCode": 404,
"message": "User not found",
"details": "No user found with ID 5",
"timestamp": "2026-01-31T10:30:00Z"
}Common status codes:
400- Bad Request (validation errors)401- Unauthorized (invalid credentials or missing token)404- Not Found (user doesn't exist)500- Internal Server Error (unhandled exceptions)
The repository includes test utilities:
- UserManagementAPI.http - HTTP requests for testing with REST Client or similar tools
- test-api.ps1 - PowerShell script for automated API testing
- TEST_VALIDATION_REPORT.md - Detailed testing documentation
. est-api.ps1- Store JWT secrets in environment variables or secure configuration
- Implement proper user authentication against a database
- Use HTTPS in production
- Implement rate limiting
- Add proper password hashing (bcrypt, Argon2)
- Consider implementing refresh tokens
- Add logging to a persistent store
For testing purposes only:
- Username:
admin - Password:
password123
This project is open source and available for educational purposes.
jrigo23
Built with β€οΈ using ASP.NET Core