Does php mvc framework agavi use REST compliant CRUD?

The agavi framework uses a PUT request to create and POST to update information. Usually in REST it is used the other way around (often referring to POST, adding information, while PUT replaces the entire data record).

If I understand correctly, the important issue is that PUT must be idempotent, while POST does not have this requirement. So I figured out how the creation of a new record could be idempotent (i.e. a multiple request does not result in multiple creations of a record), in particular when normally the ORM uses the ID as the primary key and the ID of the new record will not be known to the client (since it is automatically created in the database), hence it cannot be part of the query. How agavi supports the idempotency requirement in light of this for a PUT request.

Thank.

+2


source to share


4 answers


PUT can be used to create or update complete records. POST is commonly used for partial updates and related operations, and to create a new post type on the server without specifying a resource URL (for example, POST to / articles / 23 / comments returns status 201 and location: / articles / 23 / comments / 283136 ). So in your case (with sequence / autoincrement id) you would use this approach.

However, HTML (and therefore web forms) is different. It only knows GET and POST, not DELETE and PUT. For delete and update operations, it overloads the POST method.



This is why Agavi displays POST for "write" and GET for "read" by default - this is the most common use case, and "read" and "write" are chosen because they are relatively neutral and also represent the security aspects of GET and POST in some sense. safety as in "GET can be called without side effects" and blah).

You can change the display of verbs for the AgaviWebRequest implementation in factories.xml; refer to the Agavi users mailing list or IRC channel if you need help (or ask here). Many people on the IRC channel are also very well versed in URL scheme design if you need further help building your API.

+5


source


Instead of thinking of it PUT

as creating, think of it as "giving up." You are putting the resource in a URI (i.e. you are sending the entire resource in a URI).

PUT http://example.com/articles/1

      



If you repeat this (send the same entire resource to the same URI), you get the same result, and you haven't changed the resource in that URI, making it idempotent.

If the agavi implementation PUT

is idempotent, then it implements correctly PUT

. Otherwise it is not.

+2


source


PUT can be used to create a resource, except if the resource already exists (or was already created by a previous PUT), it will simply update it. However, POST should not update resources if it is just CRUD. Note that HTTP verbs do not have a definite correspondence to certain actions, as they are much more useful than just CRUD.

Also note that this question has nothing to do with REST - just the correct use of HTTP. So please remove the REST tag.

0


source


I've had this problem before. This can be solved by modifying factories.xml

0


source







All Articles