使用 RESTful URL 能给我带来什么? [英] What does using RESTful URLs buy me?

查看:45
本文介绍了使用 RESTful URL 能给我带来什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在阅读有关 REST 的信息,我正在尝试弄清楚使用它的优势是什么.具体来说,REST 风格的 URL 有什么优势,使它们值得通过带有查询字符串的更典型的 GET 请求实现?

I've been reading up on REST, and I'm trying to figure out what the advantages to using it are. Specifically, what is the advantage to REST-style URLs that make them worth implementing over a more typical GET request with a query string?

为什么是这个网址:

    http://www.parts-depot.com/parts/getPart?id=00345

被认为不如这个?

    http://www.parts-depot.com/parts/00345

在上面的例子中(取自这里)第二个网址确实是外观更加优雅简洁.但它是有代价的……第一个 URL 很容易用任何网络语言实现,开箱即用.第二个需要额外的代码和/或服务器配置来解析出值,以及额外的文档和花费时间向初级程序员解释系统并向同行证明其合理性.

In the above examples (taken from here) the second URL is indeed more elegant looking and concise. But it comes at a cost... the first URL is pretty easy to implement in any web language, out of the box. The second requires additional code and/or server configuration to parse out values, as well as additional documentation and time spent explaining the system to junior programmers and justifying it to peers.

所以,我的问题是,除了让 URL 看起来很酷的乐趣之外,RESTful URL 对我有什么好处,使使用它们值得实现成本?

So, my question is, aside from the pleasure of having URLs that look cool, what advantages do RESTful URLs gain for me that would make using them worth the cost of implementation?

推荐答案

希望如果你让你的 URL 引用一个名词,那么你就有更好的机会正确实现 HTTP 动词.除此之外,一个网址与另一个网址相比绝对没有优势.

The hope is that if you make your URL refer to a noun then there is a better chance that you will implement the HTTP verbs correctly. Beyond that there is absolutely no advantage of one URL versus another.

实际情况是,URL 的内容与 RESTful 系统完全无关.它只是一个标识符.

The reality is that the contents of an URL are completely irrelevant to a RESTful system. It is simply an identifier.

重要的不是它的样子,而是你用它做什么.

It's not what it looks like, it is what you do with it that is important.

这篇关于使用 RESTful URL 能给我带来什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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