There are a few core concepts you need to understand in making API requests. By the end of this morning's workshop you should have a mental model of
- The request-response pattern
- HTTP methods and status codes
- XMLHttpRequests
- The meaning of 'asynchronous' in the context of API requests
We will be working in pairs this morning, so figure out who you will be working with. The plan is that each pair should actively read and discuss each topic and try to make sure they both understand the material. How you do this is up to you - you may like to take some time to read separately and then discuss the material between you.
For each topic we will give you 10-15 minutes of reading and discussion time in your pairs, and then we will spend 10-15 minutes asking you questions about the material, and we will pick on pairs at random to answer the questions or explain aspects of the material. We will also attempt to answer any questions you may have for us.
After that we will work on some examples in which we will make API requests.
Start by adding JSONView a Chrome extension that makes JSON data much more readable in Chrome
Read each section and be ready to answer questions
-
Example one: fix a broken API request
- You will need to clone the repository and work on the code locally
- If you have ssh keys for github:
git clone [email protected]:lucymonie/api-workshop.git
- Otherwise, use:
git clone https://github.com/lucymonie/api-workshop.git
- Open index.html in the browser and you will see that the API request is not working
- Open main.js and look for what's broken or missing in the code. If you're confused, check it line-by-line against the description of XHR in this file
-
Example two: write an XHR from scratch
- Click on the link and clone the repo to your local machine
- Follow the instructions in the readme
- If you're at all hazy about how the internet works, watch this excellent explanation
- If you're interested in how domains are translated into ip addresses, watch this amusing discussion of DNS
- REST (Representational State Transfer) is a best practice standard for web interactions. This video gives some background about REST.