concept topping in category api

This is an excerpt from Manning's book Irresistible APIs: Designing web APIs that developers will love.
Keeping in line with the simple API, I’ve created a simple application to exercise the API, creating a list of toppings for your virtual pizza. Again, for a real application there would be a full pizza and a method to place the order, but this application is deliberately as simple as possible so it’s easy to understand how it works.
I’ll go through the same sequence I did in the last section. Here’s our starting pizza, with pepperoni, pineapple, and pickles. Loading the initial page causes an API call to be generated, and we get the current list of toppings from the system.
Adding toppings to a pizza
Figure 7.8. The 200 (successful) response to the request for /toppings shows how the API will respond to a successful call. Because this is a JSON object, the top level is designated by curly braces, and the toppings item in the response is a list of the toppings in the system. The status pieces (success and status) reside outside of the list, as meta-information about the response.
![]()
There’s a design decision to be made here. If a pizza has a topping, should the user be able to DELETE that topping? Let’s consider three scenarios. This decision could be made at development time, but if you want the behavior to work a certain way, the specification is the place to indicate that. The potential paths to take are
Go ahead and delete the topping from the system and remove it from any pizzas that contain it (unexpected behavior). Reject the request to delete the topping, listing the pizzas that have the topping (this requires that the client application make the calls to delete the topping from each pizza explicitly). Allow for a parameter to allow the client to have a “safe” or “all” mode for removing toppings. The safe mode would fail if a pizza has the topping. The all mode would remove the topping everywhere it exists (all). The third option would be the friendliest one, but for the purposes of this demonstration you’ll implement the second option. Delete the topping from the system only if it doesn’t already exist on a pizza. If the topping does exist on pizzas, the system should return a helpful error message indicating that some number of pizzas contains the topping.