Skip to content

Instantly share code, notes, and snippets.

@neeraj9
Last active February 9, 2019 22:26
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save neeraj9/93dfd35b0a2145309b303b5f2b045330 to your computer and use it in GitHub Desktop.
Save neeraj9/93dfd35b0a2145309b303b5f2b045330 to your computer and use it in GitHub Desktop.
BeamParticle Python 3 Dynamic function for /post/ HTTP POST JSON handler
#!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