Commit be084f6f authored by Joel Collins's avatar Joel Collins
Browse files

Added API plugin demo

parent 4cbfe16c
Loading
Loading
Loading
Loading
+26 −1
Original line number Diff line number Diff line
from openflexure_microscope.api.utilities import parse_payload
from openflexure_microscope.api.v1.views import MicroscopeView

ENDPOINTS = {}
from flask import request, Response

import logging


class PluginTestAPI(MicroscopeView):

    def get(self):
        data = self.microscope.plugin.test1.run()  # Call a method from our plugin
        return Response(data)

    def post(self):
        # Get payload
        state = parse_payload(request)
        logging.debug(state)

        # Handle absolute positioning
        if 'data' in state:  # If value is given in payload JSON
            data = str(state['data'])  # Process and store that value

        return Response(data)

ENDPOINTS = {
    'test1': PluginTestAPI
}