1

I have an interesting issues and wanted some input from someone with a similar experience. I have an Android app that makes a REST call (e.g. accepts an open order). App sends out the request and runs into connectivity issues, meanwhile server gets the request, changes order state and sends back a response (e.g. HTTP 200). But, the app, missing its network connection, does not receive the response and gets an timeout exception. If I try to accept the order again, I get response that it is already taken (in this case by me).

The question would be - what should be the best approach to such situation. For now, the requirements are to run a loop if I get a timeout exception (in some scenarios it's a loop including another web call to check whether this order did not appear in my "CurrentOrders"). I don't like this design and was wondering what would be better. Maybe the web call could return 200 (success) if the same client tries to accept the same order twice or more? Or how would some of you handle such situation?

1 Answers1

0

I'm not quite clear about the semantic of your "accept" action.

What does it actually do? On the one hand it seems it updates the order state. It should be then idempotent since further updates should not change anything.

On the other hand you have some kind of external state (order is taken). This can't be done through REST, you have to use some kind of unique id to resolve the conflict. Look at this question for more info.

Community
  • 1
  • 1
PsiX
  • 1,661
  • 1
  • 17
  • 35
  • I get the orders through a message broker. When I accept one - i send a request saying ../AcceptOrder/OrderID. The server is a black box for me, but I would guess that it sets the state of the order to taken. If I get 200 from the response, I put the order to the database and consider it to be taken by me. –  May 06 '14 at 10:51
  • and to clarify - it is usually a HTTP POST. The comment about idempotence is nice, didn't know that. But does that apply to POST requests? –  May 06 '14 at 10:59
  • Do you get the information about who has taken the order? If yes you can check if you have the order yourself. Otherwise take a look at this answer, which tries to elaborate how to prevent double POST requests (e.g. through unique ids). http://stackoverflow.com/questions/15159274/avoid-duplicate-posts-with-rest – PsiX May 06 '14 at 12:11
  • 1
    yes, i wish i would get the owner of the order. that would be a good enough solution. anyway, thanks for the links and your insights, I think I can manage something from here. –  May 06 '14 at 13:29