The Cloud Servers API supports both the JSON and XML
data serialization formats. The request format is
specified using the Content-Type header
and is required for operations that have a request
body. The response format can be specified in requests
using either the Accept header or adding
an .xml or .json extension to the request URI. Note
that it is possible for a response to be serialized
using a format different from the request (see example
below). If no response format is specified, JSON is
the default. If conflicting formats are specified
using both an Accept header and a query
extension, the query extension takes precedence.
| Format | Accept Header | Query Extension | Default |
| JSON | application/json | .json | Yes |
| XML | application/xml | .xml | No |
Example 2.5. Request with Headers: JSON
POST /v1.0/214412/images HTTP/1.1
Host: servers.api.rackspacecloud.com
Content-Type: application/json
Accept: application/xml
X-Auth-Token: eaaafd18-0fed-4b3a-81b4-663c99ec1cbb
{
"image" : {
"serverId" : 12,
"name" : "Just in case"}
}
Example 2.6. Response with Headers: XML
HTTP/1.1 200 OKAY
Date: Mon, 12 Nov 2007 15:55:01 GMT
Server: Apache
Content-Length: 185
Content-Type: application/xml; charset=UTF-8
<image xmlns="http://docs.rackspacecloud.com/servers/api/v1.0"
id="22" name="Just in case" serverId="12"
created="2010-10-10T12:00:00Z"
status="SAVING" progress="0" />
Notice, in the above example, that the content type
is set to application/json but application/xml is
requested through the Accept header. An
alternative method of achieving the same result is
illustrated below – this time we utilize a URI
extension instead of an Accept header.
Example 2.7. Request with Extension: JSON
POST /v1.0/214412/images.xml HTTP/1.1
Host: servers.api.rackspacecloud.com
Content-Type: application/json
X-Auth-Token: eaaafd18-0fed-4b3a-81b4-663c99ec1cbb
{
"image" : {
"serverId" : 12,
"name" : "Just in case"}
}

