REST APIs, Girls Who Code
-
Upload
twitter-developers -
Category
Technology
-
view
149 -
download
1
Transcript of REST APIs, Girls Who Code
![Page 1: REST APIs, Girls Who Code](https://reader033.fdocuments.in/reader033/viewer/2022052313/587085d91a28ab57368b7923/html5/thumbnails/1.jpg)
REST APIs@alexjsingerAugust 1st, 2016
![Page 2: REST APIs, Girls Who Code](https://reader033.fdocuments.in/reader033/viewer/2022052313/587085d91a28ab57368b7923/html5/thumbnails/2.jpg)
What an API is How an API works
1 3Where and why an API is used
2
GoalsTo understand…
![Page 3: REST APIs, Girls Who Code](https://reader033.fdocuments.in/reader033/viewer/2022052313/587085d91a28ab57368b7923/html5/thumbnails/3.jpg)
#Servers
![Page 4: REST APIs, Girls Who Code](https://reader033.fdocuments.in/reader033/viewer/2022052313/587085d91a28ab57368b7923/html5/thumbnails/4.jpg)
Servers
A computer on a network
Run software for specific tasks
Specialized servers for things like web pages, emails, and databases
![Page 5: REST APIs, Girls Who Code](https://reader033.fdocuments.in/reader033/viewer/2022052313/587085d91a28ab57368b7923/html5/thumbnails/5.jpg)
Networked systems need a way to communicate with each other Networked systems
communicate each other
![Page 6: REST APIs, Girls Who Code](https://reader033.fdocuments.in/reader033/viewer/2022052313/587085d91a28ab57368b7923/html5/thumbnails/6.jpg)
![Page 7: REST APIs, Girls Who Code](https://reader033.fdocuments.in/reader033/viewer/2022052313/587085d91a28ab57368b7923/html5/thumbnails/7.jpg)
![Page 8: REST APIs, Girls Who Code](https://reader033.fdocuments.in/reader033/viewer/2022052313/587085d91a28ab57368b7923/html5/thumbnails/8.jpg)
![Page 9: REST APIs, Girls Who Code](https://reader033.fdocuments.in/reader033/viewer/2022052313/587085d91a28ab57368b7923/html5/thumbnails/9.jpg)
Dash Button
![Page 10: REST APIs, Girls Who Code](https://reader033.fdocuments.in/reader033/viewer/2022052313/587085d91a28ab57368b7923/html5/thumbnails/10.jpg)
Client-Server Model
![Page 11: REST APIs, Girls Who Code](https://reader033.fdocuments.in/reader033/viewer/2022052313/587085d91a28ab57368b7923/html5/thumbnails/11.jpg)
Client-Server Model
Client Server
(laptop, phone, physical device) (…just a computer)
![Page 12: REST APIs, Girls Who Code](https://reader033.fdocuments.in/reader033/viewer/2022052313/587085d91a28ab57368b7923/html5/thumbnails/12.jpg)
Challenges
Systems don’t “speak the same language”
Don’t expose server code
Change server code without breaking communications
Ensure communication is secure
![Page 13: REST APIs, Girls Who Code](https://reader033.fdocuments.in/reader033/viewer/2022052313/587085d91a28ab57368b7923/html5/thumbnails/13.jpg)
#RESTAPIFTW
![Page 14: REST APIs, Girls Who Code](https://reader033.fdocuments.in/reader033/viewer/2022052313/587085d91a28ab57368b7923/html5/thumbnails/14.jpg)
presentationalRerogrammingS
T ransfer
API
pplication
nterface
tate
![Page 15: REST APIs, Girls Who Code](https://reader033.fdocuments.in/reader033/viewer/2022052313/587085d91a28ab57368b7923/html5/thumbnails/15.jpg)
Request / response communicationHTTP
Request
https://www.twitter.com/onedirection
1. URL
2. Method
3. Header information
4. Body
![Page 16: REST APIs, Girls Who Code](https://reader033.fdocuments.in/reader033/viewer/2022052313/587085d91a28ab57368b7923/html5/thumbnails/16.jpg)
Request / response communicationHTTP
Request
https://www.twitter.com/onedirection
Response
1. Data
2. Header information
3. Status Code
![Page 17: REST APIs, Girls Who Code](https://reader033.fdocuments.in/reader033/viewer/2022052313/587085d91a28ab57368b7923/html5/thumbnails/17.jpg)
http://www.songzify.com/songssongssongzify.com
Request - URL (endpoint)Unique address for a “thing” or resource on a server
Examples:
Domain Path
http://www.songzify.com/artists
![Page 18: REST APIs, Girls Who Code](https://reader033.fdocuments.in/reader033/viewer/2022052313/587085d91a28ab57368b7923/html5/thumbnails/18.jpg)
Request - MethodA 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
![Page 19: REST APIs, Girls Who Code](https://reader033.fdocuments.in/reader033/viewer/2022052313/587085d91a28ab57368b7923/html5/thumbnails/19.jpg)
Request - MethodA 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
![Page 20: REST APIs, Girls Who Code](https://reader033.fdocuments.in/reader033/viewer/2022052313/587085d91a28ab57368b7923/html5/thumbnails/20.jpg)
Request - MethodA 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
![Page 21: REST APIs, Girls Who Code](https://reader033.fdocuments.in/reader033/viewer/2022052313/587085d91a28ab57368b7923/html5/thumbnails/21.jpg)
Request - MethodA 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
![Page 22: REST APIs, Girls Who Code](https://reader033.fdocuments.in/reader033/viewer/2022052313/587085d91a28ab57368b7923/html5/thumbnails/22.jpg)
Response - DataData 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
![Page 23: REST APIs, Girls Who Code](https://reader033.fdocuments.in/reader033/viewer/2022052313/587085d91a28ab57368b7923/html5/thumbnails/23.jpg)
Response - Status CodeA numeric code to indicate the status of the request
![Page 24: REST APIs, Girls Who Code](https://reader033.fdocuments.in/reader033/viewer/2022052313/587085d91a28ab57368b7923/html5/thumbnails/24.jpg)
Response - Status CodeA 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
![Page 25: REST APIs, Girls Who Code](https://reader033.fdocuments.in/reader033/viewer/2022052313/587085d91a28ab57368b7923/html5/thumbnails/25.jpg)
Putting it all together…Requests use the URL, Method, Body and Headers to tell the serverwhat 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!
![Page 26: REST APIs, Girls Who Code](https://reader033.fdocuments.in/reader033/viewer/2022052313/587085d91a28ab57368b7923/html5/thumbnails/26.jpg)
#DesignAPI
![Page 27: REST APIs, Girls Who Code](https://reader033.fdocuments.in/reader033/viewer/2022052313/587085d91a28ab57368b7923/html5/thumbnails/27.jpg)
Think about features that API should expose on the serverSongzify
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
![Page 28: REST APIs, Girls Who Code](https://reader033.fdocuments.in/reader033/viewer/2022052313/587085d91a28ab57368b7923/html5/thumbnails/28.jpg)
Dinner with an APIExercise
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
![Page 29: REST APIs, Girls Who Code](https://reader033.fdocuments.in/reader033/viewer/2022052313/587085d91a28ab57368b7923/html5/thumbnails/29.jpg)
#LearnMore
![Page 30: REST APIs, Girls Who Code](https://reader033.fdocuments.in/reader033/viewer/2022052313/587085d91a28ab57368b7923/html5/thumbnails/30.jpg)
API DocsAPI docs outline requirements for requests and response
It’s a good idea to become familiar with their structure since most RESTAPIs follow the same format
Examples:
https://dev.twitter.com/rest/publichttps://developer.spotify.com/web-api/endpoint-reference/https://www.instagram.com/developer/endpoints/
![Page 31: REST APIs, Girls Who Code](https://reader033.fdocuments.in/reader033/viewer/2022052313/587085d91a28ab57368b7923/html5/thumbnails/31.jpg)
REST APIs@alexjsinger
![Page 32: REST APIs, Girls Who Code](https://reader033.fdocuments.in/reader033/viewer/2022052313/587085d91a28ab57368b7923/html5/thumbnails/32.jpg)
What an API is How an API works
1 3Where and why an API is used
2
GoalsTo understand…
![Page 33: REST APIs, Girls Who Code](https://reader033.fdocuments.in/reader033/viewer/2022052313/587085d91a28ab57368b7923/html5/thumbnails/33.jpg)
#ThankYou!