This is a sample project that implements a RESTful API for managing products. The API allows the creation, retrieval, update, and deletion of products. It also integrates RabbitMQ for publishing product creation events.
- Clone the repository:
git clone
- Install the required packages by running the following command:
dotnet restore
- Start the RabbitMQ server using Docker by running the following command:
docker-compose up -d
- Run the application by running the following command:
dotnet run
The API supports the following endpoints:
- POST
/api/products
- creates a new product - PUT
/api/products/{id}
- updates an existing product - 0DELETE
/api/products/{id}
- deletes a product - GET
/api/products/{id}
- retrieves a product by its ID - GET
/api/products
- retrieves all products
To create a new product, send a POST request to /api/products
with the following JSON data in the request body:
{
"name": "Product Name",
"description": "Product Description",
"price": 9.99
}
The API will respond with the following JSON data:
{
"id": "4e833bf3-9477-4ee8-8b45-d2f28b632d07",
"name": "Product Name",
"description": "Product Description",
"price": 9.99
}
The API will also publish a message to RabbitMQ with the following JSON data:
{
"id": "4e833bf3-9477-4ee8-8b45-d2f28b632d07",
"name": "Product Name",
"description": "Product Description",
"price": 9.99
}
You can use the RabbitMQ management console to view the published messages. Open a web browser and go to http://localhost:15672/
. Log in using the default credentials (guest/guest).