ramka.middleware package#

Submodules#

ramka.middleware.base_middleware module#

class ramka.middleware.base_middleware.Middleware(app: App)#

Bases: object

Base middleware class.

Middleware is a class that can be used to modify the request and response objects. The idea is that middleware wraps the application and it can be wrapped with another middleware. This way, the application can be easily extended. For example, a middleware can be used to log the requests, and another middleware can be used to add some header to the response.

Subclass this class and override the process_request and process_response methods to implement custom middleware. Each middleware can override one of those methods or both.

add(middleware_cls: Type[Middleware])#

Add another middleware to the execution chain.

Parameters:

middleware_cls (Type[Middleware]) – The middleware class to add.

handle_request(request: Request) Response#

Handle the request.

This method is called by the application. It calls the process_request method before the request is handled, and then the process_response method after the request is handled.

Parameters:

request (Request) – The request to handle.

process_request(request: Request) None#

Process the request.

This method is called by the application before the request is handled. It can be overridden to add custom logic to the request.

Parameters:

request (Request) – The request to process.

process_response(request: Request, response: Response) None#

Process the response.

This method is called by the application after the request is handled. It can be overridden to add custom logic to the response. It takes the request as one of the arguments but modifying it won’t have any effect as the request is already handled.

Parameters:
  • request (Request) – The request object.

  • response (Response) – The response to process.

Module contents#

class ramka.middleware.Middleware(app: App)#

Bases: object

Base middleware class.

Middleware is a class that can be used to modify the request and response objects. The idea is that middleware wraps the application and it can be wrapped with another middleware. This way, the application can be easily extended. For example, a middleware can be used to log the requests, and another middleware can be used to add some header to the response.

Subclass this class and override the process_request and process_response methods to implement custom middleware. Each middleware can override one of those methods or both.

add(middleware_cls: Type[Middleware])#

Add another middleware to the execution chain.

Parameters:

middleware_cls (Type[Middleware]) – The middleware class to add.

handle_request(request: Request) Response#

Handle the request.

This method is called by the application. It calls the process_request method before the request is handled, and then the process_response method after the request is handled.

Parameters:

request (Request) – The request to handle.

process_request(request: Request) None#

Process the request.

This method is called by the application before the request is handled. It can be overridden to add custom logic to the request.

Parameters:

request (Request) – The request to process.

process_response(request: Request, response: Response) None#

Process the response.

This method is called by the application after the request is handled. It can be overridden to add custom logic to the response. It takes the request as one of the arguments but modifying it won’t have any effect as the request is already handled.

Parameters:
  • request (Request) – The request object.

  • response (Response) – The response to process.