Adding custom routes with AshJsonApi

Is it possible to add custom routes like:
json_api do
type "many_actions"
routes do
base "/many_actions"
post "/another", :another
end
end
json_api do
type "many_actions"
routes do
base "/many_actions"
post "/another", :another
end
end
Looks like you can do something similar with relationships, but is there a way to expose additional actions on the resource? This is related to the many issues on JSON:API, but most of these have to do with discoverability; the spec is fairly wide-open when it comes to adding additional routes in general. https://github.com/json-api/json-api/issues/745 https://github.com/json-api/json-api/issues/684 https://github.com/json-api/json-api/issues/773 https://github.com/json-api/json-api/pull/1268 https://github.com/json-api/json-api/pull/1254
5 Replies
\ ឵឵឵
\ ឵឵឵OP3y ago
Bump
ZachDaniel
ZachDaniel3y ago
Sorry, didn't see this 🙂 I'm not exactly sure I understand the question though You can add as many route as you want, connected to as many actions as you want
\ ឵឵឵
\ ឵឵឵OP3y ago
Maybe I'm just not locking down the syntax for it. I tried a couple of ways including as above but it doesn't seem to be happy. Is the way to go to add additional routes blocks with different bases?
ZachDaniel
ZachDaniel3y ago
base "/type"
post :open, route: "/open"
update :add_comment, route: "/:id/add_comment"
update :remove_comment, route: "/:id/remove_comment"
update :close, route: "/:id/close"
base "/type"
post :open, route: "/open"
update :add_comment, route: "/:id/add_comment"
update :remove_comment, route: "/:id/remove_comment"
update :close, route: "/:id/close"
Something like that is what you'd want you can only have one base multiple route blocks won't work In fact if you did
routes do
base "/foo"
end
routes do
base "/bar"
end
routes do
base "/foo"
end
routes do
base "/bar"
end
The second base would overwrite the first
\ ឵឵឵
\ ឵឵឵OP3y ago
Yeah, that was my understanding actually, that it would behave like all the other transformers and merge the route blocks together. Great, that's the missing piece of the syntax though! Do you mind approving the workflow for https://github.com/ash-project/ash/pull/528 ? Overlaps with the PR we talked about.

Did you find this page helpful?