from typing import Callable

import tornado.web


class APIHandler(tornado.web.RequestHandler):
    def initialize(self, json_source: Callable[[], dict]):
        """Simple JSON API handler that returns JSON generated by the given callable"""
        self.json_source = json_source

    async def get(self):
        """GET /_monitor/[endpoint].json"""
        self.write(self.json_source())
