Last active
October 2, 2017 06:59
-
-
Save sirleech/5055971 to your computer and use it in GitHub Desktop.
web.py example with a few URLs and a JSON web service. Installed as mod_wsgi on apache, see conf at https://gist.github.com/sirleech/5055976
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import web | |
import json | |
urls = ( | |
'/', 'index', | |
'/random', 'random', | |
'/dump', 'dump' | |
) | |
class index: | |
def GET(self): | |
return "Hello, web.py!" | |
class random: | |
def GET(self): | |
web.header('Content-Type', 'application/json') | |
return "{\"random\":\"444\"}" | |
class dump: | |
def GET(self): | |
web.header('Content-Type', 'application/json') | |
web.header('Access-Control-Allow-Origin', '*') | |
import datetime | |
now = datetime.datetime.now() | |
import random | |
rand = 556 | |
rand = random.randint(0,500) | |
data = [ { 'dateTime':str(now), 'random':rand} ] | |
data_string = json.dumps(data) | |
return data_string | |
if __name__ == "__main__": | |
app = web.application(urls, globals()) | |
app.run() | |
app = web.application(urls, globals(), autoreload=False) | |
application = app.wsgifunc() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment