I have an existing application that controls a machine and want to add a REST interface to it. Two of the high level commands are to start and stop machine operation. I had originally though about mapping these operations to POST and DELETE verbs, such as:
POST /control // start machine operation
DELETE /control // stop machine operation
but we’re not really deleting anything as such, just stopping operation. Delete doesn’t seem to be a good fit. Another idea was to further spell out the operations in the URL, such as
POST /control/start_operation // start machine operation
POST /control/stop_operation // stop machine operation
but this seems to contradict the REST concept of not putting verbs in the URLs. Any advice from the Stack Overflow readers out there on how best to map this kind of operation?
REST stands for Representational State Transfer where the interaction focuses on transferring the state of resources.
In order to design a “proper” REST interface, you first have to define what resources’ state is being transferred.
From what you’ve said, it seems that the only state that would be transferred is the current status of the machine. To that end, you are really just updating that state with the REST calls, and there happens to be additional activities that happen based on this state.
The HTTP verb that best fits the “Update the state and have other things happen” model is POST. You would POST to
/myMachineController/statusand the payload would be eitheronoroff.In general, REST is very much a data-centric service paradigm and doesn’t usually fit too well in places where there isn’t very much data to act on.