58
STX NEXT talented developers | flexible teams | agile experts RESTFUL API BEST PRACTICES By Malwina Nowakowska

RESTFUL API - EuroPython...RESTful APIs Web service APIs that adhere to the REST architectural constraints are called RESTful APIs Richardson REST Maturity Model Resources /tickets

  • Upload
    others

  • View
    15

  • Download
    0

Embed Size (px)

Citation preview

Page 1: RESTFUL API - EuroPython...RESTful APIs Web service APIs that adhere to the REST architectural constraints are called RESTful APIs Richardson REST Maturity Model Resources /tickets

STX NEXT

talented developers | flexible teams | agile experts

RESTFUL APIBEST PRACTICES

By Malwina Nowakowska

Page 2: RESTFUL API - EuroPython...RESTful APIs Web service APIs that adhere to the REST architectural constraints are called RESTful APIs Richardson REST Maturity Model Resources /tickets

Malwina Nowakowska

Developer

STX Next

Love Python

Page 3: RESTFUL API - EuroPython...RESTful APIs Web service APIs that adhere to the REST architectural constraints are called RESTful APIs Richardson REST Maturity Model Resources /tickets
Page 4: RESTFUL API - EuroPython...RESTful APIs Web service APIs that adhere to the REST architectural constraints are called RESTful APIs Richardson REST Maturity Model Resources /tickets
Page 5: RESTFUL API - EuroPython...RESTful APIs Web service APIs that adhere to the REST architectural constraints are called RESTful APIs Richardson REST Maturity Model Resources /tickets

API

API

API

API

API

APIAPI

API

Page 6: RESTFUL API - EuroPython...RESTful APIs Web service APIs that adhere to the REST architectural constraints are called RESTful APIs Richardson REST Maturity Model Resources /tickets
Page 7: RESTFUL API - EuroPython...RESTful APIs Web service APIs that adhere to the REST architectural constraints are called RESTful APIs Richardson REST Maturity Model Resources /tickets
Page 8: RESTFUL API - EuroPython...RESTful APIs Web service APIs that adhere to the REST architectural constraints are called RESTful APIs Richardson REST Maturity Model Resources /tickets
Page 9: RESTFUL API - EuroPython...RESTful APIs Web service APIs that adhere to the REST architectural constraints are called RESTful APIs Richardson REST Maturity Model Resources /tickets
Page 10: RESTFUL API - EuroPython...RESTful APIs Web service APIs that adhere to the REST architectural constraints are called RESTful APIs Richardson REST Maturity Model Resources /tickets
Page 11: RESTFUL API - EuroPython...RESTful APIs Web service APIs that adhere to the REST architectural constraints are called RESTful APIs Richardson REST Maturity Model Resources /tickets
Page 12: RESTFUL API - EuroPython...RESTful APIs Web service APIs that adhere to the REST architectural constraints are called RESTful APIs Richardson REST Maturity Model Resources /tickets
Page 13: RESTFUL API - EuroPython...RESTful APIs Web service APIs that adhere to the REST architectural constraints are called RESTful APIs Richardson REST Maturity Model Resources /tickets
Page 14: RESTFUL API - EuroPython...RESTful APIs Web service APIs that adhere to the REST architectural constraints are called RESTful APIs Richardson REST Maturity Model Resources /tickets

Special demo event

Page 15: RESTFUL API - EuroPython...RESTful APIs Web service APIs that adhere to the REST architectural constraints are called RESTful APIs Richardson REST Maturity Model Resources /tickets
Page 16: RESTFUL API - EuroPython...RESTful APIs Web service APIs that adhere to the REST architectural constraints are called RESTful APIs Richardson REST Maturity Model Resources /tickets
Page 17: RESTFUL API - EuroPython...RESTful APIs Web service APIs that adhere to the REST architectural constraints are called RESTful APIs Richardson REST Maturity Model Resources /tickets
Page 18: RESTFUL API - EuroPython...RESTful APIs Web service APIs that adhere to the REST architectural constraints are called RESTful APIs Richardson REST Maturity Model Resources /tickets

RESTful API

Page 19: RESTFUL API - EuroPython...RESTful APIs Web service APIs that adhere to the REST architectural constraints are called RESTful APIs Richardson REST Maturity Model Resources /tickets

„Representational State Transfer (REST) is a

style of software architecture for distributed

hypermedia systems such as the World Wide

Web”

Page 20: RESTFUL API - EuroPython...RESTful APIs Web service APIs that adhere to the REST architectural constraints are called RESTful APIs Richardson REST Maturity Model Resources /tickets

Architectural constraints

Client-Server

Stateless

Cacheable

Uniform Interface

Layered System

Code on Demand (optional)

Page 21: RESTFUL API - EuroPython...RESTful APIs Web service APIs that adhere to the REST architectural constraints are called RESTful APIs Richardson REST Maturity Model Resources /tickets

Client-Server

Page 22: RESTFUL API - EuroPython...RESTful APIs Web service APIs that adhere to the REST architectural constraints are called RESTful APIs Richardson REST Maturity Model Resources /tickets

Stateless

Page 23: RESTFUL API - EuroPython...RESTful APIs Web service APIs that adhere to the REST architectural constraints are called RESTful APIs Richardson REST Maturity Model Resources /tickets

Cacheable

Page 24: RESTFUL API - EuroPython...RESTful APIs Web service APIs that adhere to the REST architectural constraints are called RESTful APIs Richardson REST Maturity Model Resources /tickets

Uniform Interface 1) Identifying the resource

2) Resource representation

3) Self-descriptive messages

4) Hypermedia as the engine of application state

Page 25: RESTFUL API - EuroPython...RESTful APIs Web service APIs that adhere to the REST architectural constraints are called RESTful APIs Richardson REST Maturity Model Resources /tickets

Layered System

Page 26: RESTFUL API - EuroPython...RESTful APIs Web service APIs that adhere to the REST architectural constraints are called RESTful APIs Richardson REST Maturity Model Resources /tickets

Code on Demand (optional)

Page 27: RESTFUL API - EuroPython...RESTful APIs Web service APIs that adhere to the REST architectural constraints are called RESTful APIs Richardson REST Maturity Model Resources /tickets

Architectural properties

Performance

Scalability

Simplicity of interfaces

Modifiability of components to meet changing needs (even while the application is running)

Visibility of communication between components by service agents

Portability of components by moving program code with the data

Reliability is the resistance to failure at the system level in the presence of failures within

components, connectors, or data

Page 28: RESTFUL API - EuroPython...RESTful APIs Web service APIs that adhere to the REST architectural constraints are called RESTful APIs Richardson REST Maturity Model Resources /tickets

RESTful APIs

Web service APIs that adhere to the REST architectural

constraints are called RESTful APIs

Page 29: RESTFUL API - EuroPython...RESTful APIs Web service APIs that adhere to the REST architectural constraints are called RESTful APIs Richardson REST Maturity Model Resources /tickets

Richardson REST Maturity Model

Page 30: RESTFUL API - EuroPython...RESTful APIs Web service APIs that adhere to the REST architectural constraints are called RESTful APIs Richardson REST Maturity Model Resources /tickets

Resources

Page 31: RESTFUL API - EuroPython...RESTful APIs Web service APIs that adhere to the REST architectural constraints are called RESTful APIs Richardson REST Maturity Model Resources /tickets

/tickets

/events

/users

/baskets

/event_venues

Page 32: RESTFUL API - EuroPython...RESTful APIs Web service APIs that adhere to the REST architectural constraints are called RESTful APIs Richardson REST Maturity Model Resources /tickets

/tickets

/events

/users

/baskets

/event_venues

Nouns

Page 33: RESTFUL API - EuroPython...RESTful APIs Web service APIs that adhere to the REST architectural constraints are called RESTful APIs Richardson REST Maturity Model Resources /tickets

/tickets

/events

/users

/baskets

/event_venues

Nouns

Plural

Page 34: RESTFUL API - EuroPython...RESTful APIs Web service APIs that adhere to the REST architectural constraints are called RESTful APIs Richardson REST Maturity Model Resources /tickets

/tickets

/events

/users

/baskets

/event_venues

Nouns

Case convention

Plural

Page 35: RESTFUL API - EuroPython...RESTful APIs Web service APIs that adhere to the REST architectural constraints are called RESTful APIs Richardson REST Maturity Model Resources /tickets

Create POST

Read GET

Update PUT/PATCH

Delete DELETE

Page 36: RESTFUL API - EuroPython...RESTful APIs Web service APIs that adhere to the REST architectural constraints are called RESTful APIs Richardson REST Maturity Model Resources /tickets

Create POST

Read GET

Update PUT/PATCH

Delete DELETE

Page 37: RESTFUL API - EuroPython...RESTful APIs Web service APIs that adhere to the REST architectural constraints are called RESTful APIs Richardson REST Maturity Model Resources /tickets

GET /events - Read a list of events

GET /events/12 - Read a specific event

POST /events - Create a new event

PUT/PATCH /events/12 - Update event #12

DELETE /events/12 - Delete event #12

Page 38: RESTFUL API - EuroPython...RESTful APIs Web service APIs that adhere to the REST architectural constraints are called RESTful APIs Richardson REST Maturity Model Resources /tickets

GET /events/12/prices - Read a list of event’s prices

GET /events/12/prices/5 - Read a specific event’s price

POST /events/12/prices - Create a new event’s price

