简体   繁体   中英

Is OData RESTful?

I am writing an WEB API project where I use OData for advcened querying of resources. The service should be RESTful. But I am not sure if OData is RESTful because of URI format.

Everywhere I look REST URI format looks like this

http://example.com/resources/142

But OData URI format should be like this

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

I am not sure if both is right for REST or OData is not completly 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.

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. Other than that, URI semantics and format are irrelevant. What matters to REST is how the client gets the URI. If they are reading URI patterns from documentation and filling placeholders with values, then that's not RESTful. You should do some research on HATEOAS if that's new for you.

The URI is not so strict to call it REST-ful. There are no standards for checking your service and saying: "This is REST" or "This is not REST".

No matter if the URI is:

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.

(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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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