Can I modify path_params before executing update action in ash_json_api patch api?

I have an actor in Conn.private and I want to use actor.id in patch api read_action.
By reading the ash_json_api source code, I found that read_action uses only path_params.
So I want to put actor.id in path_params before executing read_action in patch api.

Can I do this in my application code? (I think it’s not possible for now.)

(self reply)
I think this could be done using Plug in the Router.
However, I want to achieve this in a more flexible way, allowing it to differ by each actions.
+ not using Plug, using features in ash_json_api

Are you setting the actor using Ash.PlugHelpers.set_actor ? The actor is available in all actions, no need to include their id in routes.

Yes. I am using it. This was just an example (but bad one :rofl:).
+ Another example.
Copy a value in request body params to path_params, to use in read_action.

:thinking: I may not fully understand, but based on what I think you’re getting at, you just need to make sure that you have

  1. a path parameter in the route
  2. a corresponding argument on the action
json_api do
  routes do
    base "/things"

    index "path/with/:foo"
  end
end

actions do
  read :things_by_foo do
    argument :foo, :string, allow_nil?: false

    prepare fn query, _ -> 
      query.arguments.foo # => will have the path param value
    end
  end
end

Then you can hit /things/path/with/some_value_for_foo.
and then the foo argument will be "some_value_for_foo".

Sorry for poor explanation.
In short, I want to use body params (not path params) in patch api read_action.

Ah, right. Currently that is not possible.

But why?
It’s not hard to make ash_json_api to use also query params and body params in read action, I think.

PRs welcome :slight_smile: