MagicTheGathering / mtg-api

Magic: The Gathering API allows developers to easily consume MTG card and set data in JSON format.
39 stars 3 forks source link

Rename Custom Response Headers to use camelCase or snake_case #10

Closed Saeris closed 7 years ago

Saeris commented 7 years ago

The current format of the Response Headers (hyphenated) causes issues in JavaScript (and possibly other languages) when using the dot notation for accessing properties of objects, forcing the use of bracket notation instead. Examples:

console.log(headers.rate-limit); // Error (trying to subtract limit from headers.rate)
console.log(headers.["rate-limit"]); // 5000
console.log(headers.rateLimit); // 5000
console.log(headers.rate_limit); // 5000

JavaScript prefers camelCase for variable/property names, so that would be the ideal naming convention, but if this conflicts with other SDK's this might not be the best choice, wherein snake_case would be an acceptable alternative. More info:

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Property_Accessors

Suggested names for the existing headers:

adback03 commented 7 years ago

For your use case, it seems most appropriate to use the square bracket notation when accessing the headers:

headers["rate-limit"]

I'm hesitant to change the names for the headers, as it appears common naming conventions for HTTP Headers are Foo-Bar (hyphenated). This would be true for built in response headers as well, like Content-Encoding or Content-Type. If you wanted to access those via JavaScript dot notation, you would run into the same issue.

https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers