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 ‘readables’

readables {ATTRIBUTE},{ATTRIBUTE},...

Declares which attributes of the model are to be exposed by the JSON representation. All listed attributes (by Symbol) are expected to be attributes or instance methods of the model class, that are called when the representation is built. The returned value must at least respond to #to_json.

Attributes exposed with readables but not with writables are read-only. Attempts to update them with PATCH are silently ignored.

The via_get and allow directives are also required to route and authorize GET requests and to canonical URIs of resources/model-instances.

Example

expose(Person) {
  readables :first_name, :last_name, :phone
  via_get {
    allow do |*args|
      true
    end
  }
}

would yield a representation for GET https://example.com/people/42:

{
    "self"      : "https://example.com/people/42",
    "first_name": "Jason",
    "last_name" : "Plant",
    "phone"     : "082-0193878560"
}

None of the attributes/properties can be changed via HTTP API.