Getting to grips with APIs
Most modern systems communicate between client and server using an API. This is a list of agreed requests and responses between the two components. This sounds complicated, but it is quite simple. If we put the https://random.dog/woof.json URL into a browser, we get back the URL of a random dog, from a database of dog images. We also get the size of the file, in bytes.
Our browser is the client, and it sends an HTTP GET
request to an API endpoint (/woof.json
) on the server at the https://random.dog URL. In response to this request, the server sends a message containing a URL back to us, in the first frame in the following figure. We can look at the headers in the second frame below and see that the content type is JSON. We can then display the URL in a browser to see a picture of an adorable dog, below. Note that Iām using Firefox, here, which allows us to see the headers as well as the content. Other browsers will only show the JSON content.