rest apis, girls who code

33
REST APIs @alexjsinger August 1st, 2016

Upload: twitter-developers

Post on 16-Apr-2017

151 views

Category:

Technology


1 download

TRANSCRIPT

Page 1: REST APIs, Girls Who Code

REST APIs@alexjsingerAugust 1st, 2016

Page 2: REST APIs, Girls Who Code

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

#Servers

Page 4: REST APIs, Girls Who Code

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

Networked systems need a way to communicate with each other Networked systems

communicate each other

Page 6: REST APIs, Girls Who Code
Page 7: REST APIs, Girls Who Code
Page 8: REST APIs, Girls Who Code
Page 9: REST APIs, Girls Who Code

Dash Button

Page 10: REST APIs, Girls Who Code

Client-Server Model

Page 11: REST APIs, Girls Who Code

Client-Server Model

Client Server

(laptop, phone, physical device) (…just a computer)

Page 12: REST APIs, Girls Who Code

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

#RESTAPIFTW

Page 14: REST APIs, Girls Who Code

presentationalRerogrammingS

T ransfer

API

pplication

nterface

tate

Page 15: REST APIs, Girls Who Code

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

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

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

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

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

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

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

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

Response - Status CodeA numeric code to indicate the status of the request

Page 24: REST APIs, Girls Who Code

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

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

#DesignAPI

Page 27: REST APIs, Girls Who Code

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

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

#LearnMore

Page 30: REST APIs, Girls Who Code

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

REST APIs@alexjsinger

Page 32: REST APIs, Girls Who Code

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

#ThankYou!