Skip to content

Use PATCH verb instead of PUT for "update" #348

@dlee

Description

@dlee

Rails should map the PATCH HTTP verb to the update action to respect proper HTTP/REST semantics.

The current mapping of PUT to update is an imprecise mapping of HTTP verbs ("REST") to CRUD. PUT more accurately means "place" or "replace", and can even be used to create new records at a specific URI.

From the HTTP specs for PATCH:

The PUT method is already defined to overwrite a resource
with a complete new body, and cannot be reused to do partial changes.
Otherwise, proxies and caches, and even clients and servers, may get
confused as to the result of the operation.

Furthermore, Rails convention for the update action is not idempotent--a requirement for PUT according to the specs.

As a solution, I propose that PATCH requests be routed to the update action alongside PUT. Furthermore, PATCH should be made the default form method when editing existing model records, since 99% of the time, users want to modify an existing record instead of replacing it. In later versions, PUT can be deprecated or mapped to a different action with proper semantics.

This change should not break browser compatibility since browsers are already using _method param override for PUT; changing that to PATCH should be simple. Furthermore, leaving the default PUT routing (alongside PATCH) in restful routes should make this change backwards compatible for most users.

If this is something the core developers agree with, I can contribute a ... um ... patch.

Reference: http://tools.ietf.org/html/rfc5789

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions