building adaptable apis with narwhl (api days paris)

35
Intel Confidential Do Not Forward Taming The RESTed NARWHL An Approach to Building Adaptable APIs

Upload: rob-zazueta

Post on 08-Jul-2015

376 views

Category:

Software


4 download

DESCRIPTION

An updated version of my NARWHL talk given at API Days Paris.

TRANSCRIPT

Page 1: Building Adaptable APIs with NARWHL (API Days Paris)

Intel Confidential — Do Not Forward

Taming The RESTed NARWHLAn Approach to Building Adaptable APIs

Page 2: Building Adaptable APIs with NARWHL (API Days Paris)

2

Page 3: Building Adaptable APIs with NARWHL (API Days Paris)

3

Is this RESTful?

http://api.example.com/events/query.json?id=87465

Twitter: @rzazueta http://www.narwhl.com

Page 4: Building Adaptable APIs with NARWHL (API Days Paris)

4

What About This?

Find “Rob Zazueta” in the employee Database.

GET /countries

[

"/countries/usa/states",

"/countries/can/provinces",

...

]

GET /countries/usa/states

[

"/countries/usa/states/al",

"/countries/usa/states/ak",

...

]

GET /countries/usa/states/ca

[

"/countries/usa/states/ca/divisions",

"/countries/usa/states/ca/employees",

...

]

GET /countries/usa/states/ca/employees[

"/countries/usa/states/ca/employees/alan_akbar

",

"/countries/usa/states/ca/employees/bill_allen"

...

]

Twitter: @rzazueta http://www.narwhl.com

Page 5: Building Adaptable APIs with NARWHL (API Days Paris)

5

Google: “What is a REST API?”

Twitter: @rzazueta http://www.narwhl.com

Page 6: Building Adaptable APIs with NARWHL (API Days Paris)

6

Consistency Counts

Twitter: @rzazueta http://www.narwhl.com

Page 7: Building Adaptable APIs with NARWHL (API Days Paris)

7

Page 8: Building Adaptable APIs with NARWHL (API Days Paris)

8

Introducing the RESTed NARWHL

A design framework to build RESTful

APIs intended for consumption by

applications built by people

Twitter: @rzazueta http://www.narwhl.com

Page 9: Building Adaptable APIs with NARWHL (API Days Paris)

9

I Want To Hear From YOU!

The RESTed NARWHL

http://www.narwhl.com

Twitter: @rzazueta http://www.narwhl.com

Page 10: Building Adaptable APIs with NARWHL (API Days Paris)

10

1. It’s how I describe intuitive APIs

Noun

As

Resource

With

Hyper

Links Twitter: @rzazueta http://www.narwhl.com

Page 11: Building Adaptable APIs with NARWHL (API Days Paris)

11

2. Narwhals are an awesome mashup

+ =

Twitter: @rzazueta http://www.narwhl.com

Page 12: Building Adaptable APIs with NARWHL (API Days Paris)

12

3. Narwhals are real.

Twitter: @rzazueta http://www.narwhl.com

Page 13: Building Adaptable APIs with NARWHL (API Days Paris)

13

Obligatory RMM Slide

Source: http://martinfowler.com/articles/richardsonMaturityModel.html

Twitter: @rzazueta http://www.narwhl.com

Page 14: Building Adaptable APIs with NARWHL (API Days Paris)

14

Use Cases Uncover Resources

A customer wants to browse for products by category.

A customer wants to add a product to their shopping cart.

A store admin wants to list all customers who bought a given

product.

Twitter: @rzazueta http://www.narwhl.com

Page 15: Building Adaptable APIs with NARWHL (API Days Paris)

15

Use Cases Uncover Resources

A customer wants to browse for products by category.

A customer wants to add a product to their shopping cart.

A store admin wants to list all customers who bought a

given product.

Twitter: @rzazueta http://www.narwhl.com

Page 16: Building Adaptable APIs with NARWHL (API Days Paris)

16

Use Cases Uncover Resources

Customers

Products

Categories

Shopping Cart

Store Admin

Twitter: @rzazueta http://www.narwhl.com

