googleapis how google builds apis

Upload: scribdreader2013

Post on 03-Apr-2018

239 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/28/2019 Googleapis How Google Builds Apis

    1/95

    How Google Builds APIs

    Zach Maier, Mark Stahl,Joey Schorr, Yaniv Inbar

    May 19-20, 2010

  • 7/28/2019 Googleapis How Google Builds Apis

    2/95

    How Google Builds APIs

    View live notes and ask questionsabout this session on Google Wave

    http://bit.ly/apiwave#googleapis8

  • 7/28/2019 Googleapis How Google Builds Apis

    3/95

    How Google Builds APIs

  • 7/28/2019 Googleapis How Google Builds Apis

    4/95

    How Google Builds APIs

    Google APIs 101

  • 7/28/2019 Googleapis How Google Builds Apis

    5/95

    How Google Builds APIs

    Google APIs 101

    Making Future APIs Awesome

  • 7/28/2019 Googleapis How Google Builds Apis

    6/95

    How Google Builds APIs

    Google APIs 101

    Making Future APIs Awesome

    How Google ReallyBuilds APIs

  • 7/28/2019 Googleapis How Google Builds Apis

    7/95

    How Google Builds APIs

    Google APIs 101

    Making Future APIs Awesome

    How Google ReallyBuilds APIs

    Questions and Comments

  • 7/28/2019 Googleapis How Google Builds Apis

    8/95

    How Google Builds APIs

    Google APIs 101

    Making Future APIs Awesome

    How Google ReallyBuilds APIs

    Questions and Comments

  • 7/28/2019 Googleapis How Google Builds Apis

    9/95

    REST == Representational State Transfer

    Client and servers transferring resource representations

    Good for cached and layered systems (like the web)

    REST 101

  • 7/28/2019 Googleapis How Google Builds Apis

    10/95

    REST == Representational State Transfer

    Client and servers transferring resource representations

    Good for cached and layered systems (like the web)

    In HTTP, this means verbs acting on resource URIs

    GET http://gdata.youtube.com/feeds/api/channels

    REST 101

  • 7/28/2019 Googleapis How Google Builds Apis

    11/95

    REST == Representational State Transfer

    Client and servers transferring resource representations

    Good for cached and layered systems (like the web)

    In HTTP, this means verbs acting on resource URIs

    GET http://gdata.youtube.com/feeds/api/channels

    AtomPub models data as feedsofentries

    Or more generally, as collectionsofresources

    REST 101

  • 7/28/2019 Googleapis How Google Builds Apis

    12/95

    REST 101

  • 7/28/2019 Googleapis How Google Builds Apis

    13/95

    REST 101

  • 7/28/2019 Googleapis How Google Builds Apis

    14/95

    REST 101

  • 7/28/2019 Googleapis How Google Builds Apis

    15/95

    REST 101

  • 7/28/2019 Googleapis How Google Builds Apis

    16/95

    REST 101

  • 7/28/2019 Googleapis How Google Builds Apis

    17/95

    REST 101

  • 7/28/2019 Googleapis How Google Builds Apis

    18/95

    REST 101

  • 7/28/2019 Googleapis How Google Builds Apis

    19/95

    REST 101

  • 7/28/2019 Googleapis How Google Builds Apis

    20/95

    REST 101

  • 7/28/2019 Googleapis How Google Builds Apis

    21/95

    REST 101

  • 7/28/2019 Googleapis How Google Builds Apis

    22/95

    Google Data

  • 7/28/2019 Googleapis How Google Builds Apis

    23/95

    Google Data

  • 7/28/2019 Googleapis How Google Builds Apis

    24/95

    Google Data Atom

    Right now you MUST understand Atom to use the APIs.

  • 7/28/2019 Googleapis How Google Builds Apis

    25/95

    Google Data Atom

    Right now you MUST understand Atom to use the APIs

    Core built around...

    Atom Syndication Format (RFC4287)

    Atom Publishing Protocol (RFC5023)

  • 7/28/2019 Googleapis How Google Builds Apis

    26/95

    Google Data Atom

    Right now you MUST understand Atom to use the APIs

    Core built around...

    Atom Syndication Format (RFC4287)

    Atom Publishing Protocol (RFC5023)

    Extended the core features

    Query parameters

    ConcurrencyBatch

  • 7/28/2019 Googleapis How Google Builds Apis

    27/95

    Google Data

    More than 25 APIs

    More than 2B hits per day across all APIs.

  • 7/28/2019 Googleapis How Google Builds Apis

    28/95

    The Future Google APIs

    We're moving to a brand new API infrastructure

  • 7/28/2019 Googleapis How Google Builds Apis

    29/95

    The Future Google APIs

    We're moving to a brand new API infrastructure

    You might already be using it...

  • 7/28/2019 Googleapis How Google Builds Apis

    30/95

    How Google Builds APIs

    Google APIs 101

    Making Future APIs AwesomeHow Google ReallyBuilds APIs

    Questions and Comments

  • 7/28/2019 Googleapis How Google Builds Apis

    31/95

    The Future Google APIs

    Rough edges in Google APIs

    Output formats

    Calling styles

    Client libraries

  • 7/28/2019 Googleapis How Google Builds Apis

    32/95

    Output Formats

  • 7/28/2019 Googleapis How Google Builds Apis

    33/95

    Output Formats

    Issue: Resources can be verbose

  • 7/28/2019 Googleapis How Google Builds Apis

    34/95

    Output Formats

    Solution: Allow operations on partial data

  • 7/28/2019 Googleapis How Google Builds Apis

    35/95

    Output Formats

    Solution: Allow operations on partial data

    Partial Response: GET just the fields you want

  • 7/28/2019 Googleapis How Google Builds Apis

    36/95

    Output Formats

    Solution: Allow operations on partial data

    Partial Response: GET just the fields you want

    http://gdata.youtube.com/feeds/api/videos

    ?v=2&q=google%20io&max-results=1

    &alt=xml

    bit.ly/nopartial

    http://bit.ly/nopartialhttp://bit.ly/nopartial
  • 7/28/2019 Googleapis How Google Builds Apis

    37/95

    Output Formats

    Solution: Allow operations on partial data

    Partial Response:GET just the fields you want

    http://gdata.youtube.com/feeds/api/videos

    ?v=2&q=google%20io&max-results=1

    &alt=xml

    bit.ly/nopartial

    http://gdata.youtube.com/feeds/api/videos

    ?v=2&q=google%20io&max-results=1

    &alt=xml&fields=entry(title,content)

    bit.ly/partialon

    http://bit.ly/partialonhttp://bit.ly/partialonhttp://bit.ly/partialonhttp://bit.ly/nopartialhttp://bit.ly/partialonhttp://bit.ly/nopartial
  • 7/28/2019 Googleapis How Google Builds Apis

    38/95

    Output Formats

    Solution: Allow operations on partial data

    Partial Response:GET just the fields you want

    http://gdata.youtube.com/feeds/api/videos

    ?v=2&q=google%20io&max-results=1

    &alt=xml

    bit.ly/nopartial

    http://gdata.youtube.com/feeds/api/videos

    ?v=2&q=google%20io&max-results=1

    &alt=xml&fields=entry(title,content)

    bit.ly/partialon

    Partial Update: PATCH just the fields you retrieved

    http://bit.ly/partialonhttp://bit.ly/partialonhttp://bit.ly/partialonhttp://bit.ly/nopartialhttp://bit.ly/partialonhttp://bit.ly/nopartial
  • 7/28/2019 Googleapis How Google Builds Apis

    39/95

    Output Formats

    Solution: Allow operations on partial data

    Partial Response:GET just the fields you want

    http://gdata.youtube.com/feeds/api/videos

    ?v=2&q=google%20io&max-results=1

    &alt=xml

    bit.ly/nopartial

    http://gdata.youtube.com/feeds/api/videos

    ?v=2&q=google%20io&max-results=1

    &alt=xml&fields=entry(title,content)

    bit.ly/partialon

    Partial Update: PATCH just the fields you retrieved

    More documentation at http://bit.ly/partialops

    http://bit.ly/partialonhttp://bit.ly/partialonhttp://bit.ly/partialonhttp://bit.ly/nopartialhttp://bit.ly/partialonhttp://bit.ly/nopartial
  • 7/28/2019 Googleapis How Google Builds Apis

    40/95

    Output Formats

    Issue: XML isn't easy on all platforms

  • 7/28/2019 Googleapis How Google Builds Apis

    41/95

    Solution: Support multiple read-write formats

    Output Formats

  • 7/28/2019 Googleapis How Google Builds Apis

    42/95

    Solution: Support multiple read-write formats

    Architecture Issue: Protocol-specific data model

    Output Formats

  • 7/28/2019 Googleapis How Google Builds Apis

    43/95

    Solution: Support multiple read-write formats

    Architecture Issue: Protocol-specific data model

    Output Formats

  • 7/28/2019 Googleapis How Google Builds Apis

    44/95

    Solution: Support multiple read-write formats

    Architecture Solution: Generic data model

    Output Formats

  • 7/28/2019 Googleapis How Google Builds Apis

    45/95

    Solution: Support multiple read-write formats

    Architecture Solution: Generic data model

    Output Formats

  • 7/28/2019 Googleapis How Google Builds Apis

    46/95

    Solution: Support multiple read-write formats

    Architecture Solution: Generic data model

    http://www.googleapis.com/buzz/v1/activities

    /markstahl/@public?q=google&max-results=1

    &alt=atom bit.ly/buzzatom

    http://www.googleapis.com/buzz/v1/activities

    /markstahl/@public?q=google&max-results=1

    &alt=json bit.ly/buzzjson

    Output Formats

    http://www.googleapis.com/buzz/v1/activities/markstahl/@public?q=google&max-results=1&alt=atom&prettyprint=truehttp://www.googleapis.com/buzz/v1/activities/markstahl/@public?q=google&max-results=1&alt=json&prettyprint=truehttp://www.googleapis.com/buzz/v1/activities/markstahl/@public?q=google&max-results=1&alt=atom&prettyprint=true
  • 7/28/2019 Googleapis How Google Builds Apis

    47/95

    Solution: Support multiple read-write formats

    Architecture Solution: Generic data model

    Output Formats

  • 7/28/2019 Googleapis How Google Builds Apis

    48/95

    Solution: Support multiple read-write formats

    Architecture Solution: Generic data model

    Output Formats

  • 7/28/2019 Googleapis How Google Builds Apis

    49/95

    Calling Styles

  • 7/28/2019 Googleapis How Google Builds Apis

    50/95

    Calling Styles

    Issue: REST can be Awkward

  • 7/28/2019 Googleapis How Google Builds Apis

    51/95

    Calling Styles

    Issue: REST can be Awkward

  • 7/28/2019 Googleapis How Google Builds Apis

    52/95

    Calling Styles

    Issue: REST can be Awkward

  • 7/28/2019 Googleapis How Google Builds Apis

    53/95

    Calling Styles

    Issue: REST can be Awkward

    C lli S l

  • 7/28/2019 Googleapis How Google Builds Apis

    54/95

    Calling Styles

    Issue: REST can be Awkward

    C lli St l

  • 7/28/2019 Googleapis How Google Builds Apis

    55/95

    Calling Styles

    Solution: Augment REST with Custom Verbs

    C lli St l

  • 7/28/2019 Googleapis How Google Builds Apis

    56/95

    Calling Styles

    Solution: Augment REST with Custom Verbs

    C lli St l

  • 7/28/2019 Googleapis How Google Builds Apis

    57/95

    Calling Styles

    Solution: Augment REST with Custom Verbs

    C lli St l

  • 7/28/2019 Googleapis How Google Builds Apis

    58/95

    Calling Styles

    Solution: Augment REST with Custom Verbs

    C lli St l

  • 7/28/2019 Googleapis How Google Builds Apis

    59/95

    Calling Styles

    Solution: Augment REST with Custom Verbs

    Example: Two ways to mark a task as "done"

    C lli St l

  • 7/28/2019 Googleapis How Google Builds Apis

    60/95

    Calling Styles

    Solution: Augment REST with Custom Verbs

    Example: Two ways to mark a task as "done"

    The RESTful way

    GET /tasks/@me/{taskId}

    modify resource on client, set the "done" bit

    PUT /tasks/@me/{taskId}

    C lli St l

  • 7/28/2019 Googleapis How Google Builds Apis

    61/95

    Calling Styles

    Solution: Augment REST with Custom Verbs

    Example: Two ways to mark a task as "done"

    The RESTful way

    GET /tasks/@me/{taskId}

    modify resource on client, set the "done" bit

    PUT /tasks/@me/{taskId}

    Using custom verbs

    POST /tasks/@me/{taskId}?method=markDone

    Calling Styles

  • 7/28/2019 Googleapis How Google Builds Apis

    62/95

    Calling Styles

    Issue: RPC is the basis of many API Standards

    Calling Styles

  • 7/28/2019 Googleapis How Google Builds Apis

    63/95

    Calling Styles

    Solution: Parallel REST and JSON-RPC interface

    Calling Styles

  • 7/28/2019 Googleapis How Google Builds Apis

    64/95

    Calling Styles

    Solution: Parallel REST and JSON-RPC interface

    Calling Styles

  • 7/28/2019 Googleapis How Google Builds Apis

    65/95

    Calling Styles

    Solution: Parallel REST and JSON-RPC interface

    Parallel calling styles for common methods

    Calling Styles

  • 7/28/2019 Googleapis How Google Builds Apis

    66/95

    Calling Styles

    Solution: Parallel REST and JSON-RPC interface

    Parallel calling styles for common methods, and custom verbs

    Client Libraries

  • 7/28/2019 Googleapis How Google Builds Apis

    67/95

    Client Libraries

    Client Libraries

  • 7/28/2019 Googleapis How Google Builds Apis

    68/95

    Client Libraries

    Issue: Client libraries don't stay on the cutting edge

    Client Libraries

  • 7/28/2019 Googleapis How Google Builds Apis

    69/95

    Client Libraries

    Solution: Dynamic Discovery

    Client Libraries

  • 7/28/2019 Googleapis How Google Builds Apis

    70/95

    Client Libraries

    Solution: Dynamic Discovery

    Discovery Document

    JSON object

    Describes resources, URLs, verbs, parameters, (schemas)

    Always up to date

    Client Libraries

  • 7/28/2019 Googleapis How Google Builds Apis

    71/95

    Client Libraries

    Solution: Dynamic Discovery

    Discovery Document

    JSON object

    Describes resources, URLs, verbs, parameters, (schemas)

    Always up to date

    Discovery is just another API

    http://www.googleapis.com/directory/v0.1/

    describe?api=discovery&apiVersion=v1

    bit.ly/buzzdiscovery

    Client Libraries

    http://bit.ly/buzzdiscovery
  • 7/28/2019 Googleapis How Google Builds Apis

    72/95

    Client Libraries

    Solution: "Generic" Client Libraries

    Client Libraries

  • 7/28/2019 Googleapis How Google Builds Apis

    73/95

    Client Libraries

    Solution: "Generic" Client Libraries

    Discover resources, URL templates, verbs

    No more scraping URLs from doc

    Client Libraries

  • 7/28/2019 Googleapis How Google Builds Apis

    74/95

    Client Libraries

    Solution: "Generic" Client Libraries

    Discover resources, URL templates, verbs

    No more scraping URLs from doc

    Use simple classes to represent resources

    Create POJOs to map JSON

    Client Libraries

  • 7/28/2019 Googleapis How Google Builds Apis

    75/95

    Client Libraries

    Solution: "Generic" Client Libraries

    Discover resources, URL templates, verbs

    No more scraping URLs from doc

    Use simple classes to represent resources

    Create POJOs to map JSON

    Make advanced features easy(er)

    Batching, Async, Partial Get and Update

    Client Libraries

  • 7/28/2019 Googleapis How Google Builds Apis

    76/95

    Client Libraries

    Solution: "Generic" Client Libraries

    Discover resources, URL templates, verbs

    No more scraping URLs from doc

    Use simple classes to represent resources

    Create POJOs to map JSON

    Make advanced features easy(er)

    Batching, Async, Partial Get and Update

    Works on multiple platforms

    Java client works on servers, AppEngine, Android

    JavaScript client works on web pages, gadgets, AppScript

    Client Libraries

  • 7/28/2019 Googleapis How Google Builds Apis

    77/95

    Client Libraries

    Solution: "Generic" Client Libraries

    Discover resources, URL templates, verbs

    No more scraping URLs from doc

    Use simple classes to represent resources

    Create POJOs to map JSON

    Make advanced features easy(er)

    Batching, Async, Partial Get and Update

    Works on multiple platforms

    Java client works on servers, AppEngine, Android

    JavaScript client works on web pages, gadgets, AppScript

    Release once ... Works with Any API

  • 7/28/2019 Googleapis How Google Builds Apis

    78/95

    Java Client Demonstration

    Client Libraries

  • 7/28/2019 Googleapis How Google Builds Apis

    79/95

    Client Libraries

    Solution: "Generic" Client Libraries

    Client Libraries

  • 7/28/2019 Googleapis How Google Builds Apis

    80/95

    Client Libraries

    Solution: "Generic" Client Libraries

    Why we like this client sample

    Resource URLs are discovered dynamically

    Very little Buzz specific code

    Runs on Android

    Client Libraries

  • 7/28/2019 Googleapis How Google Builds Apis

    81/95

    Client Libraries

    Solution: "Generic" Client Libraries

    Why we like this client sampleResource URLs are discovered dynamically

    Very little Buzz specific code

    Runs on Android

    Go check it out yourself!

    Sample: bit.ly/iobuzz

    Library:bit.ly/javalib

    The Future Google APIs

    http://bit.ly/javalibhttp://bit.ly/iobuzzhttp://bit.ly/javalibhttp://bit.ly/iobuzz
  • 7/28/2019 Googleapis How Google Builds Apis

    82/95

    The Future Google APIs

    The Future Google APIs

  • 7/28/2019 Googleapis How Google Builds Apis

    83/95

    The Future Google APIs

    Issues we've noticed in 5 years of building APIs

    How we're fixing those issues

    The Future Google APIs

  • 7/28/2019 Googleapis How Google Builds Apis

    84/95

    e utu e Goog e s

    Issues we've noticed in 5 years of building APIs

    Resources can be verbose

    How we're fixing those issues

    Allow operations on partial data

    The Future Google APIs

  • 7/28/2019 Googleapis How Google Builds Apis

    85/95

    g

    Issues we've noticed in 5 years of building APIs

    Resources can be verboseXML isn't easy on all platforms

    How we're fixing those issues

    Allow operations on partial data

    Provide multiple read-write formats

    The Future Google APIs

  • 7/28/2019 Googleapis How Google Builds Apis

    86/95

    g

    Issues we've noticed in 5 years of building APIs

    Resources can be verboseXML isn't easy on all platforms

    REST can be awkward

    How we're fixing those issues

    Allow operations on partial data

    Provide multiple read-write formats

    Augment REST with custom verbs, provide REST and RPC

    The Future Google APIs

  • 7/28/2019 Googleapis How Google Builds Apis

    87/95

    g

    Issues we've noticed in 5 years of building APIs

    Resources can be verboseXML isn't easy on all platforms

    REST can be awkward

    Client libraries don't stay on the cutting edge

    How we're fixing those issues

    Allow operations on partial data

    Provide multiple read-write formats

    Augment REST with custom verbs, provide REST and RPC

    Dynamic discovery and "generic" client libraries

  • 7/28/2019 Googleapis How Google Builds Apis

    88/95

    How Google Builds APIs

    Google APIs 101

    Making Future APIs Awesome

    How Google ReallyBuilds APIs

    Questions and Comments

    How Google ReallyBuilds APIs

  • 7/28/2019 Googleapis How Google Builds Apis

    89/95

    g y

    How Google ReallyBuilds APIs

  • 7/28/2019 Googleapis How Google Builds Apis

    90/95

    g y

    Implement Internal Service

    Define abstract resource (using protocol buffers)

    Define collections and verbs (using protocol buffer RPC)

    How Google ReallyBuilds APIs

  • 7/28/2019 Googleapis How Google Builds Apis

    91/95

    g y

    Implement Internal Service

    Define abstract resource (using protocol buffers)

    Define collections and verbs (using protocol buffer RPC)

    Configure the API Stack

    Map REST paths, RPC methods, query parametersAdd common functionality: auth, caching, logging, ...

    How Google ReallyBuilds APIs

  • 7/28/2019 Googleapis How Google Builds Apis

    92/95

    g y

    Implement Internal Service

    Define abstract resource (using protocol buffers)

    Define collections and verbs (using protocol buffer RPC)

    Configure the API Stack

    Map REST paths, RPC methods, query parametersAdd common functionality: auth, caching, logging, ...

    Write Output Templates

    Set up external data representation

    JSON, Atom, XML, ...

  • 7/28/2019 Googleapis How Google Builds Apis

    93/95

    API Configuration Tool Demonstration

    How Google ReallyBuilds APIs

  • 7/28/2019 Googleapis How Google Builds Apis

    94/95

    You just saw the simple three steps:

    Service implementedAPI stack configured

    Output templates written

  • 7/28/2019 Googleapis How Google Builds Apis

    95/95

    How Google Builds APIs

    Google APIs 101

    Making Future APIs Awesome

    How Google ReallyBuilds APIs

    Questions and Comments

    http://bit.ly/apiwave