Popular Posts

Monday, January 26, 2015

Asp.net Web Api Patch using Delta



Using Delta
Listing 6-14 shows Delta in use. You will need to tweak your PATCH method to take Delta as an input instead of
just using your model. Then, to perform a patch update over an existing resource, you call the PATCH method exposed
by the Delta proxy and pass in an instance of that object that should be updated. In this example, you have no DB
to persist in, but you should then proceed to save the original object in the DB, as its state has been modified to reflect
the updates requested by the client. 






        [Route("delta/{id:int}")]

        public Item Patch(int id, Delta<Item> newItem)

        {

            var item = _items.FirstOrDefault(x => x.Id == id);

            if (item == null) throw new HttpResponseException(HttpStatusCode.NotFound);

            newItem.Patch(item);

            //item instance is now updated

            return item;

        }

No comments:

Post a Comment