REST API 应该区分大小写还是不区分大小写? [英] Should a REST API be case sensitive or non case sensitive?

查看:102
本文介绍了REST API 应该区分大小写还是不区分大小写?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在工作中,我们遇到了区分大小写的 REST api 的问题,它会忽略拼写错误的参数而不返回任何错误.在我看来,这很糟糕.然后是一般问题:

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:

REST API 应该区分大小写还是不区分大小写?

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

每种方法的优缺点是什么?

What are the advantages and disadvantages of each approach?

推荐答案

正如其他人回答的那样,构成 API 的 URL 的 HTTP 部分区分大小写.这遵循 UNIX 约定,其中 URI 路径映射到文件系统路径,并且文件系统路径区分大小写.另一方面,Windows 遵循其使路径不区分大小写的惯例.

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.

然而,在 Unix 中拥有两条仅大小写不同的路径是不好的做法;此外,预计路径是小写的.

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.

永远不应该共存.此外,products 应该优先于 Products.Products 是否应该返回 404、301 到 products 或者只是作为 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 API 是规范的小写和不区分大小写的.我认为这让客户的生活变得更轻松,同时具有明确的默认设置并且对大多数用户来说并不奇怪.

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?

这篇关于REST API 应该区分大小写还是不区分大小写?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