Who: Alex Singer @alexjsinger
Date: August 1, 2016
Event: Girls Who Code Boston
This presentation covers the basics of what a REST API is, why and when it's used, and how to think about API design. It was delivered to ~20 students participating in Girls Who Code at the Boston Twitter office over the summer. The age ranges were between 15-16 years old.
12. Challenges
Systems don’t “speak the same language”
Don’t expose server code
Change server code without breaking
communications
Ensure communication is secure
18. Request - Method
A CRUD style verb to associate the endpoint with an action on the server
Method Description
GET Read resource data from the server
POST Create a resource on the server
PUT Update a resource on the server
DELETE Delete a resource from the server
19. Request - Method
A CRUD style verb to associate the endpoint with an action on the server
Method Description
GET Read resource data from the server
POST Create a resource on the server
PUT Update a resource on the server
DELETE Delete a resource from the server
20. Request - Method
A CRUD style verb to associate the endpoint with an action on the server
Method Description
GET Read resource data from the server
POST Create a resource on the server
PUT Update a resource on the server
DELETE Delete a resource from the server
21. Request - Method
A CRUD style verb to associate the endpoint with an action on the server
Method Description
GET Read resource data from the server
POST Create a resource on the server
PUT Update a resource on the server
DELETE Delete a resource from the server
22. Response - Data
Data returned by the server to the client after processing the request
The HTML content of a requested
web page
Examples:
JSON or XML of an API request
23. Response - Status Code
A numeric code to indicate the status of the request
24. Response - Status Code
A numeric code to indicate the status of the request
Common Codes:
Code Description
1xx Information i.e. 101 switching protocols
2xx Success i.e. 200 OK or 201 created
3xx Redirection i.e. 301 moved permanentely
4xx Client Error i.e. 401 unauthorized or 404 not found
5xx Server Error i.e. 500 internal server error
25. Putting it all together…
Requests use the URL, Method, Body and Headers to tell the server
what it wants to do.
GET https://api.twitter.com/1.1/statuses/user_timeline.json?
user_id=onedirection&screen_name=onedirection
Request:
Response:
Let’s take a look at the real data!
27. Think about features that API should expose on the server
Songzify
It should…
List all artists
List all songs by artist
List all songs
Allow an artist to be created
Allow an artist to be deleted
/artists
/songs/{artist_id}
/songs
/artists
/artists/{artist_id}
Endpoint
GET
GET
GET
POST
DELETE
Method
-
artist_id
-
artist_name
artist_id
Body
28. Dinner with an API
Exercise
Groups of 2
Think through a full dinner and
functionality a “Server” should
provide to satisfy the “Client”
Create a table showing the Endpoints,
Methods, and Body for each action
For each action, describe the expected
response from the server
30. API Docs
API docs outline requirements for requests and response
It’s a good idea to become familiar with their structure since most REST
APIs follow the same format
Examples:
https://dev.twitter.com/rest/public
https://developer.spotify.com/web-api/endpoint-reference/
https://www.instagram.com/developer/endpoints/