开发者

What is the difference between offering a REST API and offering a "web service" with a basic API to retrieve and/or modify data?

SO I am about to write a REST API with Django using django-piston but my employer just wanted to be able to retrieve and create data, so I was wondering what is the difference between:

  • just creating methods to set and retri开发者_如何学Goeve data and making them publicly available (of course with authentication and validation in place)
  • creating a REST API for the purpose of creating and retrieving data ?

Thanks in advance!


Your second point is basically a sub set of your first point. REST is just a set of methods to create and retrieve data. It is however a fairly standardized set of methods using HTTP verbs instead of different urls to declare what you are trying to do.

So instead of /comments/new/, /comments/delete/, /comments/update/, you would just have /comments/ and POSTing to create, PUTing to update, and DELETEing to delete.

I also agree with Zach on TastyPie for what it's worth.


The two key alternatives to "RESTful" would be traditional html forms or a more formal RPC protocol thats implemented on top of HTTP, like XML-RPC or SOAP.

The main advantage of the former is that it can be invoked through a web-browser with no client code at all; but unless the application is designed in a thoughtful way, it's often quite difficult to drive such an interface from a custom client; which must often set cookies to do authentication and specify arguments that it isn't interested in. There's no notion of data types for this kind of API either, everything is text.

The latter has the advantage of getting you up and running in no time at all; You can just write normal functions in python, with a decorator, and they are available for clients that have the appropriate client libraries. The main disadvantage is also that this usually requires the client have such a library. Things like soap or xml-rpc are not typically an option for in-browser applications, or on resource-constrained devices.

RESTful is a sort of middle way that combines many advantages of both. Since the semantics are defined purely in terms of HTTP, any client capable of issuing HTTP can use a RESTful API. HTTP is much more flexible than plain old web forms, usually in terms of giving a Content-Type to the request or response that supports the needed structure. Unfortunately, there's not really a single standard defining how RESTful clients or services should represent their data, so there's necessarily a bit of customization on both ends to get things to work in the best way. Sometimes the flexibility means that you spend more time getting the api just right then you would have had to if you used a different interface, but it often leads to a thinner and yet less leaky abstraction.

There are a few standards or de-facto standards that are also good models of RESTful interfaces, such as json-rpc and the Atom Publishing Protocol.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