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?
The standard naming conventions used in modern software development are as follows: Pascal case. camel case. snake case.
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.
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:
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With