Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import falcon
- import json
- REGISTER = {}
- class Handler:
- def on_get(self, req, resp, key):
- """Handles GET requests"""
- resp.status = falcon.HTTP_200
- resp.body = REGISTER.get(key, "") # json.dumps({"value": }, encoding='utf-8')
- def on_post(self, req, resp, key):
- try:
- value = req.stream.read()
- except Exception as ex:
- raise falcon.HTTPError(falcon.HTTP_400,
- 'Error',
- ex.message)
- REGISTER[key] = value
- resp.status = falcon.HTTP_201
- resp.body = json.dumps({"success": True}, encoding='utf-8')
- api = falcon.API()
- api.add_route('/{key}', Handler())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement