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 :
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.