Current section
12 Versions
Jump to
Current section
12 Versions
Compare versions
3
files changed
+16
additions
-10
deletions
| @@ -11,7 +11,7 @@ Features: | |
| 11 11 | |
| 12 12 | Example endpoint view generated by Carve: |
| 13 13 | |
| 14 | - ``` |
| 14 | + ```json |
| 15 15 | { |
| 16 16 | "result": { |
| 17 17 | "id": "D3Wcorr0oa", |
| @@ -49,7 +49,7 @@ end | |
| 49 49 | |
| 50 50 | To configure custom hashing salt, add to `config.exs`: |
| 51 51 | |
| 52 | - ```ex |
| 52 | + ```elixir |
| 53 53 | config :carve, |
| 54 54 | salt: "your-secret-salt", |
| 55 55 | min_length: 10 |
| @@ -59,7 +59,7 @@ config :carve, | |
| 59 59 | |
| 60 60 | In your Phoenix JSON view, just declare how your endpoint should look like: |
| 61 61 | |
| 62 | - ```ex |
| 62 | + ```elixir |
| 63 63 | defmodule UserJSON do |
| 64 64 | use Carve.View, :user |
| 65 65 | |
| @@ -76,15 +76,15 @@ And that's it -- this macro will make `index(%{ result: users })` and `show(%{ r | |
| 76 76 | |
| 77 77 | Of course, just formatting the view alone is not Carvers only point; you can declare the links of each view, and Carve will automatically output them for the client: |
| 78 78 | |
| 79 | - ```ex |
| 79 | + ```elixir |
| 80 80 | defmodule UserJSON do |
| 81 81 | use Carve.View, :user |
| 82 82 | |
| 83 | - # Return the links of a given user |
| 83 | + # Return the links of a given user as ViewModule => id |
| 84 84 | links fn user -> |
| 85 85 | %{ |
| 86 | - FooWeb.TeamJSON => user.team_id, |
| 87 | - FooWeb. ProfileJSON => user.profile_id |
| 86 | + FooWeb.TeamJSON => user.team_id, # You can also pass list of ids or the Ecto record(s) |
| 87 | + FooWeb. ProfileJSON => user.profile_id |
| 88 88 | } |
| 89 89 | end |
| 90 90 | |
| @@ -104,9 +104,15 @@ defmodule UserJSON do | |
| 104 104 | end |
| 105 105 | ``` |
| 106 106 | |
| 107 | + After activating `show` and `index` methods in the controller: |
| 108 | + |
| 109 | + ```elixir |
| 110 | + render(conn, :index, result: requests) # or render(conn, :show, result: record) |
| 111 | + ``` |
| 112 | + |
| 107 113 | Example response Carve will render for this view: |
| 108 114 | |
| 109 | - ```ex |
| 115 | + ```json |
| 110 116 | { |
| 111 117 | "result": { |
| 112 118 | "id": "D3Wcorr0oa", |
| @@ -1,6 +1,6 @@ | |
| 1 1 | {<<"links">>,[{<<"GitHub">>,<<"https://github.com/azer/carve">>}]}. |
| 2 2 | {<<"name">>,<<"carve">>}. |
| 3 | - {<<"version">>,<<"0.1.1">>}. |
| 3 | + {<<"version">>,<<"0.1.2">>}. |
| 4 4 | {<<"description">>, |
| 5 5 | <<"DSL for building JSON APIs fast. Creates endpoint views, renders linked data automatically.">>}. |
| 6 6 | {<<"elixir">>,<<"~> 1.12">>}. |
| @@ -4,7 +4,7 @@ defmodule Carve.MixProject do | |
| 4 4 | def project do |
| 5 5 | [ |
| 6 6 | app: :carve, |
| 7 | - version: "0.1.1", |
| 7 | + version: "0.1.2", |
| 8 8 | elixir: "~> 1.12", |
| 9 9 | start_permanent: Mix.env() == :prod, |
| 10 10 | deps: deps(), |