designing an api

24
API Design Choices: Audience, Aggregation & beyond By Jacob Ideskog, Solution Architect @jacobideskog, @2botech Copyright © 2013 Twobo Technologies AB. All rights reserved.

Upload: twobo-technologies

Post on 11-May-2015

985 views

Category:

Business


0 download

DESCRIPTION

History, design choices, service aggregation, levels of REST,

TRANSCRIPT

Page 1: Designing an API

API Design Choices: Audience,

Aggregation & beyond

By Jacob Ideskog, Solution Architect

@jacobideskog, @2botech

Copyright © 2013 Twobo Technologies AB. All rights reserved.

Page 2: Designing an API

Agenda

History

Trends

REST

Aggregation vs Mashups

Copyright © 2013 Twobo Technologies AB. All rights reserved.

Page 3: Designing an API

Disruptive trends

Cloud

Computing

Social

Networks

Mobile

Big

Data

Copyright © 2013 Twobo Technologies AB. All rights reserved.

Page 4: Designing an API

Back in the days

Copyright © 2013 Twobo Technologies AB. All

rights reserved

Web apps have evolved

from CGI to

the cloud

HTTP, HTML, CGI

COM & CORBA

SOAP & SOA

Web 2.0 & REST

The Cloud

Cloud APIs

Page 5: Designing an API

How to start?

Design-by-buzzword

Copyright © 2013 Twobo Technologies AB. All

rights reserved

Hypermedia

Node.js

JSON REST

Page 6: Designing an API

Target Audience

Who is it for?

Apps?

Mobile Apps?

Internal Apps

Other Services?

All of the above?

Copyright © 2013 Twobo Technologies AB. All

rights reserved

Page 7: Designing an API

Target Architecture

What are you serving

Processing services

Data services

Communication services

?

Copyright © 2013 Twobo Technologies AB. All

rights reserved

Page 8: Designing an API

The glorious REST

Representional State Transfer

Highly Scalable

Uses URI identifiers

No state on server side

Hyperlinked

No uniform standard

NOT A PROTOCOL

Copyright © 2013 Twobo Technologies AB. All

rights reserved

Page 9: Designing an API

Resource or service

Copyright © 2013 Twobo Technologies AB. All

rights reserved http://martinfowler.com/articles/richardsonMaturityModel.html

Level 0: The Swamp of POX

Level 1: Resource

Level 2: HTTP Verbs

Level 3: Hypermedia Controls

Glory of Rest

Page 10: Designing an API

Level 0 Swamp of POX

Copyright © 2013 Twobo Technologies AB. All

rights reserved

Copyright © 2013 Twobo Technologies AB. All

rights reserved

POST <getBook>

POST <deleteUser>

<book ...

<ok ...

/api

XML RPC all over again

Page 11: Designing an API

Level 1 Resources

Uses URIs

But still XML messages as operations

Copyright © 2013 Twobo Technologies AB. All

rights reserved

POST <getBook>

POST <deleteUser>

<book ...

<ok ...

/books/2

/users/24

Page 12: Designing an API

Level 2 HTTP Verbs

Utilizes the semantics of HTTP

Copyright © 2013 Twobo Technologies AB. All

rights reserved

GET - Read a resource HEAD – Read metadata about resource OPTIONS – Read what operations are available POST – Add a new resource, or run operation PUT – Replace existing resource completely DELETE – Remove resource (PATCH – Update existing resource in place)

GET ?pagesize=A4

DELETE

200 OK <book ...

201 No Content

/books/2

/users/32

Page 13: Designing an API

Level 3 The Glory of REST

HATEOAS

Hypermedia As The Engine Of Application State

Or simply: Hypermedia

Let the Media Type tell you what to do

Hyperlink, hyperlink hyperlink

Copyright © 2013 Twobo Technologies AB. All

rights reserved

Page 14: Designing an API

Example

Copyright © 2013 Twobo Technologies AB. All

rights reserved

curl –v http://localhost/stuff <stuff xmlns:tt=http://example.com/rest tt:rel=”/stuff"> <more-stuff tt:rel="/stuff/more-stuff"/> <other-stuff tt:=”/stuff/other-stuff"/> <data> <entry>Interesting 1</entry> <entry>Interesting 2</entry> </stuff>

curl –v http://localhost/stuff/more-stuff <more-stuff xmlns:tt=http://example.com/rest tt:rel=”/stuff/more-stuff"> <things tt:rel="/stuff/more-stuff/things"/> </more-stuff>

Page 15: Designing an API

Ring a bell?

Copyright © 2013 Twobo Technologies AB. All

rights reserved

curl –v http://localhost/v2/stuff <html> <div id=“stuff”> <a href=“/stuff/more-stuff”/> <a href=“/stuff/other-stuff/> <ol id=“data”> <li id=“entry1”>Interesting 1</li> <li id=“entry2”>Interesting 2</li> </ol> <form action=“/stuff” > <input type=“text” name=“value” /> </form> </div> </html>

Page 16: Designing an API

The Real World

But? My API uses other APIs

Copyright © 2013 Twobo Technologies AB. All

rights reserved

Page 17: Designing an API

The power of Mashups

Web mashup is easy

API mashup is harder

But the payoff is greater

API aggregation is really hard

And believe me, you’ll need to do it anyway…

Copyright © 2013 Twobo Technologies AB. All

rights reserved

Page 18: Designing an API

Mashups vs. Aggregations

Copyright © 2013 Twobo Technologies AB. All

rights reserved

Mashup Aggregation

Page 19: Designing an API

Why is it hard

Different backend states and protocols

Different authentication methods

Different lookup schemes

Backend versioning

Copyright © 2013 Twobo Technologies AB. All

rights reserved

1st Original API New

‘Aggregated’ API

2ndOriginal API

Operationally

interesting

Page 20: Designing an API

Aggregators

Don’t invent the wheel

Once your API is advanced enough, you’ll have to

mash-up

But do you need aggregation?

If so: Identify the “operationally interesting” area

Focus on that

Mashup the rest

Copyright © 2013 Twobo Technologies AB. All rights reserved

Page 21: Designing an API

The Real World

Ah, the power of API Gateways!

Copyright © 2013 Twobo Technologies AB. All

rights reserved

Page 22: Designing an API

Summary

Who is it for?

What are you selling?

Hypermedia in REST

Mash-ups vs. Aggregations

Copyright © 2013 Twobo Technologies AB. All

rights reserved

Page 23: Designing an API

Questions & thanks

@2botech

www.2botech.com

@jacobideskog Copyright © 2013 Twobo Technologies AB. All rights reserved

Page 24: Designing an API