atompub, beyond blogs

52
AtomPub, beyond blogs Using the AtomPub protocol as the base of your Web API

Upload: mohanaraj-gopala-krishnan

Post on 14-Dec-2014

4.840 views

Category:

Technology


0 download

DESCRIPTION

A presentation by Mohanaraj Gopala Krishnan at barcamp Malaysia 2008. Attribution: Content and inspiration from http://bitworking.org/news/125/REST-and-WS http://bitworking.org/projects/oscon2007/html/

TRANSCRIPT

Page 1: AtomPub, beyond blogs

AtomPub, beyond blogs Using the AtomPub protocol as the base of your Web API

Page 2: AtomPub, beyond blogs

Questions for you

• Are you familiar with HTTP (Methods, Status codes etc) ?

• Are you familiar with Web Services/APIs?

• Are you familiar with AtomPub?

• Have you developed a web service before ?

• Have you used/written WS-* ?

• Have used/written AtomPub ?

Page 3: AtomPub, beyond blogs

Your mission - Build a web service that:

Page 4: AtomPub, beyond blogs

• Speaks HTTP, across the Internet

• Is scalable and robust

Page 5: AtomPub, beyond blogs

• Caters to heterogeneous clients (browsers, terminals, other web services )

•Language neutral (Java,PHP,Perl,Python, Ruby and god forbid C , C++ ;))

Page 6: AtomPub, beyond blogs

Options ?(Architecture - wise)

Page 7: AtomPub, beyond blogs

RPC Architecture

• Uses HTTP as a transport protocol - not an application protocol

• Maps procedural programming model to the Web - parameters and method calls are serialized

• Problems already solved by HTTP need to be handled (error handling, caching etc.)

• E.g. XML-RPC and ...

Page 8: AtomPub, beyond blogs

WS - *

"The SOAP stack is generally regarded as an

embarrassing failure these days" Tim Bray

http://www.infoworld.com/article/08/07/24/Sun-technologist-SOAP-stack-a-failure_1.html

Page 9: AtomPub, beyond blogs

RESTful architecture

• HTTP used correctly- application protocol

• Everything has an ID (Link-able)

• Everything is linked to each other

• Fixed interface(GET,PUT,POST,DELETE,HEAD,OPTIONS)

• Multiple representations of a resource

• Stateless

Page 10: AtomPub, beyond blogs

What does using HTTP as an

application protocol give you

for free ?

Page 11: AtomPub, beyond blogs

HTTP Pipelining

Compression (Transport encoding)

Caching (Last-modified, If-modified-since, E-tags,Cache controls)

Content negotiation (mimetype/content type)

Error handling (HTTP status codes)

Simple tooling (curl anybody ?)

Concurrency handling (Optimistic concurrency - If-Match)

Layered approach (Atompub + Opensearch + Digest authentication)

Page 12: AtomPub, beyond blogs

• Atom is both a format and a protocol

• A way to use HTTP correctly

AtomPub is a REST styled protocol (RESTful)

Page 13: AtomPub, beyond blogs

Services using AtomPub

• Google: GData

• Microsoft: Live Platform, Astoria

• IBM: Lotus Connector

• LCA: Resource synchronisation :-)

Page 14: AtomPub, beyond blogs

AtomPub 101

Page 15: AtomPub, beyond blogs

AtomPub 101The data model

Page 16: AtomPub, beyond blogs

Entry

Defines the essential pieces of a document

Page 17: AtomPub, beyond blogs

Essential pieces

• Title

• Author(s)

• ID

• Published Date

• Content

Page 18: AtomPub, beyond blogs

Feed

This is the envelope for entries

Page 19: AtomPub, beyond blogs

Service document

An introspection document for collections

Page 20: AtomPub, beyond blogs
Page 21: AtomPub, beyond blogs

AtomPub 101Operations

Page 22: AtomPub, beyond blogs

Operations on CollectionsMethod Resource Representation Description

GET Collection Atom Feed Retrieve a list of members

POST Collection Atom Entry Add a new member

Operations on MembersMethod Resource Representation Description

GET Member Atom Entry Retrieve a member representation

PUT Member Atom Entry Update a member representation

