DaveHolt DaveHolt - 10 months ago 48
JSON Question

JSON file accepting POST data?

I have seen many APIs set up where the user would send POST data to a JSON file. Take the Mandrill API for example:


How does JSON interpret the request data, connect to a database, etc if it isn't a server-side language?

Answer Source

The api is not really sending the post request to the json file, or to any file for that matter. It's just their api endpoint naming convention. The /api/1.0/messages/send.json route is intercepted by the server app which process the post data.

If you check https://mandrillapp.com/api/docs/index.JSON.html the extension of the api route sets the output format.

So you can do:

  • /api/1.0/messages/send.json
  • /api/1.0/messages/send.xml
  • /api/1.0/messages/send.yaml
  • /api/1.0/messages/send.php