Resty v0.4.0 Resty.Resource.Base View Source

This module is used to create resource struct that you’ll then be able to use with Resty.Repo and Resty.Resource.

Using the module

Resty.Resource.Base is here to help you create resource structs. The resource struct and its module holds informations about how to query the API such as the site, headers, path, auth etc…

This module (Resty.Resource.Base) defines a lot of macros to configure these options. You’ll be able to call them right after calling use Resty.Resource.Base.

defmodule MyResource do
  use Resty.Resource.Base

  set_site("site.tld")
  set_resource_path("/posts")

  attribute(:id)
  attribute(:name)
end

Attributes

Unlike ActiveResource Resty will need you to define which attributes should be allowed on the resource.

They are defined thanks to the attribute/1 macro. The attributes does not support type casting, types are taken as they come from the json serializer.

If you need to support more types than what json supports you can write your own Resty.Serializer.

Using the resource

Once you have a resource you can use it with Resty.Repo and Resty.Resource in order to query the API or get informations about retrieved resources.

MyResource |> Resty.Repo.all!()

Link to this section Summary

Functions

Add an header to the request sent from this resource

Add an attribute to the resource

Include the given root when serializing the resource

Sets the resource extension. The extension will be added in the URL

Sets the resource primary key. By default it is :id

Add a path to the resource

Add a site to the resource

Link to this section Functions

Link to this macro add_header(name, value) View Source (macro)

Add an header to the request sent from this resource

Link to this macro attribute(name) View Source (macro)

Add an attribute to the resource

Link to this macro include_root(value) View Source (macro)

Include the given root when serializing the resource

Link to this macro set_extension(extension) View Source (macro)

Sets the resource extension. The extension will be added in the URL.

Link to this macro set_primary_key(name) View Source (macro)

Sets the resource primary key. By default it is :id.

Link to this macro set_resource_path(path) View Source (macro)

Add a path to the resource

Link to this macro set_site(site) View Source (macro)

Add a site to the resource