# Werkzeug

Introduction

The following tutorial describes how to set up a bare bones Werkzeug project with a gateway exposing a method. Since Werkzeug supports generic WSGI apps, setting up a remoting gateway is trivial using the WSGI gateway.

## Example

Create a new Werkzeug project by creating a file called `server.py`:

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    #!/usr/bin/env python
    # -*- coding: utf-8 -*-

    from werkzeug import run_simple

    from pyamf.remoting.gateway.wsgi import WSGIGateway

    import logging

    logging.basicConfig(
        level=logging.DEBUG,
        format='%(asctime)s %(levelname)-5.5s [%(name)s] %(message)s'
    )

    def echo(data):
        return data

    services = {'echo': echo}
    gw = WSGIGateway(services, logger=logging, debug=True)

    run_simple('localhost', 8000, gw, use_reloader=True)

Fire up the web server with:

    python server.py

That should print something like:

    * Running on http://localhost:8000/
    * Restarting with reloader...

To test the gateway you can use a Python AMF client like this:

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    from pyamf.remoting.client import RemotingService

    import logging

    logging.basicConfig(
        level=logging.DEBUG,
        format='%(asctime)s %(levelname)-5.5s [%(name)s] %(message)s'
    )

    url = 'http://localhost:8080'
    client = RemotingService(url, logger=logging, debug=True)
    service = client.getService('echo')
    echo = service('Hello World!')

    logging.debug(echo)