• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Should client or server deal with friendly values?

Friendly values being instead of the database column name "satfod" it would be "Saturated Fats".

Should I:

A - Send the client a friendly values map on initial login so it can friendlyify food objects on its own if it wishes. So the server just sends arrays of food objects unaltered.

OR

B - Have the server put the friendly values into each food object so instead of the server sending just this:
Code:
{
protein:10,
satfod:20,
carbs50
}

It would send this:
Code:
{
values:{
protein:10,
satfod:20,
carbs:50},

friendlyValues:{
Protein:10,
Saturated Fats:20,
Carbohydrates:30}
}

It doubles the size of each food object but makes things less complex on the client side. What do you guys think? I am useless at design choices like this 😕 Option A is what im currently doing but im not really sure if thats the best way to go.
 
Transformations of data like this should pretty much always happen on the client side. The client and server make a contract of how the data should look, that contract should be minimal. But ultimately, it is the client's responsibility to handle how the data is displayed and processed.

Another alternative if you want more flexibility is to introduce one more endpoint that does a value -> friendly value mapping. So it would return something like {"satfat": "Saturated Fat"};

Another alternative is to put that mapping directly on the response. So

{
values:{ blah },
valueMappings: { "satfat": "Saturated Fat" }
}
 
The server shouldn't know or care about the "friendly values" so I'd defintely handle it on the client side as well.

It's very common to have 2 "things" for items, where 1 is the display and one is the value.
 
Client, then you could use even more cryptic text or even code numbers.

Also, when you send the map table from code => friendly text you could potentially have multiple map tables for different languages, e.g. satfat => grasa saturada
 
Back
Top