A C# Parser for REST requests generating Linq expressions
The REST query allows for filtering, sorting and paging.
Filters work with all types
| Operator | Description | Example | Field Types | Comparison Operators |
|---|---|---|---|---|
| eq | Equal |
|
string, date, int, decimal, double, boolean | |
| ne | Not equal |
|
string, date, int, decimal, double, boolean | |
| gt | Greater than |
|
date, int, decimal, double | |
| ge | Greater than or equal |
|
date, int, decimal, double | |
| lt | Less than |
|
date, int, decimal, double | |
| le | Less than or equal |
|
date, int, decimal, double | |
| contains | contains the value |
|
string | |
| notcontains | does not contain the value |
|
string | |
| startswith | starts with the value |
|
string | |
| isnull | checks if the value is null |
|
string |
Note: The default filter is [eq] It is case insensitive
You can sort by multiple fields ascending or descending.
- GET /items?code=xxx&rest=$sort_by=surname
- GET /items?code=xxx&rest=$sort_by[asc]=surname
- GET /items?code=xxx&rest=$sort_by[desc]=surname
- GET /items?code=xxx&rest=$sort_by[asc]=surname&$sort_by[desc]=firstname
Pagination is optional, by default all records are returned. If pagination is required, a sort_by should also be added
- GET /items?code=xxx&rest=$page=1&$pageSize=10
- GET /items?code=xxx&rest=$page=2&$pageSize=10
- GET /items?code=xxx&rest=$page=5&$pageSize=25
GET /items?code=xxx&rest=surname[contains]=Smi
&hometown[eq]=Edinburgh
&$sort_by[asc]=surname
&$sort_by[desc]=firstname
&$page=1
&$pageSize=10
Results The result is a JSON object with two properties Data, and Pagination:
{
"data" : [
{ "id":"1", "firstName":"Bob", "lastName": "Smith"..... },
{ "id":"2", "firstName":"Rob", "lastName": "Smith"..... },
...
{ }
],
"Pagination": {
"PageNumber": 1,
"PageSize": 10,
"PageCount": 2,
"TotalCount": 19
}
}Fixed three issues including the [contains] on a nullable string.
Updated to handle nullable types. There is a remaining issue throwing an exception when using [contains] on a nullable string.
Changed result from parse to RestResult object, which contains expressions, sort expressions with paging to come. Added Run command to parser which takes a IQueryable data source, and the rest request, parses, runs against the data and returns the results.
Refactored. Removed SQL generator.
Removed Specflow tests. Added unit tests. tests added for RestToLinq String Equals