AlpacaElixir v2.2.0 Alpaca.Resource View Source
This module uses a macro to allow us to easily create the base HTTP methods for an Alpaca Resource. Most Alpaca requests have a common set of methods to get a specific resource by ID, list all resources, update the resource, delete all resources and delete a resource by id. By using this macro we can easily build out new API endpoints in a single line of code.
Example
defmodule Alpaca.NewResource do
use Alpaca.Resource, endpoint: "new_resources"
end
We that single line of code we will now have a list/0
, list/1
,
get/1
, get/2
, create/1
, edit/2
, delete_all/0
, and delete/1
functions for a given resource.
You can also exclude functions from being created by passing them as a list
of atoms with the :exclude
keyword in the resource definition.
Example
defmodule Alpaca.NewResource do
use Alpaca.Resource, endpoint: "new_resources", exclude: [:delete_all, :delete]
end
This definition will not create a delete_all/0
or delete/1
endpoint for the
new resource you have defined.