Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use PATCH instead of PUT for updating records #3

Closed
gr0uch opened this issue Sep 5, 2013 · 9 comments · Fixed by eneuhauser/ember-json-api#6
Closed

Use PATCH instead of PUT for updating records #3

gr0uch opened this issue Sep 5, 2013 · 9 comments · Fixed by eneuhauser/ember-json-api#6

Comments

@gr0uch
Copy link
Collaborator

gr0uch commented Sep 5, 2013

Currently, the adapter still follows the default REST adapter behaviour when updating records, which is to PUT the entire resource. A smarter, better approach would be to only serialize changes, and send the request as a PATCH.

The request might look something like this:

PATCH /animals/123
Content-Type: application/json-patch+json

[
  {"op": "replace", "path": "/animals/0/name", "value": "Tomster"},
  {"op": "replace", "path": "/animals/0/links/friends", "value": ["124"]}
]
@wrenoud
Copy link

wrenoud commented Jul 14, 2014

I think you mentioned this over in #19 wrt the spec update, but it may be easier to use the new breaking changes that allow for only including changed attributes in PUT, per updating attributes.

@gr0uch
Copy link
Collaborator Author

gr0uch commented Jul 14, 2014

The JSON API authors have mentioned that PUT is almost never what you want to do. I'm keeping this open, since PATCH support is very nice to have.

@ColtonProvias
Copy link

It should be mentioned that JSON API now lists PUT as an option for updating resources. PATCH is now further down on the page as an optional implementation for servers.

http://jsonapi.org/format/#crud

@andrewbranch
Copy link

Looks like PUT is no longer mentioned in the spec. What’s the status of this?

@jonkoops
Copy link
Contributor

I've found some additional information about PUT requests in the FAQ:

Where's PUT? Can I use method X to do Y?

JSON API does not currently specify the use of the PUT method for any purpose.

Servers may complement the base specification by providing extra capabilities and alternative ways of requesting certain operations (e.g., resource creation via PUT in addition to POST).

@andrewbranch
Copy link

So shouldn’t this change be incorporated into #71? I can look into it if it’s not already in progress elsewhere.

@kurko
Copy link
Owner

kurko commented Apr 28, 2015

Yes, I think it should @andrewbranch.

@andrewbranch
Copy link

@kurko Already done :)

@jonkoops
Copy link
Contributor

jonkoops commented Jun 2, 2015

Closing this issue since the discussed code has been merged into master.

@jonkoops jonkoops closed this as completed Jun 2, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants