barracuda v0.2.0 Barracuda.Compiler

The DSL used to describe the API has stanzas like

call :create, path: “customers.json”, verb: :post, required: [:first_name, :last_name, :email], container: “customer”, expect: 201, api: :v1

create/1 will be the name of the generated function.

The HTTP action will be a POST to the path customers.json prepended with the value of base_url from the application config. A result code of 201 is required

The :first_name, :last_name, and :email parameters must be specified or the request will not be generated. These and any additional parameters will be JSON encoded ({“key”:”value”}) and then wrapped inside the customer conatiner ({“customer”:{“key”:”value”}}).

If the path has placeholders:

call :lookup,
path: "resource/{:type}/{:id}/",
required: [:id, :type]

The values specified for :id and :type will be interpolated into the path string. If there is only one required parameter and only one placeholder then the key is optional. For instance, the function generated with this stanza:

call :lookup,
path: "resource/{:id}",
required: [:id]

may be called as either lookup(id: 123) or lookup(123).

The :expect option defaults to :200; :verb defaults to :get. Required headers will be retrieved from

In the case of the :lookup stanza, two functions are generated:

lookup/1 which returns {:ok, status_code, headers, body} (similar to hackney) or {:error, msg, {options, response}}. The msg might be descriptive; options is a keyword list representing the stanza as defined. The body is decoded from the JSON into an atom keyed map.

lookup!/1 which returns only the body, decoded, upon success and raises Barracuda.Error otherwise.

Summary

Functions

compile(calls, module, config)

Macros

call(name, options)