Class: Arrow::Service
- Includes:
- Constants, HTMLUtilities, Loggable
- Defined in:
- lib/arrow/service.rb
Overview
This file contains the Arrow::Service class, a derivative of Arrow::Applet that provides some conveniences for creating REST-style service applets.
It provides:
* automatic content-type negotiation
* automatic API description-generation for service actions
* new action dispatch mechanism that takes the HTTP request method into account
* convenience functions for returning a non-OK HTTP status
Authors
-
Michael Granger <[email protected]>
Please see the file LICENSE in the top-level directory for licensing details.
Defined Under Namespace
Classes: StatusResponse
Constant Summary collapse
- SVNRev =
Subversion revision
%q$Rev$
- SvnId =
VCS Id
%q$Id$
- METHOD_MAPPING =
Map of HTTP methods to their Ruby equivalents as tuples of the form:
[ :method_without_args, :method_with_args ]
{ 'OPTIONS' => [ :options, :options ], 'GET' => [ :fetch_all, :fetch ], 'HEAD' => [ :fetch_all, :fetch ], 'POST' => [ :create, :create ], 'PUT' => [ :update_all, :update ], 'DELETE' => [ :delete_all, :delete ], }
- HTTP_METHOD_MAPPING =
Map of Ruby methods to their HTTP equivalents from either the single or collection URIs
{ :single => { :options => 'OPTIONS', :fetch => 'GET', :create => 'POST', :update => 'PUT', :delete => 'DELETE', }, :collection => { :options => 'OPTIONS', :fetch_all => 'GET', :create => 'POST', :update_all => 'PUT', :delete_all => 'DELETE', }, }
- BODILESS_HTTP_RESPONSE_CODES =
A registry of HTTP status codes that don’t allow an entity body in the response.
[ Apache::HTTP_CONTINUE, Apache::HTTP_SWITCHING_PROTOCOLS, Apache::HTTP_PROCESSING, Apache::HTTP_NO_CONTENT, Apache::HTTP_RESET_CONTENT, Apache::HTTP_NOT_MODIFIED, Apache::HTTP_USE_PROXY, ]
- SERIALIZERS =
The list of content-types and the corresponding message to send to transform a Ruby object to that content type, in order of preference. See #negotiate_content.
[ ['application/json', :to_json], ['text/x-yaml', :to_yaml], ['application/xml+rubyobject', :to_xml], [RUBY_MARSHALLED_MIMETYPE, :dump], ]
- DESERIALIZERS =
The list of content-types and the corresponding method on the service to use to transform it into something useful.
{ 'application/json' => :deserialize_json_body, 'text/x-yaml' => :deserialize_yaml_body, 'application/x-www-form-urlencoded' => :deserialize_form_body, 'multipart/form-data' => :deserialize_form_body, RUBY_MARSHALLED_MIMETYPE => :deserialize_marshalled_body, }
- DEFAULT_CONTENT_TYPE =
The content-type that’s used for HTTP content negotiation if none is set on the transaction
RUBY_OBJECT_MIMETYPE
- SPECIAL_JSON_KEY =
The key for POSTed/PUT JSON entity bodies that will be unwrapped as a simple string value. This is necessary because JSON doesn’t have a simple value type of its own, whereas all the other serialization types do.
'single_value'
Constants included from HTMLUtilities
HTMLUtilities::ARRAY_HTML_CONTAINER, HTMLUtilities::HASH_HTML_CONTAINER, HTMLUtilities::HASH_PAIR_HTML, HTMLUtilities::IMMEDIATE_OBJECT_HTML_CONTAINER, HTMLUtilities::IVAR_HTML_FRAGMENT, HTMLUtilities::OBJECT_HTML_CONTAINER, HTMLUtilities::THREAD_DUMP_KEY
Constants included from Constants
Constants::HTML_MIMETYPE, Constants::RUBY_MARSHALLED_MIMETYPE, Constants::RUBY_OBJECT_MIMETYPE, Constants::XHTML_MIMETYPE, Constants::YAML_DOMAIN
Constants inherited from Applet
Applet::SignatureStructDefaults
Instance Attribute Summary
Attributes inherited from Applet
#actions, #config, #run_count, #signature, #template_factory, #total_stime, #total_utime, #uri
Instance Method Summary collapse
-
#options(txn, *args) ⇒ Object
OPTIONS / Return a service document containing links to all :TODO: Integrate HTTP Access Control preflighted requests? (developer.mozilla.org/en/HTTP_access_control).
Methods included from HTMLUtilities
escape_html, make_html_for_object, make_object_html_wrapper
Methods inherited from Applet
#action_missing_action, applet_description, applet_maintainer, applet_name, applet_version, #average_usage, def_action, default_action, #delegable?, #delegate, inherited, inherited_from?, #initialize, #inspect, load, make_signature, method_added, normalized_name, #run, signature, signature?, template, validator
Methods inherited from Object
deprecate_class_method, deprecate_method, inherited
Constructor Details
This class inherits a constructor from Arrow::Applet
Instance Method Details
#options(txn, *args) ⇒ Object
OPTIONS / Return a service document containing links to all :TODO: Integrate HTTP Access Control preflighted requests?
(https://developer.mozilla.org/en/HTTP_access_control)
118 119 120 121 122 123 124 |
# File 'lib/arrow/service.rb', line 118 def ( txn, *args ) allowed_methods = self.allowed_methods( args ) txn.headers_out['Allow'] = allowed_methods.join(', ') txn.content_type = RUBY_OBJECT_MIMETYPE return allowed_methods end |