Blueprint for the RESTful API

NB This work is basically done: BluePrintRESTImplementation and REST Controller

We need to add support for more representations:

Also can add extra methods to the controller, such as:

Should we add a custom= option to enable customform sub-processing? (or a separate CustomController*)

  • most stuff is the same & the old GIS Layer sub-processing looks right split
  • however, for GIS, this is deprecated with the reworking inspired by the LAYER class

This is the S3 way of doing CRUD

Basic approach for the S3 architecture is to have a Web Services backend & a Javascript client front end.
RESTful APIs make this easier.

Web2Py generates URLs in this format:


These are generally used in a slightly RESTful way anyway (resources are URLs), e.g.:

/sahana/gis/features          # List_add

We have changed to URLs like these (see BluePrintRESTImplementation):

/sahana/gis/feature           # Acts as 'list' (or list_add if t2.logged_in)
/sahana/gis/feature/id        # Acts as 'display'

we could potentially do these:


but T2 requires ID to be the last argument, so can't do URLs like: /id/create (unless possibly by using

These are the benefits:

  • Consistency & ease of implementation of all basic functionality for new tables.
  • Simplified ability to create .represent widgets:
    def shn_list_item(table, resource, action, display='', extra=None):
        if extra:
            items = DIV(TR(TD(A(eval(display), _href=t2.action(resource, [action,]))), TD(eval(extra))))
            items = DIV(A(eval(display), _href=t2.action(resource, [action,])))
        return DIV(*items)

This is extended to export raw data in other formats, using the optional vars:


which was considered better than using another arg:


HTTP DELETE support has now been implemented in the REST controller.
Web2Py now supports HTTP PUT, so we plan to implement that too into the controller in order to make it turly REST-compliant.
This means a little work in clients but isn't too bad if we maintain consistency: no variations between add/create, view/display, edit/update, etc

Discussion of changes to Web2Py to make it more RESTful:

Web Services

Allows multiple client UIs

REST instead of SOAP

Less bloat, more GIS-friendly.

Python REST Servers

Python REST Clients

Javascript REST clients

Other REST clients


Last modified 10 years ago Last modified on 07/12/11 05:52:00
Note: See TracWiki for help on using the wiki.