Abstract Base Classes

Abstract routing

aiohttp has abstract classes for managing web interfaces.

The most part of aiohttp.web is not intended to be inherited but few of them are.

aiohttp.web is built on top of few concepts: application, router, request and response.

router is a pluggable part: a library user may build a router from scratch, all other parts should work with new router seamlessly.

AbstractRouter has the only mandatory method: AbstractRouter.resolve() coroutine. It must return an AbstractMatchInfo instance.

If the requested URL handler is found AbstractMatchInfo.handler() is a web-handler for requested URL and AbstractMatchInfo.http_exception is None.

Otherwise AbstractMatchInfo.http_exception is an instance of HTTPException like 404: NotFound or 405: Method Not Allowed. AbstractMatchInfo.handler() raises http_exception on call.

class aiohttp.abc.AbstractRouter

Abstract router, aiohttp.web.Application accepts it as router parameter and returns as aiohttp.web.Application.router.

coroutine resolve(request)

Performs URL resolving. It’s an abstract method, should be overridden in router implementation.

Parameters:requestaiohttp.web.Request instance for resolving, the request has aiohttp.web.Request.match_info equals to None at resolving stage.
Returns:AbstractMatchInfo instance.
class aiohttp.abc.AbstractMatchInfo

Abstract match info, returned by AbstractRouter.resolve() call.

http_exception

aiohttp.web.HTTPException if no match was found, None otherwise.

coroutine handler(request)

Abstract method performing web-handler processing.

Parameters:requestaiohttp.web.Request instance for resolving, the request has aiohttp.web.Request.match_info equals to None at resolving stage.
Returns:aiohttp.web.StreamResponse or descendants.
Raise:aiohttp.web.HTTPException on error
coroutine expect_handler(request)

Abstract method for handling 100-continue processing.

Abstract Class Based Views

For class based view support aiohttp has abstract AbstractView class which is awaitable (may be uses like await Cls() or yield from Cls() and has a request as an attribute.

class aiohttp.AbstractView

An abstract class, base for all class based views implementations.

Methods __iter__ and __await__ should be overridden.

request

aiohttp.web.Request instance for performing the request.

Abstract Abstract Access Logger

class aiohttp.abc.AbstractAccessLogger

An abstract class, base for all RequestHandler access_logger implementations

Method log should be overridden.

log(request, response, time)
Parameters: