简体   繁体   English

OData RESTful吗?

[英]Is OData RESTful?

I am writing an WEB API project where I use OData for advcened querying of resources. 我正在编写一个WEB API项目,我使用OData来进行资源查询。 The service should be RESTful. 该服务应该是RESTful。 But I am not sure if OData is RESTful because of URI format. 但由于URI格式,我不确定OData是否是RESTful。

Everywhere I look REST URI format looks like this 在任何地方我看起来REST URI格式都是这样的

http://example.com/resources/142

But OData URI format should be like this 但OData URI格式应该是这样的

http://example.com/resources(142)

I am not sure if both is right for REST or OData is not completly RESTful. 我不确定两者是否适合REST或OData不完全RESTful。

If the service you're writing should be RESTful, and you are worried about URI format, then you should do some research on the subject, because URI semantics are entirely irrelevant to REST. 如果您正在编写的服务应该是RESTful,并且您担心URI格式,那么您应该对该主题进行一些研究,因为URI语义与REST完全无关。

The only constraints REST imposes on URIs is that they are treated as atomic identifiers, meaning they can't be split in parts in order to be understood, and that one URI identifies one and only one resource. REST对URI施加的唯一约束是它们被视为原子标识符,这意味着它们不能被分割成部分以便被理解,并且一个URI标识一个且仅一个资源。 Other than that, URI semantics and format are irrelevant. 除此之外,URI语义和格式无关紧要。 What matters to REST is how the client gets the URI. REST最重要的是客户端如何获取URI。 If they are reading URI patterns from documentation and filling placeholders with values, then that's not RESTful. 如果他们从文档中读取URI模式并使用值填充占位符,那么这不是RESTful。 You should do some research on HATEOAS if that's new for you. 你应该对HATEOAS做一些研究,如果这对你来说是新的。

The URI is not so strict to call it REST-ful. URI不是那么严格,称之为REST-ful。 There are no standards for checking your service and saying: "This is REST" or "This is not REST". 没有标准可以检查您的服务并说:“这是REST”或“这不是REST”。

No matter if the URI is: 无论URI是否:

http://my.service/users/user-1/

OR 要么

http://my.service/users/1/

OR 要么

http://my.service/users(1)

It still can be REST-ful service. 它仍然可以是REST-ful服务。

(I would add this as a comment but I don't have the rep.) (我会将此作为评论添加,但我没有代表。)

There's a couple of good questions on this subject on SO already: 关于这个主题的问题已经有几个很好的问题了:

What I take from this is that there's more to a RESTful API than just the URI format and OData is more about the message content than the architecture, so if you adhere to the principles of REST with OData, then it could be considered to be RESTful. 我从中得到的是RESTful API不仅仅是URI格式,而OData更多的是关于消息内容而不是架构,所以如果你遵守REST与OData的原则,那么它可以被认为是RESTful 。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM