Skip to content

Method Chain Semantics

Oleksandr Hulyi edited this page Feb 8, 2019 · 3 revisions

Method-Chain Semantics

Semantics for queries over HTTP in form of a chain of method calls. Features:

  • Uses only one (user-defined) http query parameter
  • Sequence of the call translated (almost) directly into Linq expressions
  • Easily extensible

Semantics

Semantics consists of call, property getters, functions, namings and constants.

Calls

- - method has a dash(minus) symbol in the beginning of the method name.

Arguments are delimited with comma ,. Arguments started with colon : are functions. Method call with no arguments can be expressed without brackets._ -not() == -not

Example

You have defined your data as

var data = new List<string> {"abc", "def", "ghi"}

Then query http://.../api/data/-addtext(:`123`) translates into

var result = data.Foreach(s=>s + "123")

And query http://.../api/data/-addtext(`123`) translates into

var result = data + "123"

Properties

To get a root property only property name like Text and for sub properties use period Sub.Number

Example

var data = new List<>{
   new { Text = "abc", Sub = new { Number = 1 }  },
   new { Text = "def", Sub = new { Number = 2 }  },
}

http://.../api/data/-where(:Text-eq(`abc`))

http://.../api/data/-where(:Sub.Number-eq(2))

Constants

Costants can be either number, text, boolean or null.

  • Number is a number in javascript terms - quite big, can be negative.
  • Text is a free text delimited by ' symbol. Any other types can be represented via text e.g. '2018-10-11' or '772e1c43-1794-4bfd-84a8-d165088ca9c6'
  • Boolean true or false
  • Null is null

Build-in methods

Boolean methods

-eq( arg )

Equlity check. Text-eq(`123`) Number-eq(2)

-ne( arg )

Non-equlity check. Text-ne(`123`) Number-ne(2)

-not()

Boolean inverse method. true-not() Number-ne(2)-not()

-has( arg ), :has( arg )

String.Contains and List.Contains equivalent. data:has(2) Text-has(`abc`). Pay attention to call type, for String.Contains use -, for List.Contains use :

-oneof( arg, arg, ...)

Logical OR

-every( arg, arg, ...)

Logical AND

Query methods

:where( arg )

:get( arg, arg, ... )

:take( arg )

:skip( arg )

:order( arg ), -asc(), -desc()

Aggregations

:first()

:count()

:sum( arg )

Understanding call context

There are two contexts in any call - call context and root The initial call context and root are what you return from your action.

http://.../api/data - here both root and call context are equal to array of data.

Call context is changed with every call.

http://.../api/data/-somemethod() - here call context is what somemethod returns, but the root is the same array of data

http://.../api/data/-somemethod()-anothermethod() - here anothermethod is executed on what is returned from somemethod. Root is still the same.