module Strelka::App::RestResources
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
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>
-
:filters => <boolean or array>
-
:associations => <boolean or array>
-
:composite =< <boolean or array>
Constants
- DEFAULTS
Resource route option defaults
Private Instance Methods
Add parameter validations for the given columns
of the specified resource object rsrcobj
to the specified parameter validator
.
# File lib/strelka/app/restresources.rb, line 677 def add_resource_params( validator, rsrcobj, *columns ) columns = rsrcobj.columns if columns.empty? columns.each do |col| config = rsrcobj.db_schema[ col ] or raise ArgumentError, "no such column %p for %p" % [ col, rsrcobj ] validator.add( col, config[:type] ) unless validator.param_names.include?( col.to_s ) end end