DELETE Member n/a Delete a member

Page 23: AtomPub, beyond blogs

POST to a collection to create an entry(Request)

Page 24: AtomPub, beyond blogs

POST to a collection to create an entry(Response)

Page 25: AtomPub, beyond blogs

Result

Page 26: AtomPub, beyond blogs

PUT to edit URL to update

Page 27: AtomPub, beyond blogs

GET the entry URL to update

Page 28: AtomPub, beyond blogs

PUT to edit URL to update (Retrieve)

Page 29: AtomPub, beyond blogs

PUT to edit URL to update (Request)

Page 30: AtomPub, beyond blogs

DELETE to edit URL to delete (Request)

Page 31: AtomPub, beyond blogs

When is AtomPub suitable for you ?

Page 32: AtomPub, beyond blogs

Dealing with collections of documents / resources

The collection-item metaphor is a powerful abstraction

Time indexed resources

Sales orders, members, events, filesystem, articles, relationships, transactions

Page 33: AtomPub, beyond blogs

Operations can be mapped to CRUD + List

• Requires some thinking

• Tough when not time indexed

• Something messaging model is better

Page 34: AtomPub, beyond blogs

Heterogeneous & Interop important

"[I]f you don't have control of both ends of the wire then loosely typed documents beat strongly typed data-structure serializations."

http://bitworking.org/news/Nelson_Minar_on_SOAP

Page 35: AtomPub, beyond blogs

http://bitworking.org/news/125/REST-and-WS

Homogenous systems - Serializing objects work OK

Heterogeneous systems - Move towards self descriptive documents

Page 36: AtomPub, beyond blogs

Misconception

Only good for blogs, html/xml type data

Page 37: AtomPub, beyond blogs

Your content in AtomPub

Page 38: AtomPub, beyond blogs

Re-orientate your thinking

• Move from a service orientation to a resource orientation (‘verb to noun’)

• Identify the resources in your system - ‘nouns’

• Map them into collections and entries

• Map the standard interface to the required operations

Page 39: AtomPub, beyond blogs

First identify the entry mandatory fields

Page 40: AtomPub, beyond blogs
Page 41: AtomPub, beyond blogs

In content element

Page 42: AtomPub, beyond blogs

In content element

• Leverage mimetypes -text, html, xhtml

• Use microformats

• Custom XML - Use - application/xml

Page 43: AtomPub, beyond blogs

Extending with custom name space

Page 44: AtomPub, beyond blogs
Page 45: AtomPub, beyond blogs
Page 46: AtomPub, beyond blogs

Use media link entries

Page 47: AtomPub, beyond blogs

Mapping operations

• Google Finance a great example

• Operations mapped

• Managing portfolios

• Managing positions

• Managing transactions

http://code.google.com/apis/finance/developers_guide_protocol.html

Page 48: AtomPub, beyond blogs

What you get ?Standard API

Pagination (RFC 5005)

Discovery (Service document)

Categorization (Atom:category)

Simple sync ( using app:edited )

Test suites for client and servers (Very IMPORTANT! - APE, feedvalidator, JGs apptestclient)

Existing implementations (client and server) that interop (http://intertwingly.net/wiki/pie/InteropGrid)

Existing libraries and toolkits

Page 49: AtomPub, beyond blogs

Limitations ?Multi-depth hierarchies (Possible by such things as rel attrib)

Incremental updates of entries (HTTP Patch, XML Diff)

Multiple(Batch) operations (Being sorted with multipart extension)

Querying (Open search)

Synchronisation (Feed sync , simple system of timestamps)

Long running transactions (Break down the collections)

Collection creation and handling (MetaAtompub)

Authentication / Encryption (Use existing auth schemes)

Page 50: AtomPub, beyond blogs

AtomPub as a layer in the stack

Page 51: AtomPub, beyond blogs

• Consume• curl• httplib2 (any httplib)

• Produce• Amplee (Library) - Python• php-atompub-server - PHP• Abdera(Library) - Java• Catalyst::Controller::Atompub -Perl• mod_atom - C/Apache

Toolkits

Page 52: AtomPub, beyond blogs

[email protected]/blog