PUT/PATCH /events/12/prices/5 - Update event’s price

DELETE /events/12/prices/5 - Delete event’s price

Page 39: RESTFUL API - EuroPython...RESTful APIs Web service APIs that adhere to the REST architectural constraints are called RESTful APIs Richardson REST Maturity Model Resources /tickets

Related resource representations

Page 40: RESTFUL API - EuroPython...RESTful APIs Web service APIs that adhere to the REST architectural constraints are called RESTful APIs Richardson REST Maturity Model Resources /tickets
Page 41: RESTFUL API - EuroPython...RESTful APIs Web service APIs that adhere to the REST architectural constraints are called RESTful APIs Richardson REST Maturity Model Resources /tickets
Page 42: RESTFUL API - EuroPython...RESTful APIs Web service APIs that adhere to the REST architectural constraints are called RESTful APIs Richardson REST Maturity Model Resources /tickets

Filtering

GET /events?state=active&category=music,comedy

Page 43: RESTFUL API - EuroPython...RESTful APIs Web service APIs that adhere to the REST architectural constraints are called RESTful APIs Richardson REST Maturity Model Resources /tickets

Sorting

GET /events?sort=-date,name

Page 44: RESTFUL API - EuroPython...RESTful APIs Web service APIs that adhere to the REST architectural constraints are called RESTful APIs Richardson REST Maturity Model Resources /tickets

Searching

GET /events?q=Madonna

Page 45: RESTFUL API - EuroPython...RESTful APIs Web service APIs that adhere to the REST architectural constraints are called RESTful APIs Richardson REST Maturity Model Resources /tickets

Limiting response

GET /events?fields=(id,title,date,artist.name)

Page 46: RESTFUL API - EuroPython...RESTful APIs Web service APIs that adhere to the REST architectural constraints are called RESTful APIs Richardson REST Maturity Model Resources /tickets

Actions

GET /search

POST /order/1234/sum

Page 47: RESTFUL API - EuroPython...RESTful APIs Web service APIs that adhere to the REST architectural constraints are called RESTful APIs Richardson REST Maturity Model Resources /tickets

Versioning

https://my-site.com/api/v1

Accept: application/vnd.my-site.v3+json

Page 48: RESTFUL API - EuroPython...RESTful APIs Web service APIs that adhere to the REST architectural constraints are called RESTful APIs Richardson REST Maturity Model Resources /tickets

Pagination

Range: events=0-30

/events?page=1

/events?page=1&per_page=50 limit=10&offset=30

Page 49: RESTFUL API - EuroPython...RESTful APIs Web service APIs that adhere to the REST architectural constraints are called RESTful APIs Richardson REST Maturity Model Resources /tickets

Accept-Ranges: events 50

Content-Range: 0-10/1234

offset – limit / count

resource max

Link: <https://api.github.com/user/repos?page=3&per_page=100>; rel="next",<https://api.github.com/user/repos?page=50&per_page=100>; rel="last"

Page 50: RESTFUL API - EuroPython...RESTful APIs Web service APIs that adhere to the REST architectural constraints are called RESTful APIs Richardson REST Maturity Model Resources /tickets

Content-Type: application/json

Accept: application/xml; application/json

Page 51: RESTFUL API - EuroPython...RESTful APIs Web service APIs that adhere to the REST architectural constraints are called RESTful APIs Richardson REST Maturity Model Resources /tickets

Pretty print

Page 52: RESTFUL API - EuroPython...RESTful APIs Web service APIs that adhere to the REST architectural constraints are called RESTful APIs Richardson REST Maturity Model Resources /tickets
Page 53: RESTFUL API - EuroPython...RESTful APIs Web service APIs that adhere to the REST architectural constraints are called RESTful APIs Richardson REST Maturity Model Resources /tickets

HATEOAS

Page 54: RESTFUL API - EuroPython...RESTful APIs Web service APIs that adhere to the REST architectural constraints are called RESTful APIs Richardson REST Maturity Model Resources /tickets

Documentation

Page 55: RESTFUL API - EuroPython...RESTful APIs Web service APIs that adhere to the REST architectural constraints are called RESTful APIs Richardson REST Maturity Model Resources /tickets
Page 56: RESTFUL API - EuroPython...RESTful APIs Web service APIs that adhere to the REST architectural constraints are called RESTful APIs Richardson REST Maturity Model Resources /tickets

Best practices

Page 57: RESTFUL API - EuroPython...RESTful APIs Web service APIs that adhere to the REST architectural constraints are called RESTful APIs Richardson REST Maturity Model Resources /tickets
Page 58: RESTFUL API - EuroPython...RESTful APIs Web service APIs that adhere to the REST architectural constraints are called RESTful APIs Richardson REST Maturity Model Resources /tickets

Thank you!