APIs in Plain English
Using an API is a little bit like ordering food in a restaurant. You ask the waiter what you want and he delivers it to you, you don'#t need to know how it's made, where it's made and so on. An API provide will supply the documentation telling you what data is available and how you can request it.
The request and response Cycle
The client (that is, the browser) sends a request to the server using an HTTP verb. In mmost cases, particularly for this course, that will be GET. The most common verbs are (I'm not sure if there are others or if this list is actually complete
•GET - the client requests data which the server sends back (all being well). •POST - the client sends some data to the server to update the data held there. •PUT - similar to POST, except that we are sending new data to the server (essentially, this is an insert command). •DELETE - deletes some data that is currently on the server.
The cycle is
•request - this is sent to the server, in the form of a GET request, for example. • response - the server will send the data back assuming that the request is properly formed and there are no other issues (such as authorization).
What is JSON?
There are two main formats in which data is usually returned to you, XML and JSON. XML used to be the most common but JSON is the dominant format now.
JSON - JavaScript Object Notation
The data is formatted like a JavaScript option which makes it easy to use in a web application.
JSON data is essentially a collection of key value pairs enclosed in curly braces. You could think of the key as being like a property so it might be something like name. The value is the value! That might be something like Philip. Both the keys and values are wrapped in double quotes and they are separated by a colon, so it will look something like this. The key-value pairs are separated with commas.
{ "name" : "Philip", "name" : "Andrew" }
In general, the data will be a little bit more complex than this and it can often look as though it represents database records, as in the following image.

Parsing Data
When the data is returned, it is on the form of a text string which we can then convert to JSON using a JavaScript method, JSON.parse. This method takes one argument and that is the response string. The converstion outputs an object which you can use like any other object in JavaScript. Bear in mind that the object is actually an array of objects so you will use JavaScripts syntax for handling arrays to access the data.