Saurabh Sharan
Saurabh Sharan

Reputation:

When to make models RESTful?

Just wondering -- how do you know when to add map.resources for a particular model? All of them? The ones you want to be accessible by a public API?

Thanks.

Upvotes: 0

Views: 168

Answers (3)

Waseem
Waseem

Reputation: 8402

First of all we do not add map.resources for models. We add them for our controllers.

The map.resources and map.resource generate RESTful urls which do not address a model and its corresponding actions; it addresses only the resource itself. A resource is a combination of dedicated controller and a model.

Usually if you are going to make a complete RESTful app, you add map.respources for all of your controllers. After doing this, you can define all your CRUD(index, new, create, edit and update) actions in the corresponding controller which access a particular resource. The actions which can be carried out on a particular resource depend upon the policies defined by your application. If you have some resource which you do not want the users(via your application front end or via some API) of your application see(or something like that), you simply don't define a show action in the corresponding controller. Similarly other actions.

You should have a look at this small tutorial about REST and Rails. The lines above in the quote are shamelessly copied from the same document.

Upvotes: 1

Martin v. Löwis
Martin v. Löwis

Reputation: 127457

  1. the model shouldn't reveal any secret or protected data (such as encrypted passwords)
  2. when you provide external access to a model, you essentially make it a public API. You should then commit to document it, maintain it, and keep it stable (in particular when you find that it is being used).

Upvotes: 0

djna
djna

Reputation: 55907

Yes, you are deliberately exposing something as a kind of service, decide whetehr that's want you want to do. Exposing a service implies a certain commitment to your users, general advice keep the number of exposed services under control, they incur onging support debt.

Upvotes: 1

Related Questions