From 4bd6a562d349161834b4e62de819c871fa18bc56 Mon Sep 17 00:00:00 2001 From: Joel Collins Date: Wed, 9 Jan 2019 16:33:36 +0000 Subject: [PATCH] Better example of JsonPayload use --- openflexure_microscope/plugins/example/api.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/openflexure_microscope/plugins/example/api.py b/openflexure_microscope/plugins/example/api.py index aa071b94..f73377be 100644 --- a/openflexure_microscope/plugins/example/api.py +++ b/openflexure_microscope/plugins/example/api.py @@ -40,11 +40,11 @@ class HelloWorldAPI(MicroscopeViewPlugin): Method to call when an HTTP POST request is made. Assumes request will include a JSON payload. """ - # Get payload JSON as a dictionary + # Get payload JSON payload = JsonPayload(request) - # Extract a value from the JSON key 'plugin_string'. If no value is given, default to None - new_plugin_string = payload.param('plugin_string') + # Extract a value from the JSON key 'plugin_string', and convert to a string. If no value is given, default to empty. + new_plugin_string = payload.param('plugin_string', default='', convert=str) if new_plugin_string: # If not None or empty # Set microscope attribute to the specified string