How to create simple python webservice

Create file

#!/usr/bin/env python

Created on Apr 10, 2013

@author: kowalczy
import web

urls = (
‘/hello/(.*)’, ‘hello’,
‘/.*’ , ‘index’
usage=”Example usage : \n”+”http://server:port/hello/name \n”

class index:
def GET(self):
return “\n”+ usage

class hello:
def GET(self, name):
if name==”:
return “Hello unknown”
return “Hello ” + name

if __name__ == “__main__”:
app = web.application(urls, globals())

start service :
python 2345
run request:

The response should be
Hello Jacek

How to send GET and POST request with wget

GET request

wget -S –header=”Accept-Encoding: gzip, deflate” -O response.txt http://server:8080/application/params

POST request

wget -S –header=”Accept-Encoding: gzip, deflate” –header=’Accept-Charset: UTF-8′ –header=’Content-Type: application/json’ -O response.json –post-data ‘{“param1″:”myspecialValue1″,”param2″:”my special value 2”}’ http://server:8080/application2/params2