如果一个REST API是区分大小写不区分大小写? [英] Should a REST API be case sensitive or non case sensitive?

查看:3415
本文介绍了如果一个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.

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

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

不应该cohexist。此外,产品应pferred到 $ P $产品。无论产品应该返回一个404,一个301 产品或者干脆是产品的别名是一个风格问题 - 它是你的选择,但要保持一致。

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.

堆栈溢出的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天全站免登陆