Hi everyone, I'm adding API functionality to an exiting app whose controller actions aren't close to being in shape for direct exposure. This pretty much precludes me from turning them into REST controllers and accomplishing this task that way.
So I've created a new api controller that will house the actions for
programmatic access. This has an unfortunate side effect of making my
routing kind of difficult.
For example, suppose I have model objects X and Y and the following API:
class ApiController(BaseController):
@jsonify
def getXbyid(self, id):
q = meta.session.query(model.X)
result = q.get(id)
return {"result": result.__json__()}
@jsonify
def getXbyacct(self, acct):
q = meta.session.query(model.X)
result = q.filter_by(acct=acct).one()
return {"result": result.__json__()}
@jsonify
def getYbyname(self, name):
q = meta.session.query(model.Y)
result = q.filter_by(name=name).one()
return {"result": result.__json__()}
How can I effectively map these actions without listing each action in
my routes? The best I have come up with is to include a route for
each parameter name I use:
map.connect("/api/{action}/{id:[0-9]+}", controller="api")
map.connect("/api/{action}/{acct:[0-9]+}", controller="api")
map.connect("/api/{action}/{name:[a-zA-Z0-9+}", controller="api")
--
Ross Vandegrift
[email protected]
"If the fight gets hot, the songs get hotter. If the going gets tough,
the songs get tougher."
--Woody Guthrie
signature.asc
Description: Digital signature
