The Atom Publishing Protocol

Joe Gregorio

BitWorking, Inc

The Structure of the Presentation

Why Blogging APIs?

?

History of Blogging APIs

LiveJournal

LiveJournal (Example Request)

POST /interface/flat HTTP/1.0
Host: www.livejournal.com
Content-type: application/x-www-form-urlencoded
Content-length: 34

mode=login&user=test&password=test

LiveJournal (Example Response)

HTTP/1.1 200 OK
Date: Sat, 23 Oct 1999 21:32:35 GMT
Server: Apache/1.3.4 (Unix)
Connection: close
Content-Type: text/plain

name
Mr. Test Account
success
OK
message
Hello Test Account!

LiveJournal Capabilities

There are other capabilities relating to 'friend' management.

LiveJournal

While not a major protocol today it set the pattern for many of the publishing APIs that would follow.

LiveJournal - Everything in POST

XML-RPC

XML-RPC Example Request

POST /RPC2 HTTP/1.0
User-Agent: Frontier/5.1.2 (WinNT)
Host: betty.userland.com
Content-Type: text/xml
Content-length: 181

<?xml version="1.0"?> 
<methodCall> 
   <methodName>examples.getStateName</methodName> 
   <params> 
      <param> 
        <value>
          <i4>41</i4>
       </value> 
     </param> 
   </params> 
</methodCall> 

XML-RPC Request Body

<?xml version="1.0"?> 
<methodCall> 
   <methodName>examples.getStateName</methodName> 
   <params> 
      <param> 
        <value>
          <i4>41</i4>
       </value> 
     </param> 
   </params> 
</methodCall> 

XML-RPC

XML-RPC follows the same patterns that the LiveJournal API set.

In addition, for most of the life of the XML-RPC specification, the content of 'string' parameters transported via XML-RPC were restricted to ASCII.

XML-RPC Protocols

Despite those weaknesses several popular APIs were built on ..

API is the wrong term.

XML-RPC Based Protocols

XML-RPC Based Protocols Evolution

XML-RPC Based Protocol Weaknesses

Because they were built on top of XML-RPC, and because of design decisions in the protocols themselves, there are some weaknesses with all of the protocols listed.

Weakness - I18N

Weakness - Extensibility

Weakness - Authentication

Weakness - Features

Weakness - Poor utilization of HTTP

Weaknesses - Summary

Enter the Atom Publishing Protocol

Enter the Atom Publishing Protocol

Atom the IETF Working Group

Origins

Status

Protocol Charter

Workgroup Products

Atom Syndication Format Example

<?xml version="1.0" encoding="utf-8"?>
<feed version="NNN"
    xmlns="http://purl.org/...">
     <head>
       <title>Example Feed</title>
       <link href="http://example.org/"/>
       <updated>2003-12-13T18:30:02Z</updated>
       <author>
         <name>John Doe</name>
       </author>
     </head>
     <entry>
       <title>A Simple Title</title>
       <link href="http://example.org/2003/12/13/atom03"/>
       <id>vemmi://example.org/2003/32397</id>
       <updated>2003-12-13T18:30:02Z</updated>
       <content>This is the content of the entry. Lorem Ipsum Dolor...</content>
     </entry>
</feed>

Atom Syndication Format Highlights

Let's look closer at an 'entry'

<entry xml:ns="http://purl.org/...">
  <title>A Simple Title</title>
  <link href="http://example.org/2003/12/13/atom03"/>
 
  <author>
    <name>Marge Inoverrah</name>
  </author>

  <id>http://example.org/2003/32397</id>
  <updated>2003-12-13T18:30:02Z</updated>

  <published>2003-12-13T18:30:02Z</published>
	   
  <summary type="TEXT">The history and lore of Lorem Ipsum.</summary>

  <content type="TEXT">Lorem Ipsum Dolor...</content>
</entry>

The Entry

Common actions in the Atom Publishing Protocol

Resources

Edit

GET

Get a list of entries.

Did I mention GET?

Delete

Common actions in the Atom Publishing Protocol - Update

Common actions in the Atom Publishing Protocol - Create

Create Info Graphic

Atom Publishing Protocol Summary

Resource Method Description
Entry GET Get the latest
Entry PUT Update an entry
Entry DELETE Delete the entry
Entry Collection GET Get a list of entries
Entry Collection POST Create a new entry

Examples

Note: URIs are opaque in Atom.

Example - Get the Collection

Example - Get Collection - Request

GET /reilly/ HTTP/1.1
Host: example.org
Content-Type: application/atom+xml

Example - Get Collection - Response


HTTP/1.1 200 Ok
Content-Type: application/atom+xml
Content-Length: nnnn 

<?xml version="1.0" encoding="utf-8"?>
<feed version="NNN"
    xmlns="http://purl.org/...">
     <head>
       <title>Example Feed</title>
       <post href="http://example.org/reilly/"/>
       ...
     </head>
     <entry>
       <title>A Simple Title</title>
       <edit href="http://example.org/reilly/3"/>
       <content>This is the content of the entry. Lorem Ipsum Dolor...</content>
     </entry>
     ...
     <entry>
       <title>Another Simple Title</title>
       <edit href="http://example.org/reilly/1"/>
       <content>More content.</content>
     </entry>
</feed>

Example - Get Collection - Response

Example - Create a new Entry

Example - Create a new Entry - Request


POST /reilly HTTP/1.1
Host: example.org
Content-Type: application/atom+xml

<?xml version="1.0" encoding='utf-8'?>
<entry 
  xmlns="http://purl.org..." >  
  <title>My First Entry</title> 
  <summary>A very boring entry...</summary> 

  <author> 
    <name>Bob B. Bobbington</name> 
  </author> 

  <created>2003-02-05T12:29:29</created> 

  <content type="XHTML" xml:lang="en-us"> 
    <p xmlns="...">Hello, <em>weblog</em> world!</p> 
  </content>  
</entry> 

Example - Create a new Entry - Response

HTTP/1.1 201 Created
Location: http://example.org/reilly/4

Example - Deleting an entry

Example - Delete - Request

DELETE /reilly/4 HTTP/1.1
Host: example.org

Example - Delete - Response

HTTP/1.1 200 Ok

Example - Review

  • GET on the Entry Collection resource returned a Feed of the most recent entries.
  • POST on the Entry Collection resource creates a new Entry.
  • GET on the Entry resource returns the entry.
  • PUT on the Entry resource updates the entry.
  • DELETE on the Entry resource deletes the entry.

Compare and contrast with XML-RPC protocols

  • Document Literal
  • Using all the verbs
  • Each resource has it's own URI

Document Literal

  • The document is used on the wire.
  • No 'serialization'.
  • The same document extension mechanism is used for the protocol extension mechanism.

Using all the verbs

  • Since 99.9% of the web is GET, there are some optimizations.
  • GETs can be cached
  • GETs can be ETag'd
  • GET responses can be compressed

GET - gzip - Request

GET /reilly/4 HTTP/1.1
Host: example.org
Accept-Encoding: compress, gzip
Content-Type: application/atom+xml

Get - gzip - Response

HTTP/1.1 200 Ok
Content-Type: application/atom+xml
Content-Encoding: gzip

...gzipped stuff goes here...

Typically 1/3 of the original size.

GET - ETag - First Response

HTTP/1.1 200 Ok
Content-Type: application/atom+xml
ETag: 3948018403940943 

GET - ETag - Second Request

GET /reilly/4 HTTP/1.1
Host: example.org
If-Match: 3948018403940943
Content-Type: application/atom+xml

Get - ETag - Second Response

HTTP/1.1 304 Not Modified
Content-Type: application/atom+xml 

We've now reduced our response body by 100%

Get - ETag/gzip - Request

Guess what this does.

GET /reilly/4 HTTP/1.1
Host: example.org
If-Match: 3948018403940943
Accept-Encoding: compress, gzip
Content-Type: application/atom+xml 

We've now reduced our response body by 100% if the entry hasn't been updated, or reduced it by 66% if it has been updated.

Concurrent Updates

The ETag: header also provides for protection against concurrent updates. When we wanted to speed up GETs we provided an If-Match: header in the GET request. That same If-Match: header can be provided on a PUT request and the request will only succeed if the entry is unchanged from when the ETag was generated.

Authentication

See RFC 2617

See HTTPS/TLS

Each resource has it's own URI

Applications outside weblogs

  • Wikis
  • Each WikiWord is an Entry.
  • Entries can be sorted on most recently edited.
  • An Atom-Powered Wiki - http://www.xml.com/pub/a/2004/04/14/atomwiki.html

SixApart Extension for songs

POST /t/atom/lists/list_id=1 HTTP/1.1
Host: www.typepad.com

<?xml version="1.0" encoding="utf-8"?>
<entry xmlns="http://purl.org/..."
  xmlns:song="http://sixapart.com/atom/song#"
  xmlns:rvw="http://purl.org/NET/RVW/0.1/">
  <song:title>Lucky Star</song:title>
  <song:album>Kish Kash</song:album>
  <song:artist>Basement Jaxx</song:artist>
  <content>Good song.</content>
  <rvw:value>4</rvw:value>
</entry>

The End

  • The End

"Just" use WebDAV

  • The stated goal of the WebDAV working group is (from the charter) to "define the HTTP extensions necessary to enable distributed web authoring tools to be broadly interoperable, while supporting user needs", and in this respect DAV is completing the original vision of the Web as a writeable, collaborative medium.

That sounds pretty close to the Atom Publishing Protocol.

"Just" use WebDAV - Locking

  • Locking (concurrency control): long-duration exclusive and shared write locks prevent the overwrite problem, where two or more collaborators write to the same resource without first merging changes. To achieve robust Internet-scale collaboration, where network connections may be disconnected arbitrarily, and for scalability, since each open connection consumes server resources, the duration of DAV locks is independent of any individual network connection.

"Just" use WebDAV - Properties

  • Properties: XML properties provide storage for arbitrary metadata, such as a list of authors on Web resources. These properties can be efficiently set, deleted, and retrieved using the DAV protocol. DASL, the DAV Searching and Locating protocol, provides searches based on property values to locate Web resources.

"Just" use WebDAV - Properties

  • Namespace manipulation: Since resources may need to be copied or moved as a Web site evolves, DAV supports copy and move operations. Collections, similar to file system directories, may be created and listed.

Note that 'namespace' in this context refers to a servers URI namespace and not an XML namespace.