Redirect on GET request

Hi!

I want to do a redirect on a get route, but I can’t find how to do it in the ash or ash-json-api docs. Basically I want this in my resource:

    routes do
      get :signed_url do
        route "/:id/signed_url"
      end
    end

Which will then respond with a temporary redirect to a signed url if the actor is authorized by the policy for the action_type(:read).

I tried playing around with modify_conn, but couldn’t get it to work unfortunately. Is this supported or not (yet :slight_smile:) possible?

Hmm…I might suggest doing this with just a regular route and phoenix controller? Although I guess you want this to show up in your open api schema :thinking: What you can do is use the modify_open_api option to use AshJsonApi.Router to add the operation manually if it is defined as a custom route.

use AshJsonApi.Router,
  ...
  modify_open_api: {__MODULE__, :modify_open_api, []}

def modify_open_api(spec, _conn, _opts) do
   # add an operation to `spec`
end 

I assume something about redirecting in the modify_conn callback causes an issue because we still attempt to render a response or something along those lines. We can potentially check for a redirect and not render a response, or check if the conn has been halted in some way.

But to be sure I’d need to know specifically how it didn’t work when you tried it.

Hahah yeah that may be a better idea! I don’t really need the schema for this, but I was so deep into setting everything up with ash_json_api, that I didn’t think about NOT using it anymore :smile:

1 Like