0

I'm trying to follow best practices for an API, and I'm getting conflicting advice. Most suggest using spinal-case for URI (such as stackoverflow and RFC3986. I have an API that allows filtering on GET requests by various parameters:

GET /endpoint?my-parameter=true

However, I also use the same parameter in GET responses and PATCH requests. There, I see a lot more camelCase or snake_case, and spinal-case is an extra with languages that don't allow hyphens in variable names. So I use this:

   { 
      myParameter: true
   }

This seems inconsistent. What's the best practice for handling these cases?

jimm101
  • 948
  • 1
  • 14
  • 36
  • There is no best practice, just be internally consistent. Lots of people use different 'cases' so if you want more consistency between your bodies and urls, change one. – Evert Nov 05 '21 at 20:15

1 Answers1

1

As Evert had said, there is no correct answer to this question.

spinal-case is ruled out because it is not usable with the basic syntax format in some languages like JavaScript. Ex: response.user-name would break and it has to be written as response[“user-name”]

So, we are left with camelCase and snake_case. Out of these, I personally prefer the snake_case as it is more clear in differentiating the words than the camelCase.

So, It is completely your opinion on which one to use but make sure that you follow it in all your APIs.

Deva Gerald
  • 284
  • 2
  • 6