Previous Page Arrow Next Page Arrow

8.2 Use of $template URL

The $template URL returns a fresh resource that has been prepared with the application’s default values. This URL is useful if you want to set up the default values in a “create resource” form. For example, a UI consumer can  do a GET on the following URL to fill a “Create Sales Order” form:

GET /sdata/myApp/myContract/-/salesOrders/$template

This GET operation returns a response such as:

200 OK
Content-Type: application/atom+xml; type=entry
<entry xmlns:sdata="" 
  <title>Sales Order 43660</title>

  <link rel="self" type="application/atom+xml; type=entry" title="Refresh" 
        href="$template" />
  <link rel="" 
        type="application/xml" title="Schema" 
        href="$schema?version=5" />
  <link rel="" 
        type="application/atom+xml; type=entry" title="Template" 
        href="$template" />
  <link rel="" 
        type="application/atom+xml; type=entry" title="Post" 
        href="" />
  <link rel="" 
        type="application/atom+xml; type=feed" title="Service" 
        href="$service" />

  <category scheme="" 
            term="resource" label="Resource"/>


    <salesOrder xmlns="">

The response payload only includes properties that have default values that are different to their datatype’s default value (0, nil). In the example, only <orderDate> is returned and it is set to the current date by the provider.

This GET operation does not create any resource, it just returns an atom entry containing default values. The $template URL can be seen as a _virtual resource_ URL.

The consumer could request the template to include templates for child resources. For example, the following URL:

GET /sdata/myApp/myContract/-/salesOrders/$template?include=orderLines

….would return a slightly richer payload:

    <salesOrder xmlns="">
SData providers MUST support GET operations on the $template URL of all resources kinds that have the sme:canPost attribute set to true  (see Resource Kind Definition).

Previous Page Arrow Next Page Arrow