0

I'm trying to create a simple REST Web Service using technology WSME reported here:

https://pypi.python.org/pypi/WSME

It's not clear, however, how to proceed. I have successfully installed the package WSME.0.6.4 but I don't understand how to proceed. On the above link we can see some python code. If I wanted to test the code what should I do? I have to create a .py file? Where this file should be saved? Are there services to be started? The documentation is not clear: it says "With this published at the / ws path of your application". What application? Do I need to install a Web Server?

Thanks.

Luca F.
  • 113
  • 1
  • 10
  • A REST API works on HTTP requests. WSME is a library to expose webservices, not necessarily just REST, on top of an existing web application. It expects that you have a web application, which runs on top of some kind of application server. – Kjir May 15 '15 at 13:16

1 Answers1

1

You could use a full blown web server to run your application . For example Apache with mod_wsgi or uWSGI , but it is not always necessary .

Also you should choose a web framework to work with .
According WSME doc's it has support for Flask microframework out of the box , which is simple enough to start with .

To get started create a file with the following source code :

from wsgiref.simple_server import make_server
from wsme import WSRoot, expose

class MyService(WSRoot):
    @expose(unicode, unicode)
    def hello(self, who=u'World'):
        return u"Hello {0} !".format(who)

ws = MyService(protocols=['restjson', 'restxml'])
application = ws.wsgiapp()
httpd = make_server('localhost', 8000, application)
httpd.serve_forever()

Run this file and point your web browser to http://127.0.0.1:8000/hello.xml?who=John
you should get <result>Hello John !</result> in response.

In this example we have used python's built in webserver which is a good choice when you need to test something out quickly .

For addition i suggest reading How python web frameworks and WSGI fit together

Community
  • 1
  • 1
Alexander
  • 12,424
  • 5
  • 59
  • 76