1.7 KiB
1.7 KiB
Integrating with a Framework
WSGI Application
wsme.wsgi -- WSGI adapter
wsme.wsgi
adapt
Returns a wsgi application that serve a wsme.controller.WSRoot.
Example
from wsme import *
import wsme.wsgi
from wsme.protocols import restjson
class MyRoot(WSRoot):
@expose(unicode)
def helloworld(self):
return u"Hello World !"
application = wsme.wsgi.adapt(
MyRoot(protocols=['REST+Json']))Turbogears 1.x
wsme.tg1 -- TG1 adapter
wsme.tg1
A TG1 Controller that publish a wsme.WSRoot.
adapt
Returns a Controller that publish a wsme.WSRoot.
Example
In a freshly quickstarted tg1 application (let's say, wsmedemo), the prefered way is the following :
Create a new file, "wsmedemo/ws.py" :
import wsme.tg1
from wsme import expose, validate, WSRoot
class WSController(WSRoot):
@expose(int)
@validate(int, int)
def multiply(self, a, b):
return a * bInsert the ws controller in the controller tree, (file controllers.py):
# ...
from wsmedemo.ws import WSController
# make sure the wanted protocols are known
import wsme.protocols.restjson
import wsme.tg1
class Root(controllers.RootController):
ws = wsme.tg1.adapt(
WSController(webpath='/ws', protocols=['REST+Json']))
# ...