wiki:S3/S3REST/s3_rest_controller

Version 10 (modified by Dominic König, 14 years ago) ( diff )

--

s3_rest_controller

Introduction

The so-called REST Controller (function s3_rest_controller()) is a helper function to easily apply the RESTful API of the S3Resource class to your controller.

s3_rest_controller does:

  • parse and execute the incoming HTTP request on the specified resource
  • populate and hand-over additional view components
  • choose and set the response view template (response.view)

Syntax

output = s3_rest_controller(prefix, resourcename, **attr)
  • prefix is the application prefix of the resource
  • resourcename is the name of the resource (without prefix)
  • attr are any additional view variables
  • output contains the result of the request and can be returned from the controller as-is
    • in interactive view formats, this is a dict of view variables

Additional View Variables

In interactive view formats, any additional named arguments in the s3_rest_controller argument list will be added to the view variables:

  • any callable argument will be invoked with the S3Request as first and only argument, and its return value will be added to the view variables
  • any non-callable argument will be added to the view variables as-is
  • any argument that gives None will remove this key from the view variables

A typical use-case is rheader:

def my_rheader(r):
  if r.interactive and r.component:
    # Code producing the rheader...
    return rheader
  else:
    return None

output = s3_rest_controller(prefix, name, rheader=my_rheader)

If my_rheader(r) gives something else than None, then this value is added as rheader to the view variables.


DeveloperGuidelines

Note: See TracWiki for help on using the wiki.