What exactly is REST architecture and how is it implemented in Rails?

前端 未结 5 814
执念已碎
执念已碎 2020-12-30 06:23

This is what I think of REST architecture.

For every resource, there is an unique URI.

We can manipulate that object using its URI and HTTP actions [POST, GE

5条回答
  •  情歌与酒
    2020-12-30 06:32

    I'd start with chapter 5 of Roy Fielding's dissertation. There are a few basic principles:

    • Resources: A resource could be typically something that you expose to the outside world as a part of your service. The emphasis is on identifying the resources (e.g: Book, UserList, CalculateDistance)
    • URI: Give every resource an identifier (e.g: example.com/books/7654)
    • Uniform interface: Use standard methods like GET, PUT. POST, DELETE, HEAD, OPTIONS
    • Representations: A resource can have multiple representations. For example, a GET on a book can return a PDF of that book's content, a HTML of the content and for that matter even a GIF with the book cover and so on. A representation is essentially a collection of all the data and markup.
    • Hypermedia: This one, in my opinion, is a very important principle. Implementation of this principle takes your application far ahead of the regular CRUD-like definitions the REST-style is boxed into. HATEOAS is the acronym which stands for Hypermedia as the engine of application state. When you click on a link or submit a form you are changing the state of the application, that's happening via hyperlinks (or hypermedia). There is very little coupling between a server and a client. A client navigates through the application via the links provided by the server. (there is a lot of discussion in the blogosphere on this priniciple ...) [Also look at Restfulie]

    I have recently answered a question on good resources to learn REST, could be helpful.

    I'm not familiar with Rails, so not addressing that part of the question.

提交回复
热议问题