rest apis, girls who code

Post on 16-Apr-2017

151 Views

Category:

Technology

1 Downloads

Preview:

Click to see full reader

TRANSCRIPT

REST APIs@alexjsingerAugust 1st, 2016

What an API is How an API works

1 3Where and why an API is used

2

GoalsTo understand…

#Servers

Servers

A computer on a network

Run software for specific tasks

Specialized servers for things like web pages, emails, and databases

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

communicate each other

Dash Button

Client-Server Model

Client-Server Model

Client Server

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

Challenges

Systems don’t “speak the same language”

Don’t expose server code

Change server code without breaking communications

Ensure communication is secure

#RESTAPIFTW

presentationalRerogrammingS

T ransfer

API

pplication

nterface

tate

Request / response communicationHTTP

Request

https://www.twitter.com/onedirection

1. URL

2. Method

3. Header information

4. Body

Request / response communicationHTTP

Request

https://www.twitter.com/onedirection

Response

1. Data

2. Header information

3. Status 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

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

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

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

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

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

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

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

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!

#DesignAPI

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

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

#LearnMore

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/

REST APIs@alexjsinger

What an API is How an API works

1 3Where and why an API is used

2

GoalsTo understand…

#ThankYou!

top related