github.com/hazelops/ize@v1.1.12-0.20230915191306-97d7c0e48f11/examples/sls-apps-monorepo/apps/pecan/handler.py (about) 1 import json 2 import requests 3 4 def endpoint(event, context): 5 # get `usd_amount` parameter from event in serverless 6 amount = json.loads(event["queryStringParameters"]["usd_amount"], parse_float=float) 7 # get rates of currencies to usd from website 8 get_rates = requests.get('http://www.floatrates.com/daily/usd.json') 9 # deserialize JSON data to Python variable 10 rdata = json.loads(get_rates.text) 11 # form the body of the message with data we have from previous iterations 12 body = { 13 "USD": amount, 14 "EUR": rdata['eur']['rate']*amount, 15 "CHF": rdata['chf']['rate']*amount, 16 "JPY": rdata['jpy']['rate']*amount, 17 } 18 19 response = { 20 "statusCode": 200, 21 "body": json.dumps(body) 22 } 23 24 return response