Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should a REST API be case sensitive or non case sensitive?

At work we got a problem with case sensitive REST api which ignores wrongly spelled parameters without returning any error. In my opinion this is bad. Then it comes the general question:

Should a REST API be case sensitive or non case sensitive?

What are the advantages and disadvantages of each approach?

like image 712
mynkow Avatar asked Jan 08 '14 16:01

mynkow


People also ask

Should REST endpoints be lowercase?

Use Lowercase LettersEnsure that you use lowercase letters in your API URLs. The RFC 3986 specification for URI standards also denotes that URIs are case-sensitive (except for the scheme and host components of the URL). Given the widespread use of it, avoid any unnecessary confusion due to inconsistent capitalization.

Should REST API be camel case?

The standard best practice for REST APIs is to have a hyphen, not camelcase or underscores.

Are API names case-sensitive?

As a general rule, for XML- and JavaScript-based features, the API names are case-sensitive, and for JSON-, Apex-, and Visualforce-based features, it is case-insensitive, as well as basic features like SOQL, SOSL, and Formula Fields.

Is API key case-sensitive?

Yes, these are case-sensitive ( [A-z0-9]{20} at present).


2 Answers

As others answered, the HTTP portion of the URL that makes APIs is case sensitive. This follows the UNIX convention, where URI paths were mapped to filesystem paths, and filesystem paths are case-sensitive. Windows, on the other hand, follows its convention of making paths case-insensitive.

However, it is bad practice in Unix to have two paths which only differ by capitalization; furthermore it is expected that paths be lower case.

Therefore: let's not break conventions.

  • https://example.org/api/v1/products

and

  • https://example.org/api/v1/Products

should never cohexist. Furthermore, products should be preferred to Products. Whether Products should return a 404, a 301 to products or simply be an alias of products is a matter of style -- it's your choice, but be consistent.

Stack Overflow APIs are canonically lower-case and case insensitive. I think this makes life easiest to the client, while having a clear default and being unsurprising for most users.

After all, can you think of a client that honestly benefits from case sensitivity and overlapping names?

like image 136
Sklivvz Avatar answered Sep 20 '22 12:09

Sklivvz


HTTP URLs are case-insensitive for the scheme and host portion and case-sensitive for the path, query and fragment.

https://datatracker.ietf.org/doc/html/draft-ietf-httpbis-p1-messaging-25#page-19

The scheme and host are case-insensitive and normally provided in lowercase; all other components are compared in a case-sensitive manner.

like image 26
Darrel Miller Avatar answered Sep 21 '22 12:09

Darrel Miller