faster_sam.middlewares package

Submodules

faster_sam.middlewares.lambda_authorizer module

faster_sam.middlewares.remove_path module

class faster_sam.middlewares.remove_path.RemovePathMiddleware(
app,
path,
)

Bases: BaseHTTPMiddleware

Removes a specified part of the request path.

e.g

This example apply the middleware to transform the request path from “/foo/bar” to “/bar” by removing a specified part (“/foo”).

>>> app = FastAPI()
>>> app.add_middleware(RemovePathMiddleware, path="/foo")
>>> @app.get("/bar")
... def bar():
...     return {"message": "Responding to GET /foo/bar}
Parameters:
  • app (ASGIApp) – Application instance the middleware is being registered to.

  • path (str) – The part of the path to be removed from incoming requests.

async dispatch(
request,
call_next,
)

Removes the specified part of the request path.

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

  • call_next (RequestResponseEndpoint) – Next middleware or endpoint on the execution stack

Returns:

The response generated by the middleware.

Return type:

Response

faster_sam.middlewares.rewrite_path module