Packages
A serialization library implementing the jsonapi.org 1.0 spec suitable for use building JSON APIs in Phoenix and any other Plug based framework or app.
Current section
Files
Jump to
Current section
Files
ja_serializer
README.md
README.md
JaSerializer
============
jsonapi.org formatting of Elixir data structures suitable for serialization by
libraries such as Poison.
Warning: This is Alpha software and subject to breaking changes.
## TODO:
* Easy integration into Pheonix.
* Easy integration into Relax.
* Support of all required JSON API 1.0 features.
* Type Specs
* Edgecase/unit tests
* Pagination, meta and advanced links.
## Serializer DSL:
```elixir
defmodule MyApp.ArticleSerializer do
use JaSerializer
serialize "articles" do
location: "/articles/:id"
attributes [:title, :tags, :body, :excerpt]
has_one :author,
include: PersonSerializer,
field: :authored_by
has_many :comments,
link: "/articles/:id/comments",
end
def comments(model, _conn) do
Comment.for_article(model)
end
def excerpt(article, _conn) do
[first | _ ] = String.split(article.body, ".")
first
end
end
```
## Usage
```elixir
model
|> MyApp.ArticleSerializer.format(conn)
|> Poison.encode!
```
## License
JaSerializer source code is released under Apache 2 License. Check LICENSE file for more information.