[Seaside-dev] Seside-REST

Philippe Marschall philippe.marschall at gmail.com
Thu Sep 10 09:24:27 UTC 2009


Hi

This is some fallout from ESUG. Currently if you wanted to create a
RESTful webservice in Seaside it was more cumbersome than it needed to
be. You basically had to do all the URL parsing yourself. Seside-REST
tries to address this by binding certain URLs to certain Smalltalk
methods.

What you need to get started:
 1. latest Seaside 3.0
 2. Seaside-REST [1]
 3. make a subclass of WARestfulHandler
 4. implement #createRoutes
 5. implement the methods
 6. register the handler (see caveats)

#createRoutes answers the routes that bind a URLs to methods. There
are two types of routes, simple and complex ones.

Simple routes are defined by an HTTP method and a Smalltalk method
selector. The take the unconsumed path elements and turn them into
method arguments. The number of arguments of the selector has to match
the number of unconsumed path elements. Binary selectors are not
supported. For example:
WARoute post: #createNewDocumentInDatabase:
matches POST request with one unconsumed path element. It will send
#createNewDocumentInDatabase: with this path element to self.

Complex routes can also match parameters, allow reordering and unbound
arguments. For example:
WARoute get: '/{2}/_uuids?count={1}' selector: #getUuids:forDatabase:
matches GET request with two unconsumed path elements the later being
'_uuids' and a parameter named 'count'. It will send
#getUuids:forDatabase: to self with the parameter value being the
first argument and the first path element being the second argument.

This is very much experimental code and subject to change. It doesn't
have any docs and likely bugs. It doesn't do any serialization or
deserialization, you can use Magritte-JSON [2] for this or something
similar. If you want to see an example head over to [3].

Caveats
- changing #createRoutes doesn't take any effect, you need to
reinitialize the object or reregister the handler
- doesn't support content negotiation
- doesn't support partial mappings
- doesn't support matching HTTP headers
- and probably a lot more

 [1] http://www.squeaksource.com/Seaside29Addons/
 [2] http://source.lukas-renggli.ch/magritteaddons
 [3] http://www.squeaksource.com/CouchDB

Cheers
Philippe


More information about the seaside-dev mailing list