[FLOW3-general] Trying to REST ;)
Oliver Wand
wand at itaw.de
Wed Nov 9 19:49:49 CET 2011
Hi Bastian,
first of all thanks a ton for providing the example.
I adapted this to my package but currently having a problem with the output.
When setting the request header to XML
AbstractRestController::detectFormat does recognize xml as expected but
still FLUID wants to render the .html template instead of .xml
Looking at getTemplatePathAndFilename FLUID obviously only checks the
action name and looks for an .html template but doesn't switch to xml then?
Any hints on this?
Thanks,
Oliver
Am 27.10.11 13:04, schrieb Bastian Waidelich:
> 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