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

via_get { ... }

The directive activates the routing of GET requests to the application. Depending on it’s context GET requests deliver arrays of or single resources/model-instances as JSON data.

via_get may appear inside the directives:

The directive’s block contains allow (required) and handler directives (optional) , which define run-time code to decide on authorization and contain custom business logic if the built-in default handlers are not appropriate.

Example

expose(Person) {
  readables :first_name, :last_name

  via_get {
    allow do |*args|
      true
    end

    ## implicit handler
    # handler do |model, uri_params|
    #   model
    # end
  }
}

Request:

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

Response:

{
    "self"      : "https://example.com/people/44",
    "first_name": "John",
    "last_name" : "Silver"
}