Previous Page Arrow Next Page Arrow

Links

SData Links are JSON objects that provide the information necessary to operate on a resource. 5

SData Links also convey the operational capabilities on a resource. If links are provided for the creation of a resource, the operation-related specifications like canPost (see the SData 1.1 standard, sme.xsd) become redundant. Other capabilities (like canFilter for example) are gathered in the $capabilities metadata element.

This chapter describes in turn:

  • The standard SData links; these cover the CRUD operations on a resource.
  • The components of an SData link.
  • The links to services and queries related to a resource.

The usage of links and the definition of a $links object is OPTIONAL.

SData defines the following standard link objects:

Description
$createLink used to create a new resource.
$deleteLink used to delete an existing resource.
$updateFullLink used to update a resource by providing all its contents.
$updatePartialLink used to update only a selected subset of the properties of a resource.
$detailsLink used to retrieve a single resource (the response will contain an entry).
$listLink used to retrieve a set of resources (the response will contain a feed).
$lookupLink used to retrieve a set of resources to be used to populate a list of choices. This corresponds to the sdata:lookup defined in the SData 1.1 specification section 6.7.
$prototypeLink used to retrieve the prototype associated with a representation - see $prototype object Section for information on prototypes.

Any of the above links MAY be present within an SData payload.

An SData Link object consists of several properties aiming to decouple the consumer from a provider. These are:

Description
$urlMUSTThe URL pointing to a resource.
$methodMAYHTTP method used to operate on the resource. - default : GET
$titleSHOULDLocalized label/caption for the link.
$idMAYMAY be used to identify a link in a specific context. This property MUST be set for prototype links if several prototypes are available for a resource.
$bodyMAYThe object containing the payload transported to the provider alongside the request.
$invocationMAYThe manner in which the provider should process the request 6.
Allowable values are:
  • sync [default],
  • async,
  • syncOrAsync.
$batchMAYExpresses the manner of invocations supported in batch by the provider.
Allowable values are:
  • false [default]: indicates batching is not supported,
  • true.
$requestMAYContains either:
  1. URL of a prototype (see SData prototypes Section)
  2. JSON object containing the description of request's individual parameters.
The omission of $request indicates that the request has no parameters. Should parameters exist, their description is found in the contained $properties object.
An individual parameter object has a unique name and contains the following properties:
  • $title [optional]: human-readable parameter name.
  • $type [mandatory]: defines the type of the parameter.
$responseMAY Contains either
  1. URL of a prototype (see SData prototypes Section)
  2. JSON object containing the description of request's expected response. The description of the properties returned by the provider is found in the enclosed $properties object
$typeMAYThe SData type(application/json;vnd.sage=sdata) or MIME type of the resource. If omitted, the contract default is returned

Example: Consider an SData object that exposes links for deletion and update operations. This would be expressed as:

{
    "$links": {
        "$updateFull": {
            "$title": "Update the resource",
            "$type": "application/json;vnd.sage=sdata",
            "$url": "{$url}",
            "$method": "PUT"
        },
        "$delete": {
            "$title": "Delete this resource",
            "$type": "application/json;vnd.sage=sdata",
            "$url": "{$url}",
            "$method": "DELETE"
        }
    }
}

The URL used is the same with the URL of the resource in this case. The {$url} notation indicates a replacement with a resource value as explained in section Substitution formalism of this document.

Links are used to express services and queries delivered by a provider, as defined in the SData specification section 11 and section 12. In this case, the name of the link object corresponds to the desired query/service.

Examples: The following is the link accessing the createBOM service returning the bill of materials associated with a sales order.

{
    "$links": {
        "createBOM": {
            "$title": "Create Bill of Materials",
            "$url": "{$url}/$service/createBOM",
            "$method": "POST",
            "$response": "{$baseUrl}/$prototypes/createBOM",
            "$invocation": "syncOrAsync"
        }
    }
}

In addition to the URL and appropriate HTTP method, the link indicates the structure of the response (by means of a prototype which is discussed later in this document) as well as the fact that the server may choose whether the service is to be performed in a synchronous or an asynchronous manner.

The following is an example showing an SData query associated with a Products resource kind (described in the SData documentation Example of Named Query):

{
    "$links": {
        "reOrder": {
            "$title": "List of products to be reordered",
            "$url": "{$url}/$queries/reorder",
            "$method": "GET",
            "$request": {
                "$properties": {
                    "family": {
                        "$title": "product category",
                        "$type": "sdata/string"
                    },
                    "threshold": {
                        "$title": "minimal in-stock threshold",
                        "$type": "sdata/integer"
                    }
                }
            },
            "$response": {
                "$type": "sdata/array",
                "$item": {
                    "$properties": {
                        "productID": {
                            "$title": "Product ID",
                            "$type": "sdata/string"
                        },
                        "description": {
                            "$title": "Description",
                            "$type": "sdata/string"
                        },
                        "inStock": {
                            "$title": "Quantity in stock",
                            "$type": "sdata/integer"
                        }
                    }
                }
            }
        }
    }
}

The reOrder named query provides a list of products with stock below a certain threshold value. The specification of the query contains the $request object that contains a description of the two parameters accepted by the query, namely family and threshold. It also describes the structure of the return with the three properties: productID, description and inStock.


5. SData Links are a specific embodiment of Roy Fielding’s hypermedia controls (enabling “Hypermedia as the Engine of Application State” or HATEOAS); Fielding’s indication to REST application designers is that operations (state transfer) be driven by hypertext. Link constructs (as known from HTML and ATOM) appear to be an appropriate means to do this.
6. This should not be confused with client-side AJAX requests. The mechanism corresponds to the sme:invocationMethod described in section 11.4 and 11.5 of the SData 1.1 standard

Previous Page Arrow Next Page Arrow