JSONAPI Elixir
A project that will render your data models into JSONAPI Documents.
Currently in beta status.
JSONAPI Support
- [x] Basic JSONAPI Document encoding [issue
- [x] Basic support for compound documents
- [ ] Links, issue#1
- [ ] Relationship links (handling relationships /user/1/image but only if its in a relationship :() issue#2
-
[x] Parsing of
sortquery parameter into Ecto Query order_by -
[ ] Parsing and limiting of
filterkeywords. issue#3 - [ ] Handling of sparse fieldsets
- [ ] Handling of includes
JSONAPI Elixir TODO
- [ ] Support full JSONAPI Spec
- [ ] Make dependency on Phoenix optional issue#4
- [ ] Make dependency on Ecto optional issue#4
- [ ] Create a plug to handle query param validation and cleanup issue#3
- [ ] Cleanup query/controller functions
- [ ] Tests
How to use
Simply add use JSONAPI.PhoenixView either to the top of your view, or to the web.ex view section and add the
proper functions to your view like so.
defmodule UserView do
use App.Web, :view
use JSONAPI.PhoenixView
def type, do: "user"
def attributes(model) do
Map.take(model, [:username, :created_at])
end
def relationships() do
%{
image: %{
view: ImageView
},
posts: %{
view: PostView
optional: true
}
}
end
def url_func() do
&user_url/3
end
end
is an example of a basic view. You can now call render normally in your phoenix application.
Philosophy
- Functions are better than Macro’s in almost every case
- DSL’s are great until you need something a little different. So use Maps.
- Make it work, worry about the rest later.
Other
- Feel free to make PR’s. I will do my best to respond within a day or two.
- If you want to take one of the TODO items just create an issue or PR and let me know so we avoid duplication.
- If you need help, I am on irc and twitter.