This project is a RESTful API developed in .NET 8. It adheres to REST standards and provides CRUD operations using GET, POST, PUT, DELETE, and PATCH methods. The API handles HTTP status codes correctly and ensures that error responses for 500, 400, 404, 200, and 201 statuses are returned in a standard format. Model validation is performed for required fields, and routing is implemented. Model binding examples are provided for both body and query parameters.
- CRUD Operations: Supports GET, POST, PUT, DELETE, and PATCH methods.
- HTTP Status Codes: Follows standard HTTP status codes with error handling for 500, 400, 404, 200, and 201 statuses.
- Model Validation: Ensures required fields in models are validated.
- Routing: Implements routing for API endpoints.
- Model Binding: Examples included for binding data from both body and query parameters.
- Listing and Sorting: Additional functionality for listing and sorting products, e.g.,
/api/products/list?name=abc
.
These instructions will help you set up and run the project on your local machine.
- Clone the repository:
git clone https://github.com/MehmetOguzOzkan/PaparaCaseWeek1.git cd PaparaCaseWeek1
- Configure the database connection string in
appsettings.json
:"ConnectionStrings": { "DefaultConnection": "Server=localhost;Database=database_name;User=root;Password=your_password;" }
- Install the required packages using NuGet Package Manager Console:
Install-Package Microsoft.EntityFrameworkCore.Design Install-Package Microsoft.EntityFrameworkCore.Tools Install-Package Pomelo.EntityFrameworkCore.MySql
- Create and apply the initial migration:
Add-Migration InitialCreate Update-Database
- Open the project in Visual Studio.
- Set the project as the startup project.
- Press F5 to run the application.
- GET /api/products: Retrieve all products.
- GET /api/products/{id}: Retrieve a product by ID.
- POST /api/products: Add a new product.
- PUT /api/products/{id}: Update an existing product.
- DELETE /api/products/{id}: Delete a product.
- PATCH /api/products/{id}: Partially update a product.
- GET /api/products/list?name=abc: List and sort products.