Luracast / Restler

Simple and effective multi-format Web API Server to host your PHP API as Pragmatic REST and/or RESTful API
http://luracast.com/products/restler/
GNU Lesser General Public License v2.1
1.36k stars 316 forks source link

multi format issue #18

Closed ahmadfathihadi closed 12 years ago

ahmadfathihadi commented 12 years ago

Hi Arul

when i call http://localhost/api/v1/index.php/text/iseng.xml?api_key=ok&text=ok it will return an xml format

but why when i call http://localhost/api/v1/index.php/text/iseng.xml/api_key=ok/text=ok return is in Json Format ?

It's same if i call http://localhost/api/v1/index.php/text/iseng.xml/ok/ok

the return is in json format

I also find that that your xml format have an issue when handle an urlencode

http://localhost/api/v1/index.php/text/iseng.xml?api_key=ok&text=budi+%26+anto

won't give any result. but

http://localhost/api/v1/index.php/text/iseng.json?api_key=ok&text=budi+%26+anto

is working fine

Thanks

Luracast commented 12 years ago

Current version of Restler (v2.07) supports the extensions only at the end of the URL.

For example

http://localhost/api/v1/index.php/text/iseng/ok/ok.xml

Will work

Since you asked, I will release an update, where the scenarios you described will work as well :)

ahmadfathihadi commented 12 years ago

unfortunately I'm still get the same issue :(

http://localhost/api/v1/index.php/text/iseng/ok/budi+%26+anto.json

will work

http://localhost/api/v1/index.php/text/iseng/ok/budi+%26+anto.xml

won't work

Thanks :)

ahmadfathihadi commented 12 years ago

i got the problem. is in your xmlformat.php

i do some following modification :

<?php
public function encode($data, $human_readable=true){
    //return $this->toXML( object_to_array($data, false), XmlFormat::$root_name, $human_readable);
    if(is_array($data)){
        $xml = new SimpleXMLElement('<root/>');
        array_walk_recursive($data, array ($xml, 'addChild'));
        return $xml->asXML();
    } else {
        return "<result>$data</result>";
    }
}

hope this can help :)

Luracast commented 12 years ago

I understood the new problem and found the solution too! for better clarity I will file an issue on that and close it with the next update :)