v3.8.0
Highlights
Handlers can return values — quick endpoints get a lot terser:
@api.route("/users")
def list_users(req, resp):
return [{"name": "alice"}] # same as resp.media = [...]A dict/list sets resp.media, a str sets resp.text, bytes set resp.content. Returning None keeps the classic mutate-resp behavior, so existing handlers are unaffected.
Proper HTTP method semantics. Method-restricted routes now return 405 Method Not Allowed with an Allow header for unsupported methods (previously 404), answer OPTIONS automatically, and accept HEAD wherever GET is supported.
App-scoped dependencies. Building on 3.7.0's dependency injection:
@api.dependency(scope="app")
async def pool():
pool = await create_pool()
yield pool
await pool.close() # runs at application shutdownThe provider resolves once on first use and is cached for the application's lifetime.
Also
set_cookie()gains asamesiteparameter, defaulting to"lax"- The validated
request_modelinstance is available asreq.state.validated— no double parsing RouteGroup.before_requesthooks are now scoped to the group's prefix (previously they silently applied to every route)- View signature inspection for dependency injection is cached per function
Breaking-ish
- Wrong-method requests now get 405 instead of 404 (the correct status code)
- Group-level before-request hooks no longer fire outside their prefix
Full changelog: https://github.com/kennethreitz/responder/blob/main/CHANGELOG.md