wiki:TG2.1DispatchDifferences
Warning: Can't synchronize with repository "(default)" (Unsupported version control system "svn": No module named svn). Look in the Trac log for more information.

This document is intended to describe the subtle differences between tg2.0 and 2.1 dispatch, as it pertains to RestController?

1) Argument matching is now part of the dispatch, making dispatch much more selective. This means that if the arguments of your post/get/etc. requests do not match up with the argument parameters provided in the controller method, the dispatch will point up to the higher level default() or lookup() functions and if it still does not find a suitable parent the controller will 404.

What this means to you: If you have "required" parameters in your argument list, those parameters must be passed into the request. For normal forms, you will not have to change your forms or any other code. For your tests, however, you may have to add additional parameters that you had previously left off.

2) The dispatch mechanism no longer assumes TGController.

What this means to you: So, if you have a Controller inside your RestController? that is not subclassing TGController, but expects TGController-like dispatch, you will have to make it subclass TGController Explicitly. Consider the following example:

class Inner:
   @expose()
   def index(self):
      "cannot get here without being explicit"

class MyRest(RestController):
   inner = Inner()

needs to become:

from tg import TGController

class Inner(TGController):
   @expose()
   def index(self):
      "cannot get here without being explicit"

class MyRest(RestController):
   inner = Inner()

You may however cascade controllers of the same type without subclassing, as the dispatch mechanism sticks with the parent dispatcher until it is forced to use the next _dispatch() in the tree.

New Functionality:

3) new/edit/put no longer require a *args, or kw parameter. Good riddens! The superfluous elements from the URL are now removed from the remainder/params before the controller method is called. Your existing controller methods that have these turds will still work, and should not require changing unless you desire clean and concise code.

4) RESTful sub-controller dispatch now supports variable argument length:

class Pizzarias:
    @expose()
    def get_all(self):
        return "tonsa pizzas here"

class Location(RestController):

    pizzarias = Pizzarias()
    
    def get_one(self, *args):
       pass

/location/23.443/334.233/pizzarias -> pizzarias.get_all() /location/Chicago/pizzarias -> pissarias.get_all()

Notice that the get_one() method of the parent class need not be exposed.

5) wsgiorg.routing_args is now populated.

This can be used in conjunction with 4) to provide a generic controller regardless of parent.

Deprecated:


class Location(RestController):

    def get_one(self, *args):
       pass

    class pizzarias:
        @expose()
        def get_all(self):
            return "tonsa pizzas here"

Declarative subcontrollers seemed like a good idea, but now less-so as we move on towards having the controller tree instantiated only one time.