Skip to content

Instantly share code, notes, and snippets.

@yheihei
Created August 9, 2016 14:05
Show Gist options
  • Save yheihei/1fda1da9ebe8b1d46965344b1523340c to your computer and use it in GitHub Desktop.
Save yheihei/1fda1da9ebe8b1d46965344b1523340c to your computer and use it in GitHub Desktop.
# -*- 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