m9t

m9t

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?

First Post!

zachdaniel

zachdaniel

Creator of Ash

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.

Most Liked

m9t

m9t

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:

Where Next?

Popular in Questions Top

vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New

Other popular topics Top

Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
greenz1
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
AstonJ
Seen any cool LiveView demos, sample apps or examples? Please post them here! :003:
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
sergio
Kind of like when jquery came out, it was super necessary. Existing drag and drop libraries have a bunch of baggage to support old browse...
New

We're in Beta

About us Mission Statement