In the case of RESTful web services, controllers can help increase the separation of concerns between servers and clients, improve network efficiency, and let servers implement complex operations atomically.
You want to know how to tackle write operations that involve
modifying more than one resource atomically, or whose mapping to
DELETE is not obvious.
Designate a controller resource for each distinct operation. Let
clients use the HTTP method
POST to submit a request to trigger the operation. If the
outcome of the operation is the creation of a new resource, return
Created) with a
Location header referring to the URI of the newly created
resource. If the outcome is the modification of one or more existing
resources, return response code
Other) with a
Location with a URI that clients can
use to fetch a representation of those modifications. If the server
cannot provide a single URI to all the modified resources, return
OK) with a representation
in the body that clients can use to learn about the outcome. Handle
errors as described in Recipe 3.13.
A controller is a resource that can atomically make changes to resources. The need for such a resource may not be apparent from your domain model, but it can help the server abstract complex business operations and provide a way for clients to trigger those operations. This in turn reduces coupling between ...