A simple ASP.NET Core Web API project with Products CRUD operations.
- ✅ Full CRUD operations for Products
- ✅ RESTful API endpoints
- ✅ Input validation
- ✅ Error handling
- ✅ Swagger/OpenAPI documentation
- ✅ Search functionality
- ✅ In-memory data storage
Method | Endpoint | Description |
---|---|---|
GET | /api/products |
Get all products |
GET | /api/products/{id} |
Get product by ID |
POST | /api/products |
Create new product |
PUT | /api/products/{id} |
Update entire product |
PATCH | /api/products/{id} |
Partially update product |
DELETE | /api/products/{id} |
Delete product |
GET | /api/products/search?name={term} |
Search products by name |
Method | Endpoint | Description |
---|---|---|
GET | /weatherforecast |
Get weather forecast data |
- .NET 8.0 SDK
- PowerShell (Windows) or Terminal (macOS/Linux)
- Clone or download the project
- Navigate to the project directory:
cd BasicApi
- Run the application:
dotnet run
- Open your browser and navigate to:
- API:
https://localhost:7xxx
- Swagger UI:
https://localhost:7xxx/swagger
- API:
- Make sure Docker is installed and running
- Build and run with Docker Compose:
docker-compose up --build
- Or build and run with Docker commands:
# Build the image docker build -t basicapi . # Run the container docker run -p 5000:8080 -p 5001:8081 basicapi
- Open your browser and navigate to:
- API:
http://localhost:5000
- HTTPS API:
https://localhost:5001
- Swagger UI:
http://localhost:5000/swagger
- API:
The API comes with 3 sample products:
- Laptop - Gaming laptop ($999.99)
- Mouse - Wireless mouse ($29.99)
- Keyboard - Mechanical keyboard ($79.99)
BasicApi/
├── Controllers/
│ └── ProductsController.cs # Products CRUD controller
├── Models/
│ ├── Product.cs # Product entity model
│ └── ProductDto.cs # Data transfer objects
├── Properties/
│ └── launchSettings.json # Launch configuration
├── appsettings.json # Application settings
├── appsettings.Development.json # Development settings
├── Program.cs # Application entry point
├── BasicApi.csproj # Project file
├── BasicApi.http # HTTP test file
├── Dockerfile # Docker container definition
├── .dockerignore # Docker ignore rules
├── docker-compose.yml # Docker Compose configuration
└── README.md # This file
- ASP.NET Core 8.0 - Web framework
- Swagger/OpenAPI - API documentation
- Newtonsoft.Json - JSON serialization
- System.ComponentModel.DataAnnotations - Model validation
dotnet build
dotnet test
This project currently uses in-memory storage. To add database support:
-
Install Entity Framework Core:
dotnet add package Microsoft.EntityFrameworkCore.SqlServer dotnet add package Microsoft.EntityFrameworkCore.Tools
-
Create a DbContext and configure it in
Program.cs
-
Update the controller to use the DbContext instead of static lists
- Fork the project
- Create a feature branch
- Make your changes
- Test your changes
- Submit a pull request
This project is for educational purposes.