Skip to content

Instantly share code, notes, and snippets.

@c-spencer
Last active August 29, 2015 14:11
Show Gist options
  • Save c-spencer/13b8bcc1a8d4baf4e803 to your computer and use it in GitHub Desktop.
Save c-spencer/13b8bcc1a8d4baf4e803 to your computer and use it in GitHub Desktop.
defmodule MyApp.UserResource do
use Phoenix.Resource
defp get_user(%{"id" => id}) do
Repo.get(User, id)
end
def supported_formats do
["html", "json", "xml"]
end
def authorized?(conn, params) do
true
end
def handle_ok("json", conn, params) do
user = get_user(params)
%{
name: user.name,
email: user.email
}
end
def handle_ok("xml", conn, params) do
XMLBuilder.build(get_user params)
end
def handle_ok("html", conn, params) do
render conn, "show.html", %{user: get_user(params)}
end
end
@c-spencer
Copy link
Author

There's a basic implementation of this port at https://github.com/sysdea-libs/wrangle now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment