Should Rest API accept POST array or JSON string?

Viewed 18224

I've been reading a few REST tutorials and some of them says that in order to send data to a rest API you should send post data as an array, which is something like this:

$data = array('foo' => 'bar');
$rest->post($data);

Then there are others that say you should send JSON data like this:

$data = array('foo' => 'bar');
$data = json_encode($data);
$rest->post($data);

Not sure if there's a standard way of doing this or either if is fine but what is generally recommended when designing API's?

EDIT: There seems to be confusion. To clarify I agree JSON should be used for client consumption but this question is about SERVER consumption. Meaning should the SERVER accept JSON or POST data from its clients?

7 Answers
Related