View on GitHub

Toast Manual

Toast is a Rack application that hooks into Ruby on Rails. It exposes ActiveRecord models as a web service (REST API).

Version 1.0.*

Table of Contents - Directives

Directive ‘single’

single({SINGLE}) { ... }

Declares that a model exposes a class method returning a single instance. {SINGLE} is the name of a class method (as Symbol).

Singles are exposed by their URI, which has the form:

https://{HOST}/{PATH}/{RESOURCE}/{SINGLE}?{PARAMS}, where

Within the block it must be declared which methods the exposed URI accepts. This is done by the directives which have further sub-directives for permissions and custom handlers:

Only GET is available. For updates or deletions use the canonical URI of the resource/model instance.

Note, that also pre-defined methods of ActiveRecord can be exposed. E.g. :first, :second, :last.

expose(Person) {
  readables :first_name, :last_name
  single(:first) {
    via_get {
      allow do |*args|
        true # allow for all
      end
    }
  }
}

gives:

GET https://example.com/people/first:

{
    "self"      : "https://example.com/people/1",
    "first_name": "John",
    "last_name" : "Smith"
}