The easiest deployment of HTTP server ever

$ cd /public_content_dir

$ python -m SimpleHTTPServer
Serving HTTP on 0.0.0.0 port 8000 …
localhost – – [27/Jun/2013 12:48:15] “GET / HTTP/1.1” 200 –
localhost – – [27/Jun/2013 12:48:19] “GET /bin/ HTTP/1.1” 200 –

check the URL http://ip-address:8000  in your browser

🙂

Thanks to my friend Krzysztof Ratecki for this cool trick !!!

 

Advertisements

How to create simple python webservice

Create file helloworld.py

#!/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”
else:
return “Hello ” + name

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

start service :
python helloworld.py 2345
run request:
http://hostname:2345/hello/Jacek

The response should be
Hello Jacek