Skip to main content

Creating a new page

Creating a new page in the Atom Publishing Protocol is represented by sending a HTTP POST to a collection with an Atom document representing the new page. An example Atom representation of a new Sitebuilder page might be as follows:

<?xml version="1.0" encoding="UTF-8"?>
<entry xmlns="http://www.w3.org/2005/Atom" xmlns:sitebuilder="http://go.warwick.ac.uk/elab-schemas/atom">
  <title>Here is my edited page</title>
  <content type="html">
    &lt;h2&gt;Hello World!&lt;/h2&gt;
    &lt;p&gt;Here is my newly created page&lt;/p&gt;
  </content>
  <sitebuilder:page-name>mynewpage</sitebuilder:page-name>
  <sitebuilder:searchable>false</sitebuilder:searchable>
  <sitebuilder:visible>false</sitebuilder:visible>
  <sitebuilder:description>A test of the ATOM representation of a page</sitebuilder:description>
  <sitebuilder:keywords>api tests, atom</sitebuilder:keywords>
</entry>

Note a few things here:

  • We specify a Sitebuilder XML Schema at http://go.warwick.ac.uk/elab-schemas/atom - this allows us to set Sitebuilder-specific properties. These are always optional
  • The <title> element contains the Page heading for the new page
  • The <sitebuilder:page-name> element is the final part of the URL for our new page. We specify that we want the URL to end /mynewpage
  • The <sitebuilder:searchable> element specifies whether our new page should be visible in search engines
  • The <sitebuilder:visible> element specifies whether our new page should be visible in local navigation
  • The <sitebuilder:description> element specifies the page's description
  • The <sitebuilder:keywords> element specifies the keywords associated with the page in a comma-separated list

We don't actually need to include everything here at all - the only required element is <title>. If we only include that, the URL of the page will be calculated from the title itself, and the page will be empty. You can see a fuller list of supported properties in Changing page properties.

In order to create this page, we need to POST it to the Collection of the parent page. So if we want to create our new page at /fac/sci/chemistry/mynewpage, we need to POST it to the Collection page for /fac/sci/chemistry. We can see an example response in cURL (newpage.atom is a file containing the content of the Atom document above):

mat@augustus:~$ curl -i -X POST --data-binary @newpage.atom -H 'Content-Type: application/atom+xml' -u cuscav
   "https://sitebuilder.warwick.ac.uk/sitebuilder2/edit/atom/atom.htm?page=/fac/sci/chemistry&type=list"
Enter host password for user 'cuscav':

HTTP/1.1 201 Created
Date: Tue, 22 Mar 2011 10:35:24 GMT
Server: Penny
Location: https://sitebuilder.warwick.ac.uk/sitebuilder2/edit/atom/atom.htm?page=/fac/sci/chemistry/mynewpage&type=single
Content-Type: application/atom+xml;charset=ISO-8859-1
Content-Length: 1266
Vary: User-Agent

<?xml version="1.0" encoding="UTF-8"?>
<entry xmlns="http://www.w3.org/2005/Atom" xmlns:sitebuilder="http://go.warwick.ac.uk/elab-schemas/atom">
  <title>Here is my edited page</title>
  <link rel="collection" 
    href="https://sitebuilder.warwick.ac.uk/sitebuilder2/edit/atom/atom.htm?page=/fac/sci/chemistry/mynewpage&type=list" />
  <link rel="edit" 
    href="https://sitebuilder.warwick.ac.uk/sitebuilder2/edit/atom/atom.htm?page=/fac/sci/chemistry/mynewpage&type=single" />
  <link rel="alternate" 
    href="http://www2.warwick.ac.uk/fac/sci/chemistry/mynewpage" />
  <id>urn:uuid:094d43ed2eb4e006012edd22205e7f97</id>
  <content type="html">
    &lt;h2&gt;Hello World!&lt;/h2&gt;
    &lt;p&gt;Here is my newly created page&lt;/p&gt;
  </content>
  <author>
    <name>Mathew Mannion</name>
  </author>
  <updated>2011-03-22T10:35:24Z</updated>
  <published>2011-03-22T10:35:24Z</published>
  <sitebuilder:page-name>mynewpage</sitebuilder:page-name>
  <sitebuilder:searchable>false</sitebuilder:searchable>
  <sitebuilder:visible>false</sitebuilder:visible>
  <sitebuilder:deleted>false</sitebuilder:deleted>
  <sitebuilder:span-rhs>false</sitebuilder:span-rhs>
  <sitebuilder:description>A test of the ATOM representation of a page</sitebuilder:description>
  <sitebuilder:keywords>api tests, atom</sitebuilder:keywords>
</entry>  

Note: it is important to send the Content-Type header. Failing to send this header will lead to a 500 Internal Server Error.

Some interesting things from the response:

  • Sitebuilder sends a 201 Created response, informing the client that a new page has been created by the operation
  • The Location header contains the URL of the Atom representation of the newly created page
  • The response is the Atom representation of the new page (sending a GET request to the URL in the Location header will return the same content)