Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to deal with different variable name convention in backend api and frontend

In javascript, I am using camel case naming convention but in the backend rest api returns all of the field names in snake case which already built. I am wondering what's the best practice for this case especially for component based front-end app( react ). I can simply replace snake case to camel case but the problem comes when I have deeply nest object.

Does anyone have a good suggestion or knows how big companies deal with this thing?

like image 999
fiddlest Avatar asked Aug 30 '17 03:08

fiddlest


People also ask

What are different variable naming conventions?

The standard naming conventions used in modern software development are as follows: Pascal case. camel case. snake case.

What are naming conventions in programming?

In computer programming, a naming convention is a set of rules for choosing the character sequence to be used for identifiers which denote variables, types, functions, and other entities in source code and documentation.


1 Answers

Unfortunately there is not much you can do about it. Most server side languages are case sensitive and therefore blindly changing the case of the client side counterparts for the server classes/interfaces is not an option.

As far as I can see there are two possibilities you can consider:

  1. If in your architecture allows you have limited amount of places that are responsible for transferring the data and serialization/deserialization of it and you have both client side and server side classes to describe the same data - you can implement you deserialization procedure that will automatically convert data into the instances of required classes with necessary name convention on client and server sides. The drawback is obvious overhead and sometimes complexity/slowliness of such transformation. Moreover if you are working within simple system you might be missing suitable place to run this transformation.

  2. Write down strict rules that stipulate that all data that are passed between server and client should follow one of the naming conventions, even though it will be different from the rest of the code. Then make sure everyone follows them. You might use tslint or such tools to ensure this rule. Drawbacks are somewhat messy code and extra steps required to ensure this rule.

like image 130
Amid Avatar answered Oct 22 '22 01:10

Amid