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

后端 未结 3 1060
南笙
南笙 2020-12-14 06:35

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 gene

3条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-14 06:48

    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?

提交回复
热议问题