Application Programming Interface using JSON

API Code

I was asked to develop an Application Programming Interface (API) that would allow a remote user to send a request to a remote server, which then performs some actions or lookups and returns an answer.

The simplest way to do this was to use JavaScript Object Notation, or JSON.

What the local site does is send a JSON request using JavaScript to the API. This uses a PHP script to interpret the request, perform security validations and send back the answer. The local device therefore needs to be able to interpret the answer.

Examples are best in this situation: UPS Runtime API. This is entirely in html and JavaScript. TBH jQuery is probably a better choice but just in case there were issues here the example is pure JS.