Communicating with the Product API
To validate whether the products of an order exist, the Order Management API validates the inserted product SKUs against the Product API through an API call either when a new order is created or when an order update contains an insertion of a new product into the order.
In real-world production applications, the Product API may need to validate whether there are enough products available in stock to be added to the order and respond properly if there are not. For our purposes of demonstrating how to create APIs, we will show how to validate whether the products of an order exist within Product API service data and retrieve their prices to be added to our order. If a product is not found, the Order Management API will return a proper message with a 404 Not Found
HTTP status code and the error message Product not found
, explaining that the order cannot be placed because that product does not exist and needs to be created in the Product API.