2

If I have a spyne application that inherits from spyne.Application and am serving that through a spyne.WsgiApplication object, how would I add custom HTTP endpoints to the WSGI server such as / or /info?

The basic structure mirrors the one found on spyne.io

class HelloWorldService(ServiceBase):
    @srpc(Unicode, Integer, _returns=Iterable(Unicode))
    def say_hello(name, times):
        for i in range(times):
            yield 'Hello, %s' % name

application = Application([HelloWorldService], # <--- spyne.Application
    tns='spyne.examples.hello',
    in_protocol=Soap11(validator='lxml'),
    out_protocol=JsonDocument()
)

if __name__ == '__main__':
    from wsgiref.simple_server import make_server

    wsgi_app = WsgiApplication(application)    # <--- spyne.WsgiApplication
    server = make_server('0.0.0.0', 8000, wsgi_app)
    server.serve_forever()
blakev
  • 4,154
  • 2
  • 32
  • 52
  • 1
    possible duplicate of: http://stackoverflow.com/questions/20275836/deploy-multiple-web-services-i-e-multiple-wsdl-files-in-python ? or do you need to do something else? – Burak Arslan Aug 13 '15 at 22:47

1 Answers1

2

In spyne importing from spyne.util.wsgi_wrapper import WsgiMounter (Source) will allow you to call the WsgiMounter function with a single dictionary parameter. The keys of the dictionary represent an extension of the root endpoint, and the values are the WSGI-compatible application.

For example:

def create_web_app(config):
    app = Flask(__name__)

    @app.route('/about')
    def about():
        return 'About Page'

    return app

wsgi_app = WsgiMounter({
    '': SpyneAppWsgi(app),
    'www': create_web_app(config)
})

..will configure one server, where the spyne application will be served from the root, and everything from the create_web_app app will be served from /www. (To get to the /about page, you would route to http://localhost:8080/www/about)

In this example create_web_app returns a Flask application.

blakev
  • 4,154
  • 2
  • 32
  • 52