What does a JSON-encoded request look like?

I am creating an API using PHP.

What do I need to do to recognize the JSON encoded request?

Does it have a specific type of request?

How do I get just the request body so that I can json_decode?

+2


a source to share


2 answers


RFC 4627 recommends a mime / json type application. You can read the request data with php: // input .



+1


a source


The mime type for json is application/json

, but I doubt it hasn't had time to add that to the answers yet.

The easiest way to define a json response is that it will most likely be wrapped in curly braces and have colons after each member. But this is still not the right way to find out about this json.



The easiest way to test it with PHP is to try json_decode if it throws an error, either it's not json, or malformed json and so you still won't be able to use it.

0


a source







All Articles