$30 off During Our Annual Pro Sale. View Details »

Distribution and Publication with Atom Web Services (ZendCon 2008)

Distribution and Publication with Atom Web Services (ZendCon 2008)

As we move toward “Web 3.0,” the Web is slowly transforming into a platform upon which massively distributed applications run. Rich clients turn personal computers into thin clients, not storing or processing any data locally but, rather, connecting to a web service where the data resides. These services may target intranets, extranets, or the global Web community, but to work they need a common language. One such language is the Atom Publishing Protocol.

Since its inception as a draft recommendation in 2003, the Atom Syndication Format (RFC 4287) has been used as an alternative to Really Simple Syndication (RSS) feeds on blogs throughout the blogosphere. Most have understood Atom as just another feed format, but the publication of the Atom Publishing Protocol (RFC 5023) opens the door for far more uses of the Atom format as both a means for distribution of data, as well as publication.

Ben Ramsey will introduce the Atom Syndication Format and Atom Publishing Protocol, explaining in depth how these can form the foundation of any web service for publication and distribution of data in any environment, from the enterprise right down to the small business level. Ramsey will also discuss RESTful design principles as they relate to the Atom Publishing Protocol.

Ben Ramsey
PRO

September 16, 2008
Tweet

More Decks by Ben Ramsey

Other Decks in Programming

Transcript

  1. Ben Ramsey ■ ZendCon ■ 16 Sep 2008
    Distribution and Publication
    With Atom Web Services

    View Slide

  2. Ben Ramsey ■ ZendCon ■ 16 Sep 2008 ■
    Distribution and Publication With Atom Web Services
    Hi, I’m Ben Ramsey.
    2

    View Slide

  3. Ben Ramsey ■ ZendCon ■ 16 Sep 2008 ■
    Distribution and Publication With Atom Web Services
    3
    Software Architect
    Organizer of Atlanta PHP user group
    Co-author of php|architect’s Zend PHP 5
    Certification Study Guide
    HTTP pedant and advocate of RESTful web
    applications

    View Slide

  4. Ben Ramsey ■ ZendCon ■ 16 Sep 2008 ■
    Distribution and Publication With Atom Web Services
    Distribution
    4

    View Slide

  5. Ben Ramsey ■ ZendCon ■ 16 Sep 2008 ■
    Distribution and Publication With Atom Web Services
    To deliver or pass out something
    5

    View Slide

  6. Ben Ramsey ■ ZendCon ■ 16 Sep 2008 ■
    Distribution and Publication With Atom Web Services
    Publication
    6

    View Slide

  7. Ben Ramsey ■ ZendCon ■ 16 Sep 2008 ■
    Distribution and Publication With Atom Web Services
    To issue something for distribution
    7

    View Slide

  8. Ben Ramsey ■ ZendCon ■ 16 Sep 2008 ■
    Distribution and Publication With Atom Web Services
    8
    Distribution
    Publication

    View Slide

  9. Ben Ramsey ■ ZendCon ■ 16 Sep 2008 ■
    Distribution and Publication With Atom Web Services
    9
    Content
    Store
    Web
    Service
    Clients

    View Slide

  10. Ben Ramsey ■ ZendCon ■ 16 Sep 2008 ■
    Distribution and Publication With Atom Web Services
    10
    Content
    Store
    Web
    Service
    Clients

    View Slide

  11. Ben Ramsey ■ ZendCon ■ 16 Sep 2008 ■
    Distribution and Publication With Atom Web Services
    Over a network, we’ll use HTTP
    for distribution and publication.
    11

    View Slide

  12. Ben Ramsey ■ ZendCon ■ 16 Sep 2008 ■
    Distribution and Publication With Atom Web Services
    Constrained interface
    Client-server
    Stateless
    Cacheable
    Layered
    12

    View Slide

  13. Ben Ramsey ■ ZendCon ■ 16 Sep 2008 ■
    Distribution and Publication With Atom Web Services
    HTTP is RESTful.
    13

    View Slide

  14. Ben Ramsey ■ ZendCon ■ 16 Sep 2008 ■
    Distribution and Publication With Atom Web Services
    What is REST?
    14

    View Slide

  15. Ben Ramsey ■ ZendCon ■ 16 Sep 2008 ■
    Distribution and Publication With Atom Web Services
    “REST strictly refers to a collection of network
    architecture principles which outline how
    resources are defined and addressed.”
    — Wikipedia
    15

    View Slide

  16. Distribution and Publication With Atom Web Services
    Ben Ramsey ■ ZendCon ■ 16 Sep 2008 ■
    What is REST?
    Representational State Transfer
    Not an architecture or a standard for
    developing web services
    Not a particular format or pattern
    It is a set of design principles
    16

    View Slide

  17. Distribution and Publication With Atom Web Services
    Ben Ramsey ■ ZendCon ■ 16 Sep 2008 ■
    Principles of REST
    Application state and functionality
    abstracted into resources
    Resources are uniquely addressable
    Resources share a uniform interface for
    transfer of state:
    Constrained set of operations
    Constrained set of content types
    17

    View Slide

  18. Distribution and Publication With Atom Web Services
    Ben Ramsey ■ ZendCon ■ 16 Sep 2008 ■
    Principles of REST
    A protocol that is:
    Client-server
    Stateless
    Cacheable
    Layered
    18

    View Slide

  19. Ben Ramsey ■ ZendCon ■ 16 Sep 2008 ■
    Distribution and Publication With Atom Web Services
    A resource-oriented architecture is RESTful.
    19

    View Slide

  20. Distribution and Publication With Atom Web Services
    Ben Ramsey ■ ZendCon ■ 16 Sep 2008 ■
    Resource-oriented architecture
    Resources
    Their names (addresses)
    Their representations
    The links between them
    20

    View Slide

  21. Ben Ramsey ■ ZendCon ■ 16 Sep 2008 ■
    Distribution and Publication With Atom Web Services
    “A resource can be anything that has identity.
    Familiar examples include an electronic
    document, an image, a service (e.g., ‘today’s
    weather report for Los Angeles’), and a
    collection of other resources. Not all resources
    are network ‘retrievable’; e.g., human beings,
    corporations, and bound books in a library can
    also be considered resources.”
    — RFC 2396
    21

    View Slide

  22. Distribution and Publication With Atom Web Services
    Ben Ramsey ■ ZendCon ■ 16 Sep 2008 ■
    ROA basics
    Each resource knows how to do three
    simple things:
    1. Represent itself to the client
    2. Transition from one state to the next
    3. Destroy itself
    Additionally, the ROA provides a means to
    create a resource
    22

    View Slide

  23. Distribution and Publication With Atom Web Services
    Ben Ramsey ■ ZendCon ■ 16 Sep 2008 ■
    ROA properties
    Resources are addressable
    Resources have no state
    Resources are connected
    Resources share the same interface
    23

    View Slide

  24. Ben Ramsey ■ ZendCon ■ 16 Sep 2008 ■
    Distribution and Publication With Atom Web Services
    This is REST in a nutshell.
    24

    View Slide

  25. Ben Ramsey ■ ZendCon ■ 16 Sep 2008 ■
    Distribution and Publication With Atom Web Services
    What is Atom?
    25

    View Slide

  26. Ben Ramsey ■ ZendCon ■ 16 Sep 2008 ■
    Distribution and Publication With Atom Web Services
    “The name Atom applies to a pair of related
    standards. The Atom Syndication Format is an
    XML language used for web feeds, while the
    Atom Publishing Protocol (short AtomPub or
    APP) is a simple HTTP-based protocol for
    creating and updating web resources.”
    — Wikipedia
    26

    View Slide

  27. Ben Ramsey ■ ZendCon ■ 16 Sep 2008 ■
    Distribution and Publication With Atom Web Services
    Atom is both a format and a protocol.
    27

    View Slide

  28. Distribution and Publication With Atom Web Services
    Ben Ramsey ■ ZendCon ■ 16 Sep 2008 ■
    The Atom format
    An XML-based web content and metadata
    syndication format
    Defined by RFC 4287
    Developed as an open alternative to the
    “frozen” RSS 2.0 format
    XML namespace:
    http://www.w3.org/2005/Atom
    28

    View Slide

  29. Distribution and Publication With Atom Web Services
    Ben Ramsey ■ ZendCon ■ 16 Sep 2008 ■
    The Atom Publishing Protocol
    An application-level protocol for publishing
    and editing web resources using HTTP and
    XML
    Defined by RFC 5023
    Also called “AtomPub” or “APP”
    XML namespace:
    http://www.w3.org/2007/app
    29

    View Slide

  30. Distribution and Publication With Atom Web Services
    Ben Ramsey ■ ZendCon ■ 16 Sep 2008 ■
    A common format
    Widespread adoption means increased
    interoperability between disparate systems
    Applications now have a common language
    and publishing protocol, leveraging HTTP
    as a vehicle
    Supported by a diverse and wide-reaching
    community through libraries for consuming
    and creating Atom services
    30

    View Slide

  31. Distribution and Publication With Atom Web Services
    Ben Ramsey ■ ZendCon ■ 16 Sep 2008 ■
    Principles of Atom
    Resource-oriented
    Discovery of resource relationships
    Categorization of resources
    Provides service auto-discovery
    Support for all content types
    Content can be published
    31

    View Slide

  32. Distribution and Publication With Atom Web Services
    Ben Ramsey ■ ZendCon ■ 16 Sep 2008 ■
    Atom is resource-oriented
    Think of an Atom web service as a catalog
    of resources that you want to expose
    Each piece of content in your system is a
    resource
    Each resource has a unique identifier
    The resources have no state
    They are cacheable
    They are connected
    They share the same interface: HTTP verbs
    32

    View Slide

  33. Distribution and Publication With Atom Web Services
    Ben Ramsey ■ ZendCon ■ 16 Sep 2008 ■
    Atom exposes relationships
    Atom documents are connected through
    links
    Links can have defined relationships:
    alternate
    related
    self
    enclosure
    via
    33

    View Slide

  34. Distribution and Publication With Atom Web Services
    Ben Ramsey ■ ZendCon ■ 16 Sep 2008 ■
    Atom categorizes resources
    Atom documents may belong to multiple
    categories
    Categories belong to namespaces
    Categories are very flexible; up to
    implementor to decide how to use them
    APP category documents expose
    categories, optionally defining limitations
    34

    View Slide

  35. Distribution and Publication With Atom Web Services
    Ben Ramsey ■ ZendCon ■ 16 Sep 2008 ■
    Atom provides auto-discovery
    APP service documents expose the
    collections of an Atom web service
    Service documents provide flexible
    workspaces for the implementor to define
    May define endpoints for publication of
    resources, acceptable content types, and
    categories
    35

    View Slide

  36. Distribution and Publication With Atom Web Services
    Ben Ramsey ■ ZendCon ■ 16 Sep 2008 ■
    Atom delivers content
    Collection documents (feeds) deliver lists of
    resources
    Collection documents can be paginated to
    allow paging through content
    Entry documents deliver individual
    resources, describing relationships with
    other resources and providing links to follow
    to more content
    36

    View Slide

  37. Distribution and Publication With Atom Web Services
    Ben Ramsey ■ ZendCon ■ 16 Sep 2008 ■
    Atom publishes content
    Individual entries may be published to an
    Atom web service to add or update content
    Atom allows for the deletion or removal of
    content entries
    Atom is flexible enough to allow for whole
    collection documents to be published,
    perhaps creating or updating many
    resources at one time
    37

    View Slide

  38. Ben Ramsey ■ ZendCon ■ 16 Sep 2008 ■
    Distribution and Publication With Atom Web Services
    Distribution with Atom
    38

    View Slide

  39. Distribution and Publication With Atom Web Services
    Ben Ramsey ■ ZendCon ■ 16 Sep 2008 ■
    Atom terminology
    Entry
    Feed
    Collection
    Category Document
    Service Document
    39

    View Slide

  40. Distribution and Publication With Atom Web Services
    Ben Ramsey ■ ZendCon ■ 16 Sep 2008 ■
    Entry
    Represents an individual piece of content
    (post, article, page, image, video,
    document, etc.)
    Entries can be related to other entries or
    feeds
    This resource represents a specific resource
    (i.e. http://example.org/posts/1234)
    Content type:
    application/atom+xml;type=entry
    40

    View Slide

  41. Ben Ramsey ■ ZendCon ■ 16 Sep 2008 ■
    Distribution and Publication With Atom Web Services
    41

    View Slide

  42. Distribution and Publication With Atom Web Services
    Ben Ramsey ■ ZendCon ■ 16 Sep 2008 ■
    Feed
    Represents a collection of Atom entries
    Feeds can be related to other feeds or
    entries
    This resource represents a specific
    collection of resources (i.e. http://
    example.org/posts)
    Atom collections are feeds
    Content type:
    application/atom+xml;type=feed
    42

    View Slide

  43. Ben Ramsey ■ ZendCon ■ 16 Sep 2008 ■
    Distribution and Publication With Atom Web Services
    43

    View Slide

  44. Distribution and Publication With Atom Web Services
    Ben Ramsey ■ ZendCon ■ 16 Sep 2008 ■
    Category
    Categories provide metadata to describe an
    Atom entry; Atom itself doesn’t define
    usage of categories
    Category documents describe the
    categories that are allowed in collections
    Content type:
    application/atomcat+xml
    44

    View Slide

  45. Ben Ramsey ■ ZendCon ■ 16 Sep 2008 ■
    Distribution and Publication With Atom Web Services
    45

    View Slide

  46. Distribution and Publication With Atom Web Services
    Ben Ramsey ■ ZendCon ■ 16 Sep 2008 ■
    Service
    A service discovery document that
    describes the locations and capabilities of
    collections
    Usually the entry point of the Atom web
    service
    Content type:
    application/atomsvc+xml
    46

    View Slide

  47. Ben Ramsey ■ ZendCon ■ 16 Sep 2008 ■
    Distribution and Publication With Atom Web Services
    47

    View Slide

  48. Ben Ramsey ■ ZendCon ■ 16 Sep 2008 ■
    Distribution and Publication With Atom Web Services
    Publication with Atom
    48

    View Slide

  49. Distribution and Publication With Atom Web Services
    Ben Ramsey ■ ZendCon ■ 16 Sep 2008 ■
    Creating resources
    Client “discovers” the resource through
    which the Atom service accepts POST
    requests to create resources (defined by
    app:collection)
    Client sends resource in POST request:
    POST /archives HTTP/1.1
    Client receives a 201 Created response in
    the event of a success
    49

    View Slide

  50. Distribution and Publication With Atom Web Services
    Ben Ramsey ■ ZendCon ■ 16 Sep 2008 ■
    Modifying resources
    Client requests a representation of the
    resource:
    GET /archives/1234 HTTP/1.1
    Client modifies the resource and tells the
    service to update it:
    PUT /archives/1234 HTTP/1.1
    Service responds with a 200 OK status to
    indicate success
    Client uses “edit” relation for this logic
    50

    View Slide

  51. Distribution and Publication With Atom Web Services
    Ben Ramsey ■ ZendCon ■ 16 Sep 2008 ■
    Removing resources
    Client sends a DELETE request to the
    sevice:
    DELETE /archives/1234 HTTP/1.1
    Service responds with a 204 No Content
    status code to indicate success
    51

    View Slide

  52. Distribution and Publication With Atom Web Services
    Ben Ramsey ■ ZendCon ■ 16 Sep 2008 ■
    Authentication
    Atom does not provide or recommend an
    auth mechanism
    Early favorite of the Atom community was
    WSSE
    Consider the use of OAuth
    Send authentication info through HTTP
    headers on each request requiring
    authenticated access
    52

    View Slide

  53. Distribution and Publication With Atom Web Services
    Ben Ramsey ■ ZendCon ■ 16 Sep 2008 ■
    Encryption
    Atom does not provide for encryption
    Use SSL for all sensitive communication
    Atom Entry and Feed Documents can
    contain XML Digital Signatures
    Can be encrypted using XML Encryption
    53

    View Slide

  54. Distribution and Publication With Atom Web Services
    Ben Ramsey ■ ZendCon ■ 16 Sep 2008 ■
    Extending Atom
    Atom is XML; as such, it may be extended
    using other vocabularies (namespaces)
    Use other namespaces to convey other
    information
    e.g. OpenSearch
    e.g. Dublin Core
    54

    View Slide

  55. Distribution and Publication With Atom Web Services
    Ben Ramsey ■ ZendCon ■ 16 Sep 2008 ■
    Parsing Atom
    DOM, XMLReader, XMLWriter, SimpleXML
    Zend_Feed, PEAR::XML_Feed_Parser,
    phpatomlib
    Apache Abdera
    55

    View Slide

  56. Distribution and Publication With Atom Web Services
    Ben Ramsey ■ ZendCon ■ 16 Sep 2008 ■
    Out-of-box Atom clients
    Fude -
    http://www.witha.jp/eXeries/software/
    Atomic (Firefox plugin) -
    https://addons.mozilla.org/en-US/firefox/addon/3188
    APP Test Client -
    http://bitworking.org/projects/apptestclient/
    56

    View Slide

  57. Distribution and Publication With Atom Web Services
    Ben Ramsey ■ ZendCon ■ 16 Sep 2008 ■
    For more information...
    http://tools.ietf.org/html/rfc4287
    http://tools.ietf.org/html/rfc5023
    http://atomenabled.org/
    My blog: http://benramsey.com/
    57

    View Slide