[Dojo-interest] Some more questions on JsonRestStore

Kris Zyp kris at sitepen.com
Wed Aug 6 14:39:01 UTC 2008


The store does set the id if you include a Location header (per the HTTP spec). Is there a reason that won't work for you? If you really want it to be a two-step process, I think the first request (server id allocation) should probably be done as a custom RPC outside of the store (so the store doesn't think the first request is actually creating an object).

Also, one more point of interest on this subject, JsonRestStore does not prevent commits from happening simultaneously (or queue them). Consequently, you can create a new item and commit, triggering a POST, and then modify that new item and do a commit before the client has received a response from the first POST. In such a situation the JsonRestStore has not received any id assignment from the server yet, and must use it's randonly generated id for the PUT. The mitigation for this is that JsonRestStore will include a Content-Location header with the POST request indicating the client side id, and the server can keep a temporary map of client ids to the server items in case the client needs to make a change to an object prior to getting id assignment. This is probably an extreme edge case for most users, making modifications prior to getting a response from the new item is probably not that common. An alternative approach is that I could force commits to be synchronized, queuing them if there is one in progress so ids are always available. However, I went with the Content-Location header approach since that minimizes client side code and has the best performance characteristics.

Kris
  ----- Original Message ----- 
  From: Peter Svensson 
  To: dojo-interest at dojotoolkit.org 
  Sent: Wednesday, August 06, 2008 8:31 AM
  Subject: Re: [Dojo-interest] Some more questions on JsonRestStore


  Hi Kris!
  Yes, I've been having some good days and some bad lately when running from svn up :)
  Still, we really need the store, since it's the best candidate for implementing a back-to-back solution. 

  I'd really appreciate if you could set the returned id in the store. Possibly you could do what I do; make a two-step, with a first POST retrieving a new object with the correct id, from the server, and then creating a new item, and as a last thing actually entering the item in the store.
  Maybe this would break true REST, but that would imply that true REST would force unique id generation to be on the client always. I'm not even sure that's safe.

  Cheers,
  PS


  On Wed, Aug 6, 2008 at 4:24 PM, Kris Zyp <kris at sitepen.com> wrote:

    > When I call store.newItem(); I get a new nice row in my DataGrid (Dojo 1.2a from SVN).  When this is saved, > by calling store.save(); the server replies with the newly created object;
    > 
    > {"id": "1"}

    Id assignment from the server is an issue I have been working lately, yesterday (or the day before) I committed an update to JsonRestStore that will update the id based on the Location header in the response to the POST request. So if I do:
    POST /mytable/
    ...

    {foo:"bar"}

    And get a response of

    HTTP/1.1 200 OK
    Location: /mytable/1
    ...

    JsonRestStore should properly assign the id to the new object. Unfortunately I have documented this yet, still trying to figure out if this is the best way (feedback appreciated). This seems to be the most HTTP conformant approach to id assignment (and JsonRestStore strives to stick to the HTTP standards as much as possible for interoperability). I could add some logic for updating based on the returned JSON object...

    Also, just FYI, the id assignment affects what URL is used for later PUT requests, it does not affect id returned from getIdentity calls. Changing the id visible through getIdentity causes widgets to break (the grid in particular). Hopefully JsonRestStore successfully hides these issues for you.

    Thanks,
    Kris


    _______________________________________________
    FAQ: http://dojotoolkit.org/support/faq
    Book: http://dojotoolkit.org/docs/book
    Forums: http://dojotoolkit.org/forum
    Dojo-interest at dojotoolkit.org
    http://turtle.dojotoolkit.org/mailman/listinfo/dojo-interest






------------------------------------------------------------------------------


  _______________________________________________
  FAQ: http://dojotoolkit.org/support/faq
  Book: http://dojotoolkit.org/docs/book
  Forums: http://dojotoolkit.org/forum
  Dojo-interest at dojotoolkit.org
  http://turtle.dojotoolkit.org/mailman/listinfo/dojo-interest
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://turtle.dojotoolkit.org/pipermail/dojo-interest/attachments/20080806/196909ad/attachment.html 


More information about the Dojo-interest mailing list