fuel / core

Fuel PHP Framework - The core of the Fuel v1 framework
http://fuelphp.com
813 stars 345 forks source link

REST controller HTTP methods #1499

Closed chrisveness closed 11 years ago

chrisveness commented 11 years ago

The REST controller implements the GET, POST, PUT, DELETE methods, but not PATCH, which is recommended for partial updates (eg https://restful-api-design.readthedocs.org/en/latest/methods.html#patch-vs-put).

I am currently using PUT for partial updates, but this is strictly against the spec, which says that values not supplied in a PUT request should be set to null.

For completeness, implementing HEAD and OPTIONS methods could be considered, though I've never made use of them.

WanWizard commented 11 years ago

The REST controller doesn't do anything specific with the HTTP method, it just uses it. What exactly happens when you use PATCH instead of PUT (and use a method "patch_something" instead of "put_something")?

chrisveness commented 11 years ago

Harro,

As I understand it, the differences between POST, PUT and PATCH are something like: a.. POST: to create new resource where the API is responsible for naming the new resource (which should be returned in the Location header) b.. PUT: either to create new resource where client is responsible for the resource name, or to replace an existing resource; in either case, any fields not supplied are set to null c.. PATCH: to update an existing resource, leaving any fields not supplied unchanged Does that make it clear?

I am in fact currently ignoring this aspect of the spec, and using PUT to do what PATCH should be used for, but I thought it might be good for FuelPHP to provide the complete set of methods.

Chris

WanWizard commented 11 years ago

I get that, but that was not my point.

Point is that the REST controller doesn't do anything special with the method. It just fetches the HTTP_METHOD passed by the webserver, so if the webserver supports PATCH, the REST controller will use it.

WanWizard commented 11 years ago

Just did a small test to an application here using

curl -i -X PATCH http://fueltest.catwoman.exite.local

And that returns the data just fine. The log confirms it gets a PATCH request in:

INFO - 2013-08-09 12:34:41 --> Application "demo" is creating new "PATCH" Request for URI: /

(note that this is a Fuel v2 setup, but that does not make a difference for the processing of the request)

chrisveness commented 11 years ago

Ok, I see, so it does it already. I hadn’t appreciated that was what you were saying. I’ll update my API.

Perhaps the other methods could be added to the documentation to save others from confusion?

Thanks, Chris

From: Harro Verton Sent: Friday, August 09, 2013 11:15 AM To: fuel/core Cc: Chris Veness Subject: Re: [core] REST controller HTTP methods (#1499)

I get that, but that was not my point.

Point is that the REST controller doesn't do anything special with the method. It just fetches the HTTP_METHOD passed by the webserver, so if the webserver supports PATCH, the REST controller will use it.

— Reply to this email directly or view it on GitHub.

WanWizard commented 11 years ago

Done. https://github.com/fuel/docs/commit/c250da704a614659f5eeba2de88c20c91b22c02f