Formatting output for rest api

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
GeXus
Forum Regular
Posts: 631
Joined: Sat Mar 11, 2006 8:59 am

Formatting output for rest api

Post 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!
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: Formatting output for rest api

Post 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.
GeXus
Forum Regular
Posts: 631
Joined: Sat Mar 11, 2006 8:59 am

Re: Formatting output for rest api

Post by GeXus »

Awesome, thank you! using json_encode then json_decode on the other end worked perfect!
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: Formatting output for rest api

Post 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.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: Formatting output for rest api

Post 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.
Post Reply