It's bit lengthy but simple to understand so please read it.
We have a feedback form where the user fills the complaint/suggestions. To fill a complaint, the user needs to fill his/her {Name, Mobile Number, ZipCode}. As a response to this complaint, we show our nearest call center number based on user's pin code.
Once the user submits the feedback [name, mobile, zip code], the complete process is:
This process needs to be integrated across platforms (Mobile, Desktop, Apps) and we need to design Restful APIs for this. Few choices:
Which of these 3 is correct OR is there any 4th way to solve this problem?
I actually like the 3rd option. A failed post shouldn't affect the ability to get the nearest call center right? A failed post would be a problem in the second option as well. These call centers should already be in database. I'm sure you'll have some code/subroutine to calculate the shortest distance between any given zip code and all of the call centers. And in the third option, even though a complaint wouldn't be filed in a failed post, at least the user could get the number of the nearest call center to continue to get help
Teach a man to fish: almost every question in of the form "what is the REST way to do X?" has the answer "figure out how to do it with html links and forms, and match that pattern as closely as you can."
the problem here is that as per rest where we send back new created object in POST response
If that wasn't true, would it make your life easier? If so, good news....
REST doesn't say anything about "create"; it says that resources should conform to the uniform interface.
If you are communicating with your API via http(s), the uniform interface is defined by RFC 7231 (not REST; REST is an architectural style, the Web is a reference application built using that style).
HTTP does not say that POST must equal create.
The POST method requests that the target resource process the representation enclosed in the request according to the resource's own specific semantics.
a representation of the status of, or results obtained from the action
In your case, the status of your action is "congratulations, our attempt to find the closest care center to you succeeded. here it is...." Yes, this has nothing to do with the fact that you created a complaint record in the database. From the point of view of the web client, there is no database . Just the resources and the uniform interface.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.