0

Javascript community generally follows camel case naming convention, whereas while writing REST api URLs follow snake case naming conventions.

What would be the better naming convention for the payloads which will be sent in HTTP requests/responses?

If the answer is snake_case then will it be better to convert each and every key in the payload to be converted to snake case while going out of the Node JS server and be converted to camelCase while coming into the Node JS server and should same be followed on the client side if it is also using JS environment?

Anshul Sahni
  • 365
  • 2
  • 4
  • 12

1 Answers1

0

The underlying transport method of an API should be hidden by a Client class.

A JavaScript Client will of course expose methods which follow the javascript naming conventions.

eg.

function niceCamelCaseFunctionName()
{
    fetch('./api/snake_case_resource')
      .then(
        function(response) {
          response.json().then(function(data) {
            var r = {
               niceProperty : data.EvilPascalCase
            } 
            return r
          });
        }
      )
}
Ewan
  • 70,664
  • 5
  • 76
  • 161