1

If I have an observableArray and update one if the items using AJAX PUT (or PATCH) to a WebAPI method, should I either

  1. Just leave it at that assuming there are no errors.
  2. Send back the updated entity with the response and update the item
  3. Perform a GET request after the PUT and update the entire array again

If I don't bring back the entity and have a foreign key, I have to go to another knockout array to get the details, however, if I bring back data from the WebAPI service, I do this on the server.

I'll add some code / a fiddle and update the question if this doesn't make sense.

PMC
  • 4,698
  • 3
  • 37
  • 57

1 Answers1

1

there are a few other questions regarding how to handle a PUT request with comments:

In REST, should I return the representation in response to a PUT?

Should a RESTful 'PUT' operation return something

I tend to side with returning the resource, with whatever modifications (if any) were made server side, and then updating the viewmodel with it. In your case, when you finish the update on the server, return the resource with all of the associated data you need to update your viewmodel. That way you dont need to do extra client side mapping of data to your updated model.

reasons why i wouldnt do 1 or 2

  • dont get any extra data the server might add, and you have to handle any other updates client side.
  • extra overhead of making yet another http request for data you could have gotten back from the initial put request
Community
  • 1
  • 1
Kevin Nacios
  • 2,843
  • 19
  • 31
  • Thanks, that was my instinct, just wanted another person to validate. I was looking at webapi questions but should have searched for rest and i would have noticed those questions – PMC Jun 29 '13 at 05:39