-
Notifications
You must be signed in to change notification settings - Fork 3
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 consists of call, property getters, functions, namings and constants.
-
- 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
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"
To get a root property only property name like Text
and for sub properties use period Sub.Number
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))
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
orfalse
- Null is
null
Equlity check. Text-eq(`123`)
Number-eq(2)
Non-equlity check. Text-ne(`123`)
Number-ne(2)
Boolean inverse method. true-not()
Number-ne(2)-not()
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 :
Logical OR
Logical AND
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.