<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def middleware_class(api=None):
 """Registers a middleware class"""

    def decorator(middleware_class):
        apply_to_api = hug.API(api) if api else hug.api.from_object(middleware_class)
        apply_to_api.http.add_middleware(middleware_class())
        return middleware_class
    return decorator