Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docs: Provide examples of how to create middleware #3930

Open
marcuslimdw opened this issue Jan 7, 2025 · 0 comments
Open

Docs: Provide examples of how to create middleware #3930

marcuslimdw opened this issue Jan 7, 2025 · 0 comments
Labels
Documentation 📚 This is related to documentation

Comments

@marcuslimdw
Copy link
Contributor

marcuslimdw commented Jan 7, 2025

Summary

For those used to thinking of a server as a function, which Starlette's BaseHTTPMiddleware does (caveat: it has its own problems), ASGI middleware can be quite confusing for two reasons:

  1. The mapping of ASGI concepts to HTTP request/response cycle concepts, at a level that the average dev will be aware of, is not clear (what are send and receive, and how do they relate to requests and responses?)
  2. Many operations are made much easier by not inspecting the raw scope dict, but rather performing framework-provided transformations (e.g. litestar.datastructures.Headers.from_scope or litestar.datastructures.URL.from_scope) on scope. These transformations are not inherently discoverable.

My suggestion: add multiple examples to the creating Middleware page, like Starlette already does.

@marcuslimdw marcuslimdw added the Documentation 📚 This is related to documentation label Jan 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Documentation 📚 This is related to documentation
Projects
None yet
Development

No branches or pull requests

1 participant