有关 REST URL 的详细问题 [英] Detail question on REST URLs

查看:33
本文介绍了有关 REST URL 的详细问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是那些小细节(可能还有宗教)问题之一.假设我们正在构建一个 REST 架构,并且为了确定性,假设服务需要三个参数,xyz.阅读有关 REST 的各种作品,似乎这应该表示为像

This is one of those little detail (and possibly religious) questions. Let's assume we're constructing a REST architecture, and for definiteness lets assume the service needs three parameters, x, y, and z. Reading the various works about REST, it would seem that this should be expressed as a URI like

http://myservice.example.com/service/ x/y/z

过去写了很多 CGI,表达这个似乎很自然

Having written a lot of CGIs in the past, it seems about as natural to express this

http://myservice.example.com/service?x=val,y=val,z=val

有什么特别的理由更喜欢全斜线形式吗?

Is there any particular reason to prefer the all-slashes form?

推荐答案

原因虽小,但在这里.

很酷的 URI 不会改变.

Cool URI's Don't Change.

http://myservice.example.com/resource/x/y/z/ 表单在上帝和每个人面前宣称这是通往特定路径的路径 资源.

The http://myservice.example.com/resource/x/y/z/ form makes a claim in front of God and everybody that this is the path to a specific resource.

请注意,我更改了名称.可能涉及到一项服务,但 REST 原则是您正在描述一个名为 /x/y/z/ 的特定 Web 资源.

Note that I changed the name. There may be a service involved, but the REST principle is that you're describing a specific web resource, named /x/y/z/.

http://myservice.example.com/service?x=val,y=val,z=val 表单并没有那么强烈的声明.它说有一段名为 service 的代码将尝试进行某种查询.不做任何保证.

The http://myservice.example.com/service?x=val,y=val,z=val form doesn't make as strong a claim. It says there's a piece of code named service that will try to do some sort of query. No guarantees.

这篇关于有关 REST URL 的详细问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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