RESTful applications logic and cross resource operations
Posted
by
Gaz_Edge
on Programmers
See other posts from Programmers
or by Gaz_Edge
Published on 2013-07-01T22:11:14Z
Indexed on
2013/07/01
23:14 UTC
Read the original article
Hit count: 242
I have an RESTful api that allows my users to receive enquiries about their business e.g. 'I would like to book service x on date y. Is this available?'. The api saves this information as a resource to the following URI
users/{userId}/enquiries/{enquiryId}
The information shown when this resource is retrieved are the standard sort of things you'd expect from an enquiry - email, first_name, last_name, address, message
The api also allows customers to be created for a user. The customer has a login and password and also a profile. The following URIs expose these two resources
PUT users/{userId}/customers/{customerId}
PUT users/{userId}/customers/{customerId}/profile
The problem I am having is that I would like to have the ability to allow users to create a customer from an enquiry. For example, the user is able to offer their service on the date requested and will then want to setup a customer with login details etc to allow them to manage the rest of the process.
The obvious answer would be to use a URI like
users/{userId}/enquiries/{enquiryId}/convert-to-client
The problem with this is is that it somewhat goes against a lot of what I've been reading about how to implement REST (specifically from the book Restful Web Services which suggests that URIs should point to resources not operations on resources).
The other option would be to get the client application (i.e. the code that calls the api) to handle some of this application logic. This doesn't quite feel right to me. I have implemented in my design that the client app is fairly dumb. It knows just enough to display the results from the API, and does not contain any application logic.
Would be great to hear what others views are on the best way of setting this up
Am I wrong to have no application logic in the client app? How would I perform this operation purely in the REST api?
© Programmers or respective owner