json - REST - best practice for returning constants/enums and handling it by JavaScript -
i developing web app, partially based on ajax calls. specifics not important here. 1 of entities uses constant ints status , need information in front end show string , conditionally show buttons/info.
const status_ordered = 1; const status_will_be_returned = 2; const status_received = 3; const status_delayed = 4; const status_archived = 5;
i have several ideas how include data in json response , how handle in javascript. looking best way this. ideas:
- send status string (converted using swich or associative table) - approach make easier show status, including in logic involve string comparison
- send int , convert string on front end site - logic, string has generated somwhere anyway (this seems suitable approach me)
- send int translation table - works nice if string value needed, makes front more independent, not change here, cause need check status on front end site anyway
Comments
Post a Comment