The Product Catalog API is a RESTful backend application built with .NET 8, following a clean, layered architecture (Domain, Application, Infrastructure, and API layers).
It provides full CRUD operations for managing Products and Users, with JWT authentication and role-based authorization (Admin / User).
This API simulates a simple product management system with different user roles:
- Admin users can perform all CRUD operations on products and manage users.
- Regular users can only view products.
- Passwords are securely stored using BCrypt hashing.
- Uses Entity Framework Core with MySQL as the database provider.
- Integrated Swagger UI for easy testing of all endpoints.
- .NET 8
- Entity Framework Core
- MySQL (
Pomelo.EntityFrameworkCore.MySql) - JWT Authentication (
Microsoft.AspNetCore.Authentication.JwtBearer) - BCrypt.Net-Next for password hashing
- Swagger / Swashbuckle
- Dependency Injection
- Async / Await architecture
Make sure you have installed:
- .NET SDK 8.0+
- MySQL Server
- Visual Studio or VS Code
- Optional: Postman for testing API requests
git clone https://github.com/Andrea2301/SM.git
cd ProductCatalogIn appsettings.json (inside ProductCatalog.Api), update the connection string:
"ConnectionStrings": {
"Default": "server=localhost;database=productdb;user=root;password=yourpassword;"
},
"Jwt": {
"Key": "your_secret_key_here",
"Issuer": "yourapp",
"Audience": "yourapp_users"
}Run from the root directory:
dotnet ef database update --project ProductCatalog.Infrastructure --startup-project ProductCatalog.ApiThis creates all required tables (Users, Products) in your MySQL database.
cd ProductCatalog.Api
dotnet runSwagger UI will be available at:
https://localhost:7069/swagger
The API uses JWT Bearer Authentication.
| Role | Permissions |
|---|---|
| Admin | Full CRUD on Products and Users |
| User | Read-only access to Products |
| Method | Endpoint | Description |
|---|---|---|
| POST | /api/Auth/register |
Register a new user |
| POST | /api/Auth/login |
Login and receive JWT |
| POST | /api/Auth/refresh |
Refresh a token |
| POST | /api/Auth/Logut |
Logout |
Example – Login Response:
{
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI..."
}| Method | Endpoint | Description | Role |
|---|---|---|---|
| GET | /api/User/GetAll |
Get all users | Admin |
| GET | /api/User/GetById/{id} |
Get user by ID | Admin |
| POST | /api/User/Create |
Create new user | Public |
| PUT | /api/User/Update/{id} |
Update user info | Admin |
| DELETE | /api/User/Delete/{id} |
Delete user | Admin |
| Method | Endpoint | Description | Role |
|---|---|---|---|
| GET | /api/Product/GetAllProducts |
Get all products | Admin / User |
| GET | /api/Product/GetById/{id} |
Get product by ID | Admin / User |
| POST | /api/Product/Create |
Add a new product | Admin |
| PUT | /api/Product/Update/{id} |
Update existing product | Admin |
| DELETE | /api/Product/Delete/{id} |
Delete product | Admin |
- Login with
/api/Auth/loginto get a JWT token. - Copy the token (without quotes).
- In Swagger UI, click Authorize (lock icon).
- Enter:
Bearer your_token_here
Now you can access protected endpoints.
POST → /api/Product/Create
{
"name": "Wireless Mouse",
"description": "Ergonomic Bluetooth mouse",
"price": 29.99
}Header:
Authorization: Bearer <your_admin_token>
| Folder | Responsibility |
|---|---|
| Domain | Core entities and repository interfaces. Defines the business model without dependencies. |
| Application | Business logic, DTOs, validation, and use cases. Connects domain with infrastructure. |
| Infrastructure | Database connection, EF Core context, and repository implementations. |
| API | Controllers, authentication, and configuration. Entry point of the application. |
You can test endpoints with:
- Swagger UI →
https://localhost:7069/swagger - Postman → Import the API and send JWT in the
Authorizationheader.
Example:
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI...