Last active
February 9, 2019 22:26
-
-
Save neeraj9/93dfd35b0a2145309b303b5f2b045330 to your computer and use it in GitHub Desktop.
BeamParticle Python 3 Dynamic function for /post/ HTTP POST JSON handler
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
#!python | |
# Sample Python 3 function to return what was passed in as the first argument. | |
# Notice that this template works for the /post/<thisfun> interface, where | |
# json input is passed in the first argument postBody, while the response | |
# is a binary or a string, which must be json as well. | |
from Pyrlang import term | |
import json | |
def main(data_binary, context_binary): | |
data = data_binary.decode('utf-8') | |
context = context_binary.decode('utf-8') | |
result = handle_event(data, context) | |
return term.Binary(result.encode('utf-8')) | |
def handle_event(data, context): | |
try: | |
json_value = json.loads(data) | |
return json.dumps(json_value) | |
except Exception as e: | |
return str(e) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment