PUT vs. POST in RESTReaders new to this topic will be struck by the endless discussion about what you should do, and the relative absence of lessons from experience.The fact that REST is preferred over SOAP is, I suppose, a high level learning from experience, but goodness we must have progressed from there Its 2.Roys dissertation was in 2.What have we developed Was it fun Was it easy to integrate with To support Will it handle the rise of smartphones and flaky mobile connectionsShould I remove Command Conquer The First Decade by Electronic Arts Command amp Conquer The First Decade is a video game distributed through EA39s.Conclave is a neutral Syndicate led by the Conclave Master, Teshin.Teshin resides within the.Spore 1.20 Patch' title='Spore 1.20 Patch' />According to ME, real life networks are unreliable.Requests timeout.Connections are reset.Networks go down for hours or days at a time.Trains go into tunnels with mobile users aboard.For any given request as occasionally acknowledged in all this discussion the request can fall in the water on its way, or the response can fall in the water on its way back.In these conditions, issuing PUT, POST and DELETE requests directly against substantive resources has always struck me as a little brutal and naive.HTTP does nothing to ensure reliable completion of the request response, and thats just fine because this is properly the job of network aware applications.Developing such an application, you can jump through hoops to use PUT instead of POST, then more hoops to give a certain kind of error on the server if you detect duplicate requests.Back at the client, you then have to jump through hoops to interpret these errors, refetch, revalidate and repost. Serial Parallel Desktop 8 Mac Tam . Or you can do this consider your unsafe requests actions as ephemeral single user resources.Extrenzor_Blade1.jpg' alt='Spore 1.20 Patch' title='Spore 1.20 Patch' />Clients request a new action on a substantive resource with an empty POST to the resource.POST will be used only for this.Once safely in possession of the URI of the freshly minted action, the client PUTs the unsafe request to the action URI, not the target resource.Resolving the action and updating the real resource is properly the job of your API, and is here decoupled from the unreliable network.The server does the business, returns the response and stores it against the agreed action URI.If anything goes wrong, the client repeats the request natural behaviour, and if the server has already seen it, it repeats the stored response and does nothing else.You will quickly spot the similarity with promises we create and return the placeholder for the result before doing anything.Also like a promise, an action can succeed or fail one time, but its result can be fetched repeatedly.Best of all, we give sending and receiving applications a chance to link the uniquely identified action to uniqueness in their respective environments.And we can start to demand, and enforce, responsible behaviour from clients repeat your requests as much as you like, but dont go generating a new action until youre in possession of a definitive result from the existing one.As such, numerous thorny problems go away.Repeated insert requests wont create duplicates, and we dont create the real resource until were in possession of the data.Repeated update requests wont hit incompatible states and wont overwrite subsequent changes.Clients can refetch and seamlessy process the original confirmation for whatever reason client crashed, response went missing, etc.Successive delete requests can see and process the original confirmation, without hitting a 4.If things take longer than expected, we can respond provisionally, and we have a place where the client can check back for the definitive result.The nicest part of this pattern is its Kung Fu Panda property.We take a weakness, the propensity for clients to repeat a request any time they dont understand the response, and turn it into a strength Before telling me this is not RESTful, please consider the numerous ways in which REST principles are respected.Clients dont construct URLs.The API stays discoverable, albeit with a little change in semantics.HTTP verbs are used appropriately.If you think this is a huge change to implement, I can tell you from experience that its not.If you think youll have huge amounts of data to store, lets talk volumes a typical update confirmation is a fraction of a kilobyte.HTTP currently gives you a minute or two to respond definitively.Even if you only store actions for a week, clients have ample chance to catch up.If you have very high volumes, you may want a dedicated acid compliant key value store, or an in memory solution.If you still need convincing, I have a little Google Docs document here.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |