Data Page

The data page can be used to expose CRUD data operations. Using a Data Page you can:

  • Expose data in different formats (XML, JSON, HTML, CSV…) using GET and POST requests
  • Insert or update records using PUT requests
  • Delete records using DELETE requests

Attributes

DataStructure Data Structure the data will be based on.
Method Optional method (filter) to be used for getting the data.
SortSet Optional sort set using which the data will be sorted.
Transformation

Optional XSLT Transformation that will be used to transform the data returned by the data service using the DataStructure attribute.

If Transformation is omitted the result is the raw data as returned by the data service in a format depending on a specified MimeType:

  • application/xml - will produce an XML document
  • application/json - will produce a JSON document

If you want to provide data in another format you need to use the transformation to produce data in such a format. The above specified formats can be used without a transformation and data will be converted automatically.

When MimeType is application/json, please consider to define also TransformationOutputStructure.

TransformationOutputStructure A data structure where an output of the Transformation will be merged into. It's applied only when ResultXpath is not set and a MimeType field is set to application/json.If not defined, the final XML->JSON conversion after transformation works the following way: DataTypes - float, int, boolean, etc. are converted to a string and attributes are prefixed with @. But if defined, conversion is DataSet->JSON conversion, which performs the standard way (without transformation).
ResultXPath

In case you need a single value or only a subset of the produced data you can use an XPath expression to select only the data you need to return.

A string value of the resulting Xpath navigator is used. It's mainly used for extracting pure text out of the result XML. If it's set and application/json mime-type is set too, then the resulting JSON conversion is always done as a non-typed XML->JSON conversion (regardless of how Transformation and TransformationOutputStructure are set).

AllowPUT If set to True it will be possible to use a PUT HTTP request to send data back to the API to be saved to the database.
AllowDELETE If set to True it will be possible to use a DELETE HTTP request to send data back to the API to be deleted from the database.
SaveValidationBeforeMerge

A validation rule that will be called on the data loaded from the database before the data from input is merged.

SaveValidationAfterMerge

A validation rule that will be called after merging the data from a database with data from input. This can be used for validating the resulting (updated) data before saving them in a database.

You will probably have the same validation rule set up as a state event anyway so any data access is always validated but you can assign the same rule here because it is cheaper to stop the web request if it is invalid than locking data in the database and validating them later in the process.

LogTransformation An XSLT transformation that will produce enhanced logging data. For details see How to set up an event logging with Log Transformations.
OmitJsonRootElement

Applicable to media type JSON. If set to True the returned JSON string will not contain the root element converted from the XML representation (e.g. "ROOT").

OmitJsonMainElement

Available from 2024.7. Applicable to media type JSON. If set to True the returned JSON string will not contain the main element (root entity) converted from the XML representation.

Updating And Inserting Data

When you want to send JSON or XML data back to the API in the HTTP request body you need to:

  1. Set AllowPUT to True.
  2. Add a new ParameterMapping under the Data Page API with any name and MappedParameter empty. This will pass the body to the API.
  3. Send the request under the same URL you used to load the data, e.g. /api/invoice/1234

It is recommended to set AllFields=True in the source data structure entities otherwise concurrency exceptions can occur.

The process then goes like this:

  1. When you send a PUT request to /api/invoice/1234 first the old invoice no. 1234 is loaded from the database
  2. Then the data of the old invoice are updated with the data sent with the request
  3. Then the changes are saved to the database.

If you want to insert data you need to provide a parameter under which no invoice will be loaded, e.g. /api/invoice/new. The first step which loads the record will find nothing resulting in INSERTs into the database.

The server has to be set to run all managed modules for all requests, otherwise put operation will fail because of unauthorized access.

<modules runAllManagedModulseForAllRequest="true">

</modules>

Pagination

You can use built-in data pagination functions to return pages of data instead of whole lists. See LoadData Method for details.

You need to map the input parameters to the internal _pageNumber and _pageSize parameters the same way you would map other parameters. See Kendo Mobile - Pagination And Server-Side Filtering for an example.

Deleting Data

When you want to send a request that will delete data you need to:

  1. Set AllowDELETE to True
  2. Send a request to the URL, e.g. /api/invoice/1234
  3. The data will get loaded and then deleted.

Concurrency Handling

As you see from the previous example there is no concurrency handling built-in and the last write wins.