gjb
gjb

Reputation: 6317

Rails model talking to a REST service

I am creating a Rails application, which rather than using a database for the backend, will communicate with an external REST service.

This will work something like this:

Model.find(1)    # GET /model/1
Model.delete(1)  # DELETE /model/1
...

The business logic necessary to turn method calls into REST requests belongs in my model. However, there are several different servers that can be queried. Where do I put the connection logic so that:

  1. the queries are spread equally between servers?
  2. if a server becomes unavailable, the request is retried using a different server?

I am assuming this logic doesn't belong in the model, but I'm not sure where.

Any advice much appreciated.

Upvotes: 0

Views: 871

Answers (1)

Chirantan
Chirantan

Reputation: 15634

Have you considered using Active Resource? It is probably meant for almost exactly this use case, if I understand correctly.

Upvotes: 2

Related Questions