Asked by:
How do I create a route map for non-hierarchical properties RESTfully?

Question
-
User1434241939 posted
Let's say I have a site that displays cars. Different people care about various characteristics more than others. Let's say there are 3 characteristics
- Color
- Passengers
- Speed
Do I have to create 6 different route maps and corresponding controller methods in order to filter cars by characteristic? For example:
- /cars/{color}/{passengers}/{speed}
- /cars/{color}/{speed}/{passengers}
- /cars/{speed}/{color}/{passengers}
- /cars/{speed}/{passengers}/{color}
- /cars/{passengers}/{speed}/{color}
- /cars/{passengers}/{color}/{speed}
What the Restful/"right" way to do this?
Tuesday, April 21, 2020 8:53 PM
All replies
-
User475983607 posted
I would not use routes. Color, passenger, and speed are filter and a querystring work great for persisting filters in the URL.
Tuesday, April 21, 2020 10:28 PM -
User1434241939 posted
Thanks very much! It helps to know that I'm not missing something obvious about route maps.
So if I have 50 different filters, should I put them all in a querystring?
Tuesday, April 21, 2020 10:32 PM -
User475983607 posted
stevebo
Thanks very much! It helps to know that I'm not missing something obvious about route maps.
So if I have 50 different filters, should I put them all in a querystring?
There is a limit to the URL length; ~2000 characters.
IMHO, this is a question of managing state. Querystring are good when you want to filter data because it is easy to persist the data in the URL. If 2000 characters is not enough space then you can use HTML forms and hidden fields, Session, cache, or a DB table.
Tuesday, April 21, 2020 10:49 PM -
User1434241939 posted
So should my [HttpGet] route just be:
/cars
which returns thousands of cars? Then I filter them on querystring and the selection becomes
/cars/{id}
What if the thousands of cars have large images associated with them? The performance would suffer doing it this way.
I'm sorry for the basic questions, but I'm just trying to learn all this.
Wednesday, April 22, 2020 10:22 AM -
User475983607 posted
So should my [HttpGet] route just be:
/cars
which returns thousands of cars? Then I filter them on querystring and the selection becomes
/cars/{id}
What if the thousands of cars have large images associated with them? The performance would suffer doing it this way.
I'm sorry for the basic questions, but I'm just trying to learn all this.
As the programmer you get to determine what data and how much is returned to the browser. It seems like you made up a problem that does not exist at the moment.
Wednesday, April 22, 2020 10:35 AM