1

I have an app where I try to adhere to REST.

The app receives requests for external links that don't belong to the app, so the sole purpose of the action is to redirect the request to the external URL.

My suggestion is to have the following controller/action: redirects_controller#create.

Is my thinking correct or should it be the show action instead?

Dave Schweisguth
  • 36,475
  • 10
  • 98
  • 121
Fellow Stranger
  • 32,129
  • 35
  • 168
  • 232

2 Answers2

0

REST (apart from Rails) is about using the correct HTTP method for the correct action. The Rails part is just using the conventional controller action for a given HTTP method.

So, if you're doing a 301 or 302 redirect to another page, which browsers handle by issuing a GET request to the URL in the redirect response's Location header, do it in a show action. This will allow the user's browser to cache the other page when appropriate, and to not notify the user before redirecting.

(There is a way to redirect POSTs, but you didn't mention it so I expect you're talking about regular 301/302 redirects.)

Community
  • 1
  • 1
Dave Schweisguth
  • 36,475
  • 10
  • 98
  • 121
0

Coming from a Java background, the REST actions must be related to CRUD operations. Requests that do not change the resource like in your case where the intent is to redirect to another page must be tied to a GET verb or show in your example.

If you were to create a new resource you would use POST. A more detailed explanation can be found in Richardson's rest maturity model level 2

rghome
  • 8,529
  • 8
  • 43
  • 62
Javier
  • 11
  • 1