def request_middleware(api=None):
 def decorator(middleware_method):
  apply_to_api = (hug.API(api) if api else hug.api.from_object(middleware_method))
  class MiddlewareRouter(object, ):
   __slots__ = ()
   def process_request(self, request, response):
    return middleware_method(request, response)
  apply_to_api.http.add_middleware(MiddlewareRouter())
  return middleware_method
 return decorator

def request_middleware ( api = None ) : def decorator ( middleware_method ) : apply_to_api = ( hug . API ( api ) if api else hug . api . from_object ( middleware_method ) ) class MiddlewareRouter ( object , ) : __slots__ = ( ) def process_request ( self , request , response ) : return middleware_method ( request , response ) apply_to_api . http . add_middleware ( MiddlewareRouter ( ) ) return middleware_method return decorator
registers a middleware function that will be called on every request .