Page 17: Building Adaptable APIs with NARWHL (API Days Paris)

17

Endpoint Design Matters

/{resource_name}/{resource_identifier}

Twitter: @rzazueta http://www.narwhl.com

Page 18: Building Adaptable APIs with NARWHL (API Days Paris)

18

Endpoint Design Matters

/products/73924

Twitter: @rzazueta http://www.narwhl.com

Page 19: Building Adaptable APIs with NARWHL (API Days Paris)

19

Endpoint Design Matters

/categories/39/products/73924

Twitter: @rzazueta http://www.narwhl.com

Page 20: Building Adaptable APIs with NARWHL (API Days Paris)

20

Endpoint Design Matters

Link: <http://api.example.com/products/73924>; rel="canonical"

Twitter: @rzazueta http://www.narwhl.com

Page 21: Building Adaptable APIs with NARWHL (API Days Paris)

21

Content Negotiation

WWBD?

Twitter: @rzazueta http://www.narwhl.com

Page 22: Building Adaptable APIs with NARWHL (API Days Paris)

22

Content Negotiation

application/x-shockwave-flash

Twitter: @rzazueta http://www.narwhl.com

Page 23: Building Adaptable APIs with NARWHL (API Days Paris)

Content Negotiation

Twitter: @rzazueta http://www.narwhl.com

Page 24: Building Adaptable APIs with NARWHL (API Days Paris)

Content Negotiation

Twitter: @rzazueta http://www.narwhl.com

Page 25: Building Adaptable APIs with NARWHL (API Days Paris)

25

Content Negotiation – Better Communication;

Saner Versioning

Start using specific MIME types in your responses –

even custom ones.

NOContent-Type: application/json

YESContent-Type: application/json;vnd.example.products+v1

Page 26: Building Adaptable APIs with NARWHL (API Days Paris)

26

Content Negotiation – Shared Profiles

Twitter: @rzazueta http://www.narwhl.com

Page 27: Building Adaptable APIs with NARWHL (API Days Paris)

27

Content Negotiation – Custom Profiles

Twitter: @rzazueta http://www.narwhl.com

Page 28: Building Adaptable APIs with NARWHL (API Days Paris)

28

Which Hypermedia Format?

Twitter: @rzazueta http://www.narwhl.com

Page 29: Building Adaptable APIs with NARWHL (API Days Paris)

29

Dynamic Client Generation Through Response Profiles

Twitter: @rzazueta http://www.narwhl.com

Page 30: Building Adaptable APIs with NARWHL (API Days Paris)

30

SDKs Suck Because:

• They’re one more thing to maintain

• They often assume functionality outside the API

• They get bloated

Twitter: @rzazueta http://www.narwhl.com

Page 31: Building Adaptable APIs with NARWHL (API Days Paris)

31

SDKs Are Necessary Because:

• No one wants to spend time figuring out your API.

Twitter: @rzazueta http://www.narwhl.com

Page 32: Building Adaptable APIs with NARWHL (API Days Paris)

32

Dynamic Code Libraries Rock Because:

• They reflect only what’s defined in the API

• They grow and change as the API iterates

• They feel more native to the developer

Twitter: @rzazueta http://www.narwhl.com

Page 33: Building Adaptable APIs with NARWHL (API Days Paris)

33

NARWHL Maturity Model*

Level 0: Nouns as Resources With Hyperlinks

Level 1: NARWHL JSON Responses

Level 2: Content Negotiation

Level 3: Response Profiles & Definitions

Awesomeness of NARWHL

*With apologies and thanks to Martin Fowler and Leonard Richardson

Twitter: @rzazueta http://www.narwhl.com

Page 34: Building Adaptable APIs with NARWHL (API Days Paris)

34

Don’t Make Me Beg…

The RESTed NARWHL

http://www.narwhl.com

Twitter: @rzazueta http://www.narwhl.com

Page 35: Building Adaptable APIs with NARWHL (API Days Paris)

Intel Confidential — Do Not Forward

Thank You!Rob Zazueta

[email protected]

@rzazueta

http://www.NARWHL.com

35