I am implementing a rest API that incorporates pagination and sorting.
my query params:
For a particular get request, a user can do the combination of the following operations:-
I was thinking to implement switch for this, by if in future additional query params are added then the list can go long
so is there an alternative where I can mention multiple conditions ( in OR form) and doesn't loose performance too?
Based on comments :- the same thing can be achieved by 5 if statements but objective is to have scalable, readable and little performance ( if its possible)
function getResults(object) {
var title = object.params
switch (title) {
case 'page':
title = 'page'
break
case 'order_By':
title = 'orderBy'
default:
title = 'Unassigned'
break
}
.......( continued)
return title
}
Just create an object a bit like this one
Page
PageSize (Limit i guess? Since paging in itself has no limit, just the pages)
Sort
SortDirection
I think this should suit you?
Then apply conditions via method. Example:
var myPagingObject = {};
function applyPagingParameter(key, value) {
myPagingObject[key] = value;
}
No if statements need like that (except in the backend ofcourse, but if you standardize 4 if statements that can be used applicationwide, why not?)