Can you explain the Web concept of RESTful?

2019-01-12 18:39发布

Looking for clear and concise explanations of this concept.

7条回答
Bombasti
2楼-- · 2019-01-12 18:46

A RESTful application is an application that exposes its state and functionality as a set of resources that the clients can manipulate and conforms to a certain set of principles:

  • All resources are uniquely addressable, usually through URIs; other addressing can also be used, though.
  • All resources can be manipulated through a constrained set of well-known actions, usually CRUD (create, read, update, delete), represented most often through the HTTP's POST, GET, PUT and DELETE; it can be a different set or a subset though - for example, some implementations limit that set to read and modify only (GET and PUT) for example
  • The data for all resources is transferred through any of a constrained number of well-known representations, usually HTML, XML or JSON;
  • The communication between the client and the application is performed over a stateless protocol that allows for multiple layered intermediaries that can reroute and cache the requests and response packets transparently for the client and the application.

The Wikipedia article pointed by Tim Scott gives more details about the origin of REST, detailed principles, examples and so on.

查看更多
兄弟一词,经得起流年.
3楼-- · 2019-01-12 18:47

The best explanation I found is in this REST tutorial.

查看更多
太酷不给撩
4楼-- · 2019-01-12 18:49

REST by way of an example:

POST /user
fname=John&lname=Doe&age=25

The server responds:

200 OK
Location: /user/123

In the future, you can then retrieve the user information:

GET /user/123

The server responds:

200 OK
<fname>John</fname><lname>Doe</lname><age>25</age>

To update:

PUT /user/123
fname=Johnny
查看更多
老娘就宠你
5楼-- · 2019-01-12 18:51

Just a few points:

  • RESTFul doesn't depend on the framework you use. It depends on the architectural style it describes. If you don't follow the constraints, you're not RESTful. The constraints are defined in half a page of Chapter 5 of Roy Fielding's document, I encourage you to go and read it.
  • The identifier is opaque and does not cary any information beyond the identification of a resource. It's a nmae, not input data, just names. as far as the client is concerned, it has no logic or value beyond knowing how to build querystrings from a form tag. If your client builds its own URIs using a schema you've decided up-front, you're not restful.
  • The use or not use of all the http verbs is not really the constraint, and it's perfectly acceptable to design an architecture that only supports POST.
  • Caching, high decoupling, lack of session state and layered architecture are the points few talk about but the most important to the success of a RESTful architecture.

If you don't spend most of your time crafting your document format, you're probably not doing REST.

查看更多
唯我独甜
6楼-- · 2019-01-12 18:58

It means using names to identify both commands and parameters.

Instead of names being mere handles or monikers, the name itself contains information. Specifically, information about what is being requested, parameters for the request, etc..

Names are not "roots" but rather actions plus input data.

查看更多
冷血范
7楼-- · 2019-01-12 19:01

I've learned the most from reading the articles published on InfoQ.com: http://www.infoq.com/rest and the RESTful Web Services book (http://oreilly.com/catalog/9780596529260/).

./alex

Disclaimer: I am associated with InfoQ.com, but this recommendation is based on my own learning experience.

查看更多
登录 后发表回答