Page tree
Skip to end of metadata
Go to start of metadata

Available since Beta 4

Use this strategy to get viewentries (column values) from the view. This is the fastest way to get data from the view.

Allowed method

  • GET

Parameters:

  • databaseName(String databaseName): name of the database to read data from, use "server!!path/database.nsf" format; when omitted, current database is used
  • viewName(String viewName): name of the view; mandatory
  • keyVariableName(String keyVariableName): name of the variable name in route to read value from; mandatory

 

Let's assume our database has view called By Category.

router.GET('topics/category/{key}') {
   strategy(VIEWENTRIES_BY_CATEGORY_PAGED) {
      viewName('By Category')
      keyVariableName('key')
 }
   mapJson '@unid', json:'id', type:'STRING'
   mapJson '\$115', json:'topic', type:'STRING'
}

 

mapJson expects to get programmatic name of the column, json name and type (allowed types are STRING, DATETIME and DOUBLE, for multi-value columns use ARRAY_OF_STRING, ARRAY_OF_DATETIME and ARRAY_OF_DOUBLE).

If programmatic name contains $, you must escape it: \$

You can also use @unid to get universal id of the documents corresponding with the viewentries.

URL parameters:

  • count: number or records to return, default is 10
  • start: position in the view to start from, default value is 1

With route defined above, URL http://server.name/path-to/db.nsf/xsp/.xrest/topics/category/test?start=5&count=7 will return 7 viewentries (column values) under category "test" from view By Category starting at position 5.

 

Returned JSON:

{
    "entries": [
        {
            "id": "54502859C07299C7C12580D8006404F4",
            "topic": "updated from rest (Martin Jinoch)"
        },
        {
            "id": "FB0ABE3F113B5EE3C12580E100361BD1",
            "topic": "created from rest (Martin Jinoch [Anonymous])"
        },
        {
            "id": "CD4C360B5B275798C12580E100364A4B",
            "topic": "created from rest (Martin Jinoch [Anonymous])"
        },
        {
            "id": "EDA5D746AC3B64CEC12580E1003680AA",
            "topic": "created from rest (Martin Jinoch [Anonymous])"
        },
        {
            "id": "4B7878B42A1F7BD8C12580E10036C46E",
            "topic": "created from rest (Martin Jinoch [Anonymous])"
        },
        {
            "id": "52CED96E3A9556C3C12580E40062E73B",
            "topic": "created from rest (Anonymous)"
        },
        {
            "id": "41B590BBCFDE224EC12580F3004FDBF7",
            "topic": "created from rest (Martin Jinoch [Anonymous])"
        }
    ],
    "start": 5,
    "total": 300,
    "count": 7
}