What case should your API request/response be?
Tags: api, case, discuss, backend
Published: 2021-03-11 20:11:18

As a backend developer who writes APIs from time to time, I’ve always wondered if I am delighting my customers who in most cases are other developers when interacting with my APIs.
Thoughts like these always make me think about lots of things from performance, speed, etc. But very recently I started to think about how the final result of my APIs are formatted and how my supposed customers would prefer to have it. This, most times is not top of mind when writing APIs.

The programming language we use for a particular application usually determines how we structure/format strings. Generally, there are about 4 popular cases for naming things in different programming languages which are:
* Camel case - JavaScript e.g firstName
* Pascal case - Pascal e.g FirstName
* Snake case - Python e.g first_name
* Kebab case - Lisp e.g first-name

So the question is:
what should be the perfect case for the request/response object of my API?
What case do other developers using my API expect to see while interacting with my API?
Should the language I code in be the determinant of how my API request/response object case will be formatted?

These thoughts took me on a journey of API exploration. I don't think there is a better way to get an answer to this question than examining the documentation of some existing brands. Below is what I discovered👇🏼

### What I’ve seen so far 👀
[Stripe](https://stripe.com/about):
Stripe uses snake case for their request/response object across their APIs regardless of the language used. Take a look at their documentation page [here](https://stripe.com/docs/api)
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tvr29f97ho3al7px1nmq.png)

[Monnify](https://www.monnify.com/):
Monnify is a brand of TeamApt, a Fintech company just like Stripe based in Lagos, Nigeria. Monnify uses camel case for the request/response object of their APIs. You can have a look at their documentation [here](https://docs.teamapt.com/display/MON/General+Integration+Docs)

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/a2kzlrysvmyipxi3amrd.png)

[Twitter](https://twitter.com)
Twitter mostly uses snake case for the request/response object of their API doc at least the parts I’ve worked with. You can also take a sneak peek at their doc [here](https://developer.twitter.com/en/docs)

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fuwaxouwz0ha7rajigck.png)

[Eventbrite](https://www.eventbrite.com/about/)
Eventbrite just like Stripe uses snake case for their request/response API object. You can take a look at their doc [here](https://www.eventbrite.com/platform/docs/introduction)

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/o1yzlclde1h068zfzrsj.png)

[Carbon](https://ng.getcarbon.co/about.html)
Carbon API documentation, different from every other one we have looked at uses a mix of snake case and camel case for their request/response object. This is the first time I am seeing anything like this. You can also take a look at their doc [here](https://sme.getcarbon.co/developers#identity-verification-overview)

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gcrvtm75wyqomqoi1out.png)

## Conclusion
I must confess that I have seen more JSON-based API request/response object for many documentations in snake_case than any other case but I have also seen a fair share in other cases especially camelCase. I have equally written some endpoints that uses snake case and camel case in various APIs as well but I will also like to have your opinion on this subject.

### P.S.
This is a very short article on a very focused topic through which I hope to drive meaningful conversation so do not hesitate to share your opinion on the topic in the comment section below.

**Frontend Developers**
* As a frontend developer (mobile or web) what case do you expect to consume your API in or what is your most preferred case? 
* Do you use any library to convert your request/response object to your preferred case of choice should the API not be in that case?

**Backend Developers**
* Does the language you write in determine what case your API request-response object will be?
* Do you use any library to unify your API request/response case irrespective of the language? Care to share?