Page 1 of 1
Formatting output for rest api
Posted: Sat Aug 14, 2010 2:12 pm
by GeXus
I'm building a very very very simple api... Basically one URL that accepts one parameter and returns data.
I'd like to format that data, so when received on the other end, it's an array... is that possible? I'm printing it out as an array now but it doesn't work...
Any help would be great! thanks!
Re: Formatting output for rest api
Posted: Sat Aug 14, 2010 2:30 pm
by John Cartwright
Generally you will convert your array to a transportable format. I.e., json, serialize() + base64_encode(), xml.
Although, you could do a var_export() and eval() on the recipient server, but that is certainly not recommended.
Re: Formatting output for rest api
Posted: Sat Aug 14, 2010 2:43 pm
by GeXus
Awesome, thank you! using json_encode then json_decode on the other end worked perfect!
Re: Formatting output for rest api
Posted: Sat Aug 14, 2010 6:50 pm
by Weirdan
John Cartwright wrote:Generally you will convert your array to a transportable format. I.e., json, serialize() + base64_encode(), xml.
Although, you could do a var_export() and eval() on the recipient server, but that is certainly not recommended.
Serialize is not recommended as well, because it would blindly create objects of available classes if they are specified in the serialized data.
Re: Formatting output for rest api
Posted: Sat Aug 14, 2010 7:21 pm
by John Cartwright
Weirdan wrote:John Cartwright wrote:Generally you will convert your array to a transportable format. I.e., json, serialize() + base64_encode(), xml.
Although, you could do a var_export() and eval() on the recipient server, but that is certainly not recommended.
Serialize is not recommended as well, because it would blindly create objects of available classes if they are specified in the serialized data.
Good point.