pezra / exhal

Use HAL APIs with ease
MIT License
22 stars 15 forks source link

Add support for some JSON-patch operations #49

Closed d-mart closed 7 years ago

d-mart commented 7 years ago
pezra commented 7 years ago

How would a phoenix action look like for this interface?

d-mart commented 7 years ago

How would a phoenix action look like for this interface?

Something like this (generic/psuedo code, but adapted from a real use)

def update(%{method: "PATCH"} = conn, %{"_json" => change_list, "id" => id}) do
  my_thing = Repo.Thing.get(id)  # generic Ecto.Repo lookup
  updated_thing = my_thing
  |> Map.from_struct
  |> ThingTranscoder.patch!(change_list)

  case Repo.Thing.changeset(my_thing, updated_thing) |> Repo.update! do
    {:error, error} -> # use conn to return error
    {:ok, _} -> # use conn to return 204
  end
end
pezra commented 7 years ago

released as 5.2.1

pezra commented 7 years ago

thanks!

d-mart commented 7 years ago

Awesome, thanks!