In this document the same webservice example will be used to illustrate the different protocols. Its source code is in the last chapter (The example).



This chapter applies for all adapters, not just the native REST implementation.

The two REST protocols share common characterics.

Each function corresponds to distinct webpath that starts with the root webpath, followed by the controllers names if any, and finally the function name.

The example’s exposed functions will be mapped to the following paths:

  • /ws/persons/create
  • /ws/persons/get
  • /ws/persons/list
  • /ws/persons/update
  • /ws/persons/destroy

In addition to this trivial function mapping, a method option can be given to the expose decorator. In such a case, the function name can be omitted by the caller, and the dispatch will look at the HTTP method used in the request to select the correct function.

The function parameters can be transmitted in two ways (if using the HTTP method to select the function, one way or the other may be usable) :

  1. As a GET query string or POST form parameters.

    Simple types are straight forward :


    Complex types can be transmitted this way:


  2. In a Json or XML encoded POST body (see below)

The result will be returned Json or XML encoded (see below).

In case of error, a 400 or 500 status code is returned, and the response body contains details about the error (see below).



Implements a REST+Json protocol.

This protocol is selected if:

  • The request content-type is either ‘text/javascript’ or ‘application/json’
  • The request ‘Accept’ header contains ‘text/javascript’ or ‘application/json’
  • A trailing ‘.json’ is added to the path
  • A ‘wsmeproto=restjson’ is added in the query string


nest_result:Nest the encoded result in a result param of an object. For example, a result of 2 would be {'result': 2}


Type Json type
str String
unicode String
int Number
float Number
bool Boolean
Decimal String
date String (YYYY-MM-DD)
time String (hh:mm:ss)
datetime String (YYYY-MM-DDThh:mm:ss)
Arrays Array
None null
Complex types Object


The Json encoded result when the response code is 200, or a Json object with error properties (‘faulcode’, ‘faultstring’ and ‘debuginfo’ if available) on error.

For example, the ‘/ws/person/get’ result looks like:

    'id': 2
    'fistname': 'Monica',
    'lastname': 'Geller',
    'age': 28,
    'hobbies': [

And in case of error:

    'faultcode': 'Client',
    'faultstring': 'id is missing'



This protocol is selected if

  • The request content-type is ‘text/xml’
  • The request ‘Accept’ header contains ‘text/xml’
  • A trailing ‘.xml’ is added to the path
  • A ‘wsmeproto=restxml’ is added in the query string


Type XML example
<value>a string</value>
<value>a string</value>
<value nil="true"/>
Complex types


A xml tree with a top ‘result’ element.



A xml tree with a top ‘error’ element, having ‘faultcode’, ‘faultstring’ and ‘debuginfo’ subelements:

    <faultstring>id is missing</faultstring>



Implements the SOAP protocol.

A wsdl definition of the webservice is available at the ‘api.wsdl’ subpath. (/ws/api.wsdl in our example).

The protocol is selected if the request matches one of the following condition:

  • The Content-Type is ‘application/soap+xml’
  • A header ‘Soapaction’ is present


tns:Type namespace



Implements the Ext Direct protocol.

The provider definition is made available at the /extdirect/api.js subpath.

The router url is /extdirect/router[/subnamespace].



Base namespace of the api. Used for the provider definition.


Default notation for function call parameters. Can be overriden for individual functions by adding the extdirect_params_notation extra option to @expose.

The possible notations are :

  • 'named' – The function will take only one object parameter in which each property will be one of the parameters.
  • 'positional' – The function will take as many parameters as the function has, and their position will determine which parameter they are.

expose extra options

 Override the params_notation for a particular function.

The example

In this document the same webservice example will be used to illustrate the different protocols:

class Person(object):
    id = int
    lastname = unicode
    firstname = unicode
    age = int

    hobbies = [unicode]

    def __init__(self, id=None, lastname=None, firstname=None, age=None,
        if id:
   = id
        if lastname:
            self.lastname = lastname
        if firstname:
            self.firstname = firstname
        if age:
            self.age = age
        if hobbies:
            self.hobbies = hobbies

persons = {
    1: Person(1, "Geller", "Ross", 30, ["Dinosaurs", "Rachel"]),
    2: Person(2, "Geller", "Monica", 28, ["Food", "Cleaning"])

class PersonController(object):
    def get(self, id):
        return persons[id]

    def list(self):
        return persons.values()

    def update(self, p):
        if is Unset:
            raise ClientSideError("id is missing")
        persons[] = p
        return p

    def create(self, p):
        if is not Unset:
            raise ClientSideError("I don't want an id") = max(persons.keys()) + 1
        persons[] = p
        return p

    def destroy(self, id):
        if id not in persons:
            raise ClientSideError("Unknown ID")

class WS(WSRoot):
    person = PersonController()

root = WS(webpath='ws')