Strelka::App::

RestResources

module
Extended With
Strelka::Plugin

RESTful resource utilities for Strelka::App.

This plugin allows you to automatically set up RESTful service resources for Sequel::Model-derived classes.

For example, if you have a model class called ACME::Customer for tracking customer data, you can set up a RESTful resource in your Strelka app like this:

require 'strelka'
require 'acme/customer'

class ACME::RestServices < Strelka::App
    plugins :restresources
    resource ACME::Customer
end

Assuming the primary key for customers is a column called 'id', this will install the following routes:

options 'customers'
get 'customers'
get 'customers/:id'
post 'customers'
post 'customers/:id'
put 'customers'
put 'customers/:id'
delete 'customers'
delete 'customers/:id'

The restresources plugin depends on the routing, negotiation, and parameters plugins, and will load them automatically if they haven't been already.

Goals:

Composite resources generated from associations

Honor If-unmodified-since and If-match headers

Support the 'fields' parameter for GET /collection

Support reverse-ordering (via '-fieldname'?)

Caching support (ETag, If-modified-since)

Means of tailoring responses for requests for which the response isn't clearly specified in the RFC (DELETE /resource)

Sequel plugin for adding links to serialized representations

Caveats / Known Problems

Supported/Planned Options

The 'resource' directive accepts options that control which methods it creates for the specified resource:

:readonly => false

:include => <array of verbs>

:exclude => <array of verbs>

:subsets => <boolean or array>

:associations => <boolean or array>

Constants

DEFAULTS

Resource route option defaults