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

前端 未结 5 827
执念已碎
执念已碎 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:40

    As you might notice there are 4 HTTP actions but the basic CRUD operations in a typical web app require 7 different actions. Some of these don't actually do anything (like /new and :id/edit) and thus are sort of parallel to REST architecture. Also the index action does not act on the resource but rather on a collection of resource (thus also a unique url).

    So the basic 4 HTTP actions map to a resource like this:

    • GET maps to show -> get /teams/:id
    • PUT maps to update -> put /teams/:id
    • DELETE maps to destroy -> delete /teams/:id
    • POST is a bit of an exception, since the resource is not yet existant thus it maps to the base /teams

    So to summarize: each resource has its own unique url, plus rails defines a few additional urls for UI and collection purposes.

提交回复
热议问题