Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I agree in the case of HTML rendering, but I write a lot of JSON APIs and putting the JSON definition in the View has been very pleasant. It didn't say in OP, but how does this change an API? Maybe a `GreetJSON` instead of `GreetHTML`?


Correct. You write a moduleJSON. So this is about what we have for one of our controller/views:

  defmodule MyWeb.SystemStateJSON do
    def index(%{summary: summary}) do
      %{data: summary}
    end
  end


Yes, exactly like that.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: