Skip to content

Instantly share code, notes, and snippets.

@jeffhollan
Created April 23, 2021 03:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeffhollan/7d0645b8e953bed75b55e1503bef24c6 to your computer and use it in GitHub Desktop.
Save jeffhollan/7d0645b8e953bed75b55e1503bef24c6 to your computer and use it in GitHub Desktop.
from dapr.clients import DaprClient
from azure.functions import func
# Function to get accessories
@app.route('/accessories', methods=['GET'])
def accessories_get():
with DaprClient() as d:
data = d.get_state(store_name='accessories')
return json.dumps(data)
# Function to create accessories
@app.route('accessories/<int:accessories_id>', methods=['PUT'])
def accessories_put_by_id(accessories_id: int):
with DaprClient() as d:
req_data = {
'id': accessories_id,
'message': 'new accessory'
}
func.context.log(f'Adding accessory to database: {accessories_id}')
d.invoke_binding('dataBinding', 'create', json.dumps(req_data))
return f'Accessories = int({accessories_id})'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment