Welcome Guest, Not a member yet? Register   Sign In
Phil Sturgeon's REST Server and Arrays
#1

[eluser]jakelehner[/eluser]
Does anyone have any tips on passing in XML to Phil's REST server so it will be interpreted as an array during an XML POST?

I use this library fairly extensively and it's been great so far. I can't seem to figure out how to pass in an array using a Chrome-based REST client. If I'm using Phil's CI REST client, it's fine. But the issue comes in when using a stand-alone rest client so I can easily change the request XML during testing.

Take the following hypothetical example of adding tags to a document. Not the best example, but it works for this purpose.

The goal here is to have $this->post('tags') to be an array once the request is received.

The following does not work:
Code:
<xml>
    <docID>123</docID>
    &lt;title&gt;something awesome&lt;/title&gt;
    <tags>
        <tag>one</tag>
        <tag>two</tag>
        <tag>three</tag>
    </tags>
&lt;/xml&gt;

That results in:

Code:
Array
(
    [docID] => 123
    [title] => something awesome
    [tags] => Array
        (
            [tag] => Array
                (
                    [0] => one
                    [1] => two
                    [2] => three
                )

        )

)

Then the following throws a parse error:

Code:
&lt;xml&gt;
    <docID>123</docID>
    &lt;title&gt;something awesome&lt;/title&gt;
    <tags>
        <0>one</0>
        <1>two</1>
        <2>three</2>
    </tags>
&lt;/xml&gt;

This next one works, but seems messy and counter intuitive:

Code:
&lt;xml&gt;
    <docID>123</docID>
    &lt;title&gt;something awesome&lt;/title&gt;
    <tags>one</tags>
    <tags>two</tags>
    <tags>three</tags>
&lt;/xml&gt;

That results in:

Quote:Array
(
[docID] => 123
[title] => something awesome
[tags] => Array
(
[0] => one
[1] => two
[2] => three
)

)


Any suggestions?




Theme © iAndrew 2016 - Forum software by © MyBB