Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.69 KB | None | 0 0
  1. import falcon
  2. import json
  3.  
  4. REGISTER = {}
  5.  
  6. class Handler:
  7.     def on_get(self, req, resp, key):
  8.         """Handles GET requests"""
  9.         resp.status = falcon.HTTP_200
  10.         resp.body = REGISTER.get(key, "") # json.dumps({"value": }, encoding='utf-8')
  11.    
  12.     def on_post(self, req, resp, key):
  13.         try:
  14.             value = req.stream.read()
  15.         except Exception as ex:
  16.             raise falcon.HTTPError(falcon.HTTP_400,
  17.                 'Error',
  18.                 ex.message)
  19.  
  20.         REGISTER[key] = value
  21.  
  22.         resp.status = falcon.HTTP_201
  23.         resp.body = json.dumps({"success": True}, encoding='utf-8')
  24.  
  25. api = falcon.API()
  26. api.add_route('/{key}', Handler())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement