Created
August 9, 2016 14:05
-
-
Save yheihei/1fda1da9ebe8b1d46965344b1523340c to your computer and use it in GitHub Desktop.
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
# -*- coding: utf-8 -*- | |
import falcon | |
import json | |
import traceback | |
class ItemsResource: | |
items = { | |
"Components": { | |
"GW": 0.1, | |
"ECU1": 0.5 | |
} | |
} | |
def on_get(self, req, resp): | |
''' Handles GET requests ''' | |
resp.body = json.dumps(self.items) | |
def on_put(self, req, resp): | |
print 'put' | |
body = req.stream.read() | |
data = json.loads(body) | |
print data | |
try : | |
self.items['Components']['GW'] = data['Components']['GW'] | |
self.items['Components']['ECU1'] = data['Components']['ECU1'] | |
except: | |
traceback.print_exc() | |
api = falcon.API() | |
api.add_route('/vehicle/12345678', ItemsResource()) | |
from wsgiref import simple_server | |
httpd = simple_server.make_server('127.0.0.1', 8000, api) | |
httpd.serve_forever() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment