1

Is there a way to internally redirect in Padrino? I am writing a RESTful service, no HTML response of browser client. I have a resource, lets say, xyz.

MyApp.controllers :xyz

I have two routes in a controller:

put :index, :with => :xyz_id do...end

and

get :show, :map => '/xyz/:xyz_id' do...end

Now to simplify (and centralize) view (which is a JSON document) creation, I want to just internally redirect the control so that it processes the :show method after creating the resource. Hence, for a client of the service, PUT /xyz/1234 will create a new resource and return the same and GET /xyz/1234 will return the resource if it exists.

Is there a way to INTERNALLY (not a 302 response sent to the client) redirect to get :show method from the put :index method (after creating the resource)? Something like:

redirect (:xyz, :index, {:xyz_id => '1234'})
constantine1
  • 427
  • 1
  • 5
  • 12

1 Answers1

1

First of, you can put logic behind the showing data into separate function that you can call from both GET and PUT routes. If you really want to pass processing to a different route, you can do it with rack's call method:

put '/foo' do
  # putting related stuff
  call env.merge('REQUEST_METHOD' => 'GET')
end
Slartibartfast
  • 8,735
  • 6
  • 41
  • 45