๐Ÿ”NData query syntax

This section describes the query syntax used in PORTOS API, called "NData".

What is NData?

NData is custom syntax to perform server-side pagination, sorting, inclusion and filtering, inspired by open stack syntax.

Pagination

Pagination allows to specify range of items received from the API. Pagination can be implemented using one or both of two query parameters:

Pagination examples

Sorting

Sorting allows to change order of returned items.

The caller may (but is not required to) specify a sort direction for each key. If a sort direction is not specified for a key, then a default is set by the server. Sort directions can optionally be appended to each sort key, separated by the : character. Supported sort directions are:

Sorting examples

Inclusion

Inclusion allows to extend response format.

Inclusion examples

Filtering

API endpoint-specific filters are often supported, to filter result based on provided filter values.

No global parameters are defined. Each endpoint-specific filter supports one or more parameters. Each parameter is identified by its name, below addressed as FILTER_MEMBER.

Filtering syntax: operations, operator and operation arguments

Value of each filter is semicolon-separated (;) list of operations.

Syntax: FILTER_MEMBER=OPERATION1;OPERATION2

Each operation consists of segments delimited by colon (:) character. First segment is an operator, followed by 0 or more operation arguments.

Syntax: FILTER_MEMBER=OPERATOR:OPERATION_ARGUMENT1:OPERATION_ARGUMENT2

Example: Filter member named "DiscountRate" is associated with single operation, that has "gt" operator and one operation argument, value 10. Result query is: DiscountRate=gt:10

Multiple filter occurrence

Multiple occurrence of same filter member is supported, thus both following queries are equal:

  • DiscountRate=gt:0&DiscountRate=lt:50

  • DiscountRate=gt:0;lt:50

Operators

Each filter may support one or more operators. Usually, well-known operators (listed below) are used. Each filter may, however, support custom operators - operators with custom name.

Well-known operators

Custom operator

The filter may support custom operator - an operator with custom name (and behavior).

Example: If filter named "Foo" supports the custom operator named "op", accepting "bar" as an operation argument, example query would look like this: Foo=op:bar.

Default operator

The filter syntax allows not to specify the operator explicitly. If no operator is explicitly specified in the URI, default operator is used. Each filter may have different default operator. If not stated otherwise, the default operator is eq.

Example: With assumption that eq operator is default operator for "DiscountRate" filter, both following queries are equal:

  • DiscountRate=eq:10

  • DiscountRate=10

Example: If filter named "Foo" has the custom operation "op" marked as default, you can specify the query from example above without explicitly stating the operator, like this: Foo=bar.

Collection operation arguments

Some operators, such as in and nin are paired with argument that is an collection. To delimit these values within operation argument, comma character (,) is used.

Example: Filter named Month with one operation, that has in operator and one argument that is an collection of three string values: "January", "February" and "March".

Month=in:January,February,March

Operation argument escaping

Operation argument must be encapsulated in double quotation marks (") if their string representation contains at least one of following special characters:

  • , (conflict with collection operation argument separator)

  • : (conflict with operation segments separator)

  • ; (conflict with operations separator)

FilterMember=eq:"argument:with,special;characters"

If argument is an collection, each value is escaped separately:

FilterMember=in:"foo:bar","foo,bar","foo;bar"

If argument contains double quotation mark character ", this character must be escaped with backslash \. Example: Filter named "Actor" associated with operation with eq operator and string value Dwayne "The Rock" Johnson:

Actor=eq:"Dwayne \"The Rock\" Johnson"

URI Encoding: If NData query is transfered in URI, URI encoding takes place after all NData syntactic rules being applied. Valid URI value would be:

Actor=eq:%22Dwayne%2520%255C%2522The%2520Rock%255C%2522%2520Johnson%22

Last updated