···6060# Use Jason for JSON parsing in Phoenix
6161config :phoenix, :json_library, Jason
62626363+# ash json api
6464+config :mime, :types, %{
6565+ "application/vnd.api+json" => ["json"]
6666+}
6767+6868+config :mime, :extensions, %{
6969+ "json" => "application/vnd.api+json"
7070+}
7171+6372# Import environment specific config. This must remain at the bottom
6473# of this file so it overrides the configuration defined above.
6574import_config "#{config_env()}.exs"
+1-1
lib/sower.ex
···11defmodule Sower do
22- use Ash.Domain
22+ use Ash.Domain, extensions: [AshJsonApi.Domain]
3344 resources do
55 resource Sower.Inputs.Repository
···11defmodule Sower.Seed do
22 use Ash.Resource,
33 data_layer: AshPostgres.DataLayer,
44- domain: Sower
44+ domain: Sower,
55+ extensions: [AshJsonApi.Resource]
5667 @derive {Jason.Encoder, only: [:id, :name, :type, :out_path, :branch, :repository_id]}
78···119120120121 identities do
121122 identity :seed, [:name, :type, :out_path, :branch]
123123+ end
124124+125125+ json_api do
126126+ type "seed"
127127+128128+ routes do
129129+ base "/seeds"
130130+131131+ get :read
132132+ end
122133 end
123134124135 postgres do
+12-1
lib/sower/tree.ex
···11defmodule Sower.Tree do
22 use Ash.Resource,
33 data_layer: AshPostgres.DataLayer,
44- domain: Sower
44+ domain: Sower,
55+ extensions: [AshJsonApi.Resource]
5667 @types [:nixos, :"home-manager", :"nix-darwin"]
78···60616162 identities do
6263 identity :tree, [:name, :type]
6464+ end
6565+6666+ json_api do
6767+ type "tree"
6868+6969+ routes do
7070+ base "/trees"
7171+7272+ get :read
7373+ end
6374 end
64756576 postgres do
···33 Then he told them many things in parables, saying: “A farmer went out to sow his seed. As he was scattering the seed, some fell along the path, and the birds came and ate it up. Some fell on rocky places, where it did not have much soil. It sprang up quickly, because the soil was shallow. But when the sun came up, the plants were scorched, and they withered because they had no root. Other seed fell among thorns, which grew up and choked the plants. Still other seed fell on good soil, where it produced a crop—a hundred, sixty or thirty times what was sown. Whoever has ears, let them hear.”
44 </p>
55</div>
66-
+6
lib/sower_web/json_api_router.ex
···11+defmodule SowerWeb.JsonApiRouter do
22+ use AshJsonApi.Router,
33+ domains: [Module.concat(["Sower"])],
44+ json_schema: "/json_schema",
55+ open_api: "/open_api"
66+end
+2
lib/sower_web/router.ex
···3333 get("/seeds", SowerWeb.SeedController, :list)
3434 get("/seeds/latest", SowerWeb.SeedController, :find_latest)
3535 post("/seeds", SowerWeb.SeedController, :new)
3636+3737+ forward "/json", SowerWeb.JsonApiRouter
3638 end
37393840 # Enable LiveDashboard and Swoosh mailbox preview in development