API Conventions – Camel or snake case?

In this post, we’ll explore different APIs and take a look at the naming conventions they use. This may seem like a trivial topic, but knowing how other APIs are constructed can give the developer a piece of mind while they are implementing their API.

We’ll first explore some of the most common casings used in APIs:

Camel Case

When developers refer to camel case, they are generally referring to the notation where variables or attributes are start with a lowercase letter, with subsequent words beginning with an uppercase letter.

{
"user": {
"firstName": "Steven"
}
}

Have you ever worked on frontend development in JavaScript and faltered as you made a call to an API and had to rename all of the attributes from the result, which was in snake case?

This is one of the main advantages of creating a camel case based API. Developers using the API will have an easier time integrating the API into their front-end projects because the dominant front-end language used today, JavaScript, uses camel case by default.

One other consideration is that some backend languages such as Java and C# use camel case by default, so it will be slightly easier for the developers implementing the API to use the same convention.

Snake Case

Snake case refers to when variables and attributes start with a lowercase letter, with words separated by an underscore.

 {
"user": {
"first_name": "Steven"
}
}

Not all APIs are called from the front-end. If you have an API that will be called by other servers, then there isn’t an advantage over using camel case or snake case as you will not know what programming language the caller uses.

Some languages, such as Python and Ruby use snake case by default, so it will be slightly easier for the developers implementing the API to use the same convention.

Pascal Case

Pascal case refers to when variables and attributes are named with each word starting with an uppercase letter.

 {
"user": {
"FirstName": "Steven"
}
}

What do others do?

Let’s take a look at how other popular APIs name their API attributes!

APIVersionCase
Amazon Product Advertisingv5.0Pascal case
DigitalOceanv2Snake case
Facebook Graphv11.0Snake case
JIRAv3Camel case
Google YouTube Datav3Camel case
Microsoft Graphv1.0Camel case
OpenWeatherv2.5Snake case
PayPalv2Snake case
Spotifyv1Snake case
Steamv0002Lowercase, no spaces
Stripev1Snake case
Twitterv2Snake case
WordPressv2Snake case
Comparing APIs and their casing strategy

The list above is by no means comprehensive. However, it appears that most APIs use the snake case convention, followed by camel case.

Ultimately, the developer should follow the conventions set by their team and aim to be as consistent as possible with their team’s current APIs. In the event that you have the final say, both snake case and camel case are good options.

Hopefully this article provides you some insight into whether you want to use snake case or camel case the next time you create your API! 😎