[FLOW3-general] Trying to REST ;)

Bastian Waidelich bastian at typo3.org
Thu Oct 27 13:04:56 CEST 2011


Bastian Waidelich wrote:

Hi Oliver,

> I'll provide a little sample later. Now busy with the release ;)

Ok, that was later later than I have planned..
But in return I can provide you with a fully fledged REST example that 
supports XML, JSON and non-Ajax-Fallbacks:
https://github.com/bwaidelich/REST-Test

Most things, should be rather self-explanatory, but there are at least 
two things worth mentioning:

1. The current FLOW3 request handling does not support requests of type 
PUT. Besides the merging of GET and POST arguments is done in a way that 
does not play very well with REST because a matched route part can't be 
overridden. E.g. if you PUT to the URI 
"http://localhost/products/product-1" the argument $product is already 
mapped (usually to the UUID of the product) and won't be merged with 
your PUT data.
I worked around this by providing a simple "RestRequestHandler" that is 
automatically used for POST, PUT & DELETE Web Requests that provide a 
Content-Type header (see 
https://github.com/bwaidelich/REST-Test/blob/master/Classes/RestRequestHandler.php#L51).

2. If you update a resource (PUT), you currently *have to* specify the 
__identity property. Otherwise the property mapper doesn't recognize the 
entity and the Repository::update() call will fail.

A sample PUT request could look like this:
<root>
   <product>
     <__identity>0b0a86a1-08aa-4d11-a21c-01b459fd3747</__identity>
     <name>Modified product name</name>
     <price>123.45</price>
   </product>
</root>

(set the *Accept* and *Content-Type* headers to "application/xml"!)

The JSON version would look like:
{
   "product":
     {
       "__identity": "c95af617-50eb-497a-aed7-08b9d8139c83",
       "name": "JSON Modified2",
       "price": "543.21"
     }
}
(*Accept* and *Content-Type* headers => "application/json"!)


Let me know, if that works for you.
Bastian


More information about the FLOW3-general mailing list