I am working on a WCF RESTful service and noticed that in some places I can present operations other than CRUD (not resources) in more than one way.
Say we bought a new TV and connected it to our private network. Now we want to create a Web service for viewing and managing the TV.
To read and update the properties of the TV, we will use the following URI:
http: // domain / tv / GET | PUT - receiving and updating TV properties. ( company , owner , inches )
To use the video, we will use the following URI:
ws: // domain / tv / video - (suppose WebSocket is the best option for transferring video content)
And operations:
updateVersionstartBIT (built-in self test)changeChannelturnVolumeUp , turnVolumeDown
The first project is to use properties to represent operations. The server will see the property changes, and then perform the required operations. Finally, POST operations that cannot be represented by properties:
http: // domain / tv / GET | PUT - getting or setting volume or channel using json objects.
and for updateVersion or startBIT :
http: // domain / tv / POST with {function: 'updateVersion'} or {function: 'startBIT'}
The second project is to represent all operations using the Command resource:
http: // domain / tv / commands POST with {command: 'BIT', sender: 'Dan' ...} - create a new command to execute startBIT , changeChannel or turnVolume
The third design is to represent each operation, which can be expressed as a noun as a resource, and the rest as properties:
http: // domain / tv / versionUpdates GET | Put | REMOVE | Post
http: // domain / tv / BITs GET | Put | REMOVE | Post
http: // domain / tv / PUT ({volume: 10})
http: // domain / tv / PUT ({channel: 29})
What is the best RESTful design?
Matan source share