def handle_request()

in src/lambdas/modular_api_handler/handler.py [0:0]


    def handle_request(self, event: ProcessedEvent, context: RequestContext):
        path, method = event['path'], event['method']
        match_result = self.mapper.match(
            path, {REQUEST_METHOD_WSGI_ENV: method}
        )
        if not match_result:
            raise ResponseFactory(HTTPStatus.NOT_FOUND).message(
                f'{method} {path} not found'
            ).exc()
        controller = match_result.pop('controller')
        action = match_result.pop('action')
        to_pop = ('_summary', '_description', '_responses', '_require_auth', 
                  '_permission')
        for k in to_pop:
            match_result.pop(k, None)
        # it's expected that the mapper is configured properly because
        # if it is, there could be no KeyError
        handler = self._controllers[controller].get_action_handler(action)
        match method:
            case HTTPMethod.GET:
                body = event['query']
            case _:
                body = event['body']
        params = dict(event=body, **match_result)
        sign = inspect.signature(handler)
        if '_pe' in sign.parameters:
            # if you need to access raw event data inside event
            _LOG.debug('Expanding handler payload with raw event')
            params['_pe'] = event
        return handler(**params)