Last active
August 29, 2015 14:11
-
-
Save c-spencer/13b8bcc1a8d4baf4e803 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
chrismccord
commented
Dec 12, 2014
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