XML technologies / RSS & Atom / Atom / Publishing with the Atom Publishing Protocol / Extensions
(Excerpt from "Newsfeeds with RSS and Atom" by Heinz Wittenbrink, published by Galileo Press, 2005)
Extensions should meet the following requirements:
They must support automatic discovery so that clients can find them without users having to deal with technical details.
They must inform clients of the capabilities they provide if these are not already inherent in the service itself.
Exchanging data with the server should be no harder than for Atom’s core functionality.
An extension must not disrupt other functionality.
The Atom Publishing Protocol uses the same mechanisms for extensions as for its core functionality: communication with the server uses URIs and HTTP methods. Clients can discover available methods in a file provided by the server and receive information from it. Server resources are modified through XML documents in HTTP request and response bodies. Syntactically, namespaces are used to extend existing document formats as needed.
One way to extend the API is the familiar approach of extending the Atom Syndication Format using the namespace mechanism. Pilgrim gives the following entry as an example, using and integrating Movable Type’s commenting functionality:
POST /myblog/atom.cgi HTTP/1.1
Host: example.com
Content-Type: application/x.atom+xml
<?xml version="1.0" encoding="utf-8"?>
<entry xmlns=http://purl.org/atom/ns# xmlns:mt="http://www.movabletype.org/atom/ns#">
<title>My Entry Title</title>
<created>2003–11–17T12:29:29Z</created>
<mt:allowComments>1</mt:allowComments>
<content type="application/xhtml+xml" xml:lang="en">
<div xmlns="http://www.w3.org/1999/xhtml">
<p>Hello, <em>weblog</em> world!</p>
</div>
</content>
</entry>
When an entry is modified, a corresponding modification date is recorded.
The request header looks like this:
PUT /myblog/atom.cgi/edit/1 HTTP/1.1
Host: example.com
Content-Type: application/x.atom+xml
The server responds with:
HTTP/1.1 205 Reset Content
The corresponding messages for deleting an entry are:
DELETE /myblog/atom.cgi/edit/3 HTTP/1.1
Host: example.com
And
HTTP/1.1 200 OK
In Extending the AtomAPI Joe Gregorio uses another example. LiveJournal users can specify their current mood ("mood") when writing an entry. This feature is also supported by the XML-RPC interface offered by LiveJournal.
To extend the API, first define a namespace different from that of the core elements, for example some.lj.example.com/namespace/. It is then important to know whether an Atom implementation supports the extension and what capabilities it offers. For moods, the server should tell the client which moods are available. Support can be indicated by extending the introspection file or the feed retrieved via FeedURI, specifying a separate URI for the extension. Gregorio’s example of the corresponding fragment of the introspection file is:
<introspection xmlns="http://example.com/newformat#" xmlns:lj="some.lj.example.com/namespace/">
<create-entry>http://example.org/reilly/</create-entry>
<user-prefs>http://example.org/reilly/prefs</user-prefs>
<search-entries>http://example.org/reilly/search</search-entries>
<lj:moods>http://example.org/reilly/moods</lj:moods>
</introspection>
A GET request to that URI returns a document listing the available URIs:
<moods xmlns="some.lj.example.com/namespace/">
<mood>happy</mood>
<mood>sad</mood>
<mood>angry</mood>
</moods>
The client now knows that the server supports the mood feature and which values are possible. All that remains is to include a mood in an entry’s content. This again uses an element with an appropriate namespace, which is not the same as the service’s own namespace. Gregorio gives the following example:
<entry xmlns="http://example.com/newformat#" xmlns:lj="some.lj.example.com/namespace/" >
<title>My First Entry</title>
<subtitle>In which a newbie learns to blog...</subtitle>
<summary>A very boring entry...</summary>
<author>
<name>Bob B. Bobbington</name>
<homepage>http://bob.name/</homepage>
<weblog>http://bob.blog/</weblog>
</author>
<issued>2003–02–05T12:29:29</issued>
<lj:mood>happy</lj:mood>
<content type="application/xhtml+xml" xml:lang="en-us">
<p xmlns="...">Hello, <em>weblog</em> world! 2 < 4!</p>
</content>
</entry>
A server that does not support an extension does not list its service in the introspection file. A client that does not support it does not look for it there. Unsupported extensions therefore go unnoticed by the software and cannot disrupt it.

This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.