Rapidax

Based on Rapidash

Installation

If available in Hex, the package can be installed as:

  1. Add rapidax to your list of dependencies in mix.exs:

    def deps do

     [{:rapidax, "~> 0.0.4"}]

    end

  2. Ensure rapidax is started before your application:

    def application do

     [applications: [:rapidax]]

    end

Documentation

This example use https://github.com/typicode/jsonplaceholder#how-to

Full example source code: https://github.com/victorlcampos/rapidax-example

Modules

defmodule RapidaxExample.Client do
  use Rapidax.Client.Http, [site: "http://jsonplaceholder.typicode.com"]
end

defmodule RapidaxExample.Resource.Post do
  use Rapidax.Resource, [name: "posts"]
end

defmodule RapidaxExample.Resource.Comment do
  alias RapidaxExample.Resource.Post

  use Rapidax.Resource, [name: "comments", belongs: %Post{}]
end

Showing a resource

  alias RapidaxExample.Client
  alias RapidaxExample.Resource.Post

  {:ok, body} = Client.query(%Client{}, %Post{id: "1"})

Listing resources

  alias RapidaxExample.Client
  alias RapidaxExample.Resource.Post

  {:ok, body} = Client.query(%Client{}, %Post{})

Creating a resource

  alias RapidaxExample.Client
  alias RapidaxExample.Resource.Post

  {:ok, body} = Client.create(%Client{}, %Post{params: [title: "foo", bar: "bar", userId: 1]})

Updating a resource

  alias RapidaxExample.Client
  alias RapidaxExample.Resource.Post

  {:ok, body} = Client.update(%Client{use_patch: false}, %Post{id: "1", params: [id: 1, title: "foo", bar: "bar", userId: 1]})

Updating a resource

  alias RapidaxExample.Client
  alias RapidaxExample.Resource.Post

  {:ok, body} = Client.update(%Client{use_patch: true}, %Post{id: "1", params: [title: "foo"]})

Deleting a resource

  alias RapidaxExample.Client
  alias RapidaxExample.Resource.Post

  {:ok, body} = Client.destroy(%Client{}, %Post{id: "1"})

Filtering resources

  alias RapidaxExample.Client
  alias RapidaxExample.Resource.Post

  {:ok, body} = Client.query(%Client{}, %Post{params: [userId: "1"]})

Nested resources

  alias RapidaxExample.Client
  alias RapidaxExample.Resource.Post
  alias RapidaxExample.Resource.Comment

  {:ok, body} = Client.query(%Client{}, %Comment{belongs: %Post{id: "1"}})