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!
Formatting output for rest api
Moderator: General Moderators
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Re: Formatting output for rest api
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.
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
Awesome, thank you! using json_encode then json_decode on the other end worked perfect!
Re: Formatting output for rest api
Serialize is not recommended as well, because it would blindly create objects of available classes if they are specified in the serialized data.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.
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Re: Formatting output for rest api
Good point.Weirdan wrote:Serialize is not recommended as well, because it would blindly create objects of available classes if they are specified in the serialized data.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.