JSONAPI Elixir
A project that will render your data models into JSONAPI Documents.
Currently in beta status.
JSONAPI Support
- Basic JSONAPI Document encoding
- Basic support for compound documents
- Links
- Relationship links (specifically handling relationships /user/1/image but only if its in a relationship :()
- Parsing of
sortquery parameter into Ecto Query order_by - Parsing and limiting of
filterkeywords into - Handling of sparse fieldsets
- Handling of includes
JSONAPI Elixir TODO
- Support full JSONAPI Spec
- Make dependency on Phoenix optional
- Make dependency on Ecto optional
- Tests
How to use
A View is simply a module that define certain callbacks to configure proper rendering of your JSONAPI documents.
defmodule UserView do
use JSONAPI.PhoenixView
def url_func() do
&App.Helpers.user_url/3
end
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
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 untill you need something a little different. So use Maps.
- Make it work, worry about fast and pretty later.
Contributions
- 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.