Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Mapping variable names between frontend & backend

I’m developing a full-stack application (React, Node, Postgres). When receiving the form data from the frontend, I expect certain variable names sush as firstName and I map firstName to first_name on the backend server to insert it into the postgres db. Now my question is regarding the GET requests and sending the data back to the front end:
Should I map the names back to the frontend naming convention on the server before I send the json (map first_name back to firstName) or handle the mapping on the frontend?
What is the best practice regarding such situations?

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Yes, the best practice is to keep the code for the mapping in a single place: either in the backend, or in the frontend, not both. Keep the naming convention within each API consistent.

If your backend accepts firstName as input and does the mapping internally when inserting in the database, it should also do the mapping internally when reading from the database and provide firstName as output.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading