mirror of
https://github.com/kennethreitz/responder.git
synced 2026-06-05 06:46:14 +00:00
ff6d530338
## About A few cosmetic adjustments aka. code formatting. Also validate the outcome on CI/GHA. Feel free to improve now or later at your disposal. ## Details The updates are based on using the most recent versions of pyproject-fmt and ruff. Specifically, spots marked with `noqa` might need further love, also at your disposal. --------- Co-authored-by: Kenneth Reitz <me@kennethreitz.org>
25 lines
481 B
Python
25 lines
481 B
Python
# Example showing the lifespan context manager pattern.
|
|
# https://pypi.org/project/responder/
|
|
from contextlib import asynccontextmanager
|
|
|
|
import responder
|
|
|
|
|
|
@asynccontextmanager
|
|
async def lifespan(app):
|
|
# Startup: initialize resources
|
|
yield
|
|
# Shutdown: clean up resources
|
|
|
|
|
|
api = responder.API(lifespan=lifespan)
|
|
|
|
|
|
@api.route("/{greeting}")
|
|
async def greet_world(req, resp, *, greeting):
|
|
resp.text = f"{greeting}, world!"
|
|
|
|
|
|
if __name__ == "__main__":
|
|
api.run()
|