URL Sorting Guidelines
In this section, user can find info of generic code that can be found in different API endpoints.
We are trying to bring closer how our system works, so this might be incredibly useful content.
We will try to make further explanation of URL Sorting.
1. Overview
URL Sorting should provide a safe way to sort data via human-friendly URLs.
The main goal of this article is to explain an easy URL interface for sorting data. It allows the user to safely sort.
2. Operators
- ASC [default]
Sorting in ascending order, this should be the default ordering operator - DESC
Sorting in descending order, this could be considered as a negation sort operator
3. Operands
Operands in this case can be any variable with some meaning, ex. BirthDate, Status, ...
4. Implementation
In order to describe operators we will use the increment or decrement coefficients: +1 [asc] an -1 [desc]
Since +1 === 1 we can use the sign: 1
This means:
- ASC => 1
- DESC => -1
Lets assume that sortFunction = F(X):
- F(0) = 0
- F(ASC X) = F(X) = ASC X = X
- F(DESC X) = F(-X) = DESC X = -X
If we assume that sortUrlFunction = G(F(X)):
- G(0) = ''
- G(ASC X) = 'X'
- G(DESC X) = '-X'
This will mean that:
- F(X, Y, Z) = F1(X) + F2(Y) + F3(-Z) = *ASC X + ASC Y + DESC Z = X + Y - Z**
- G(X, Y, Z) = + X , + Y , - Z = 'X , Y , - Z'
Example:
- G(ASC BirthDate, DESC Status, DESC Balance) = 'BirthDate, Status,-Balance'