[Agavi-Users] questions about REST

4 views
Skip to first unread message

Simon Cornelius P Umacob

unread,
Mar 11, 2008, 2:06:55 AM3/11/08
to us...@lists.agavi.org
Huomenta!

I have a couple of questions about Agavi's REST support:

- With HTTP POST, data is sent using variable1=value1&variable2=value2
format and is read in Agavi using getParameter(). However, if I send
the data using HTTP PUT, the data is treated as an uploaded file and
cannot be accessed via getParamaeter(). Is there an easy way to
access the variables without parsing the uploaded file?

- Agavi "maps" executeCreate() with HTTP PUT and executeWrite() with
HTTP POST. If I use these functions in a REST context, it seems that
it makes more sense if they are mapped the other way around. Although
I understand that there is no one way to implement REST, there seems
to be a general agreement that update operations should be mapped to
HTTP PUT while create operations should be mapped to HTTP POST. I
have no qualms with the function names, except that I'll soon be
sharing my code with other devs who may have qualms about it. Is
there a way to configure our own mapping?

Thanks!


[ simon.cpu ]

_______________________________________________
users mailing list
us...@lists.agavi.org
http://lists.agavi.org/mailman/listinfo/users

David Zülke

unread,
Mar 12, 2008, 9:28:25 AM3/12/08
to Agavi Users Mailing List
Am 11.03.2008 um 07:06 schrieb Simon Cornelius P Umacob:

> Huomenta!

Hi Simon,


> I have a couple of questions about Agavi's REST support:
>
> - With HTTP POST, data is sent using variable1=value1&variable2=value2
> format and is read in Agavi using getParameter(). However, if I send
> the data using HTTP PUT, the data is treated as an uploaded file and
> cannot be accessed via getParamaeter(). Is there an easy way to
> access the variables without parsing the uploaded file?

A good question. We should maybe consider adding an option that maps
uploaded content to parameters if the Content-Type is application/x-
www-form-urlencoded.

For now, subclass AgaviWebRequest and overwrite initialize():

public function initialize(AgaviContext $context, array $parameters =
array()) {
parent::initialize($context, $parameters);

$rd = $this->getRequestData();
if($this->getMethod() == 'create' && $rd->getHeader('Content-Type')
== 'application/x-www-form-urlencoded') {
$data = $rd->getFile($this->getParameter('http_put_file_name'));
// decode data and set parameters
$rd->removeFile($this->getParameter('http_put_file_name'));
}
}

Note that right now, custom HTTP method mappings are not set back as
parameters on the request object, so you cannot read them without code
duplication. See ticket http://trac.agavi.org/ticket/724 (and also http://trac.agavi.org/ticket/725)
. I'll fix those tonight.


> - Agavi "maps" executeCreate() with HTTP PUT and executeWrite() with
> HTTP POST. If I use these functions in a REST context, it seems that
> it makes more sense if they are mapped the other way around. Although
> I understand that there is no one way to implement REST, there seems
> to be a general agreement that update operations should be mapped to
> HTTP PUT while create operations should be mapped to HTTP POST. I
> have no qualms with the function names, except that I'll soon be
> sharing my code with other devs who may have qualms about it. Is
> there a way to configure our own mapping?

Absolutely:

<parameter name="method_names">
<parameter name="PUT">write</parameter>
<parameter name="POST">create</parameter>
</parameter>

for the <request> in factories.xml.

Hope that helps,


David

David Zülke

unread,
Feb 1, 2009, 1:59:24 AM2/1/09
to Agavi Users Mailing List
On 12.03.2008, at 14:28, David Zülke wrote:

> Am 11.03.2008 um 07:06 schrieb Simon Cornelius P Umacob:
>
>> I have a couple of questions about Agavi's REST support:
>>
>> - With HTTP POST, data is sent using
>> variable1=value1&variable2=value2
>> format and is read in Agavi using getParameter(). However, if I send
>> the data using HTTP PUT, the data is treated as an uploaded file and
>> cannot be accessed via getParamaeter(). Is there an easy way to
>> access the variables without parsing the uploaded file?
>
> A good question. We should maybe consider adding an option that maps
> uploaded content to parameters if the Content-Type is application/x-
> www-form-urlencoded.

FYI, this is now implemented in 1.0, see http://trac.agavi.org/ticket/1016

- David

Reply all
Reply to author
Forward
0 new messages