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

_______________________________________________
users mailing list
[email protected]
http://lists.agavi.org/mailman/listinfo/users

Reply via email to