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!
API | Version | Case |
Amazon Product Advertising | v5.0 | Pascal case |
DigitalOcean | v2 | Snake case |
Facebook Graph | v11.0 | Snake case |
JIRA | v3 | Camel case |
Google YouTube Data | v3 | Camel case |
Microsoft Graph | v1.0 | Camel case |
OpenWeather | v2.5 | Snake case |
PayPal | v2 | Snake case |
Spotify | v1 | Snake case |
Steam | v0002 | Lowercase, no spaces |
Stripe | v1 | Snake case |
v2 | Snake case | |
WordPress | v2 | Snake case |
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! 😎