bareasgi
class Application ¶
Summary¶
Construct the application
Description¶
from bareasgi import (
Application,
Scope,
Info,
RouteMatches,
Content,
WebSocket,
text_reader,
text_writer
)
async def http_request_callback(
scope: Scope,
info: Info,
matches: RouteMatches,
content: Content
) -> HttpResponse:
text = await text_reader(content)
return 200, [(b'content-type', b'text/plain')], text_writer('This is not a test'), None
import uvicorn
app = Application()
app.http_router.add({'GET', 'POST', 'PUT', 'DELETE'}, '/{path}', http_request_callback)
uvicorn.run(app, port=9009)
bareasgi.Application(
*,
middlewares: Optional[List[HttpMiddlewareCallback]],
http_router: Optional[HttpRouter],
web_socket_router: Optional[WebSocketRouter],
startup_handlers: Optional[List[LifespanHandler]],
shutdown_handlers: Optional[List[LifespanHandler]],
not_found_response: Optional[HttpResponse],
info: Optional[MutableMapping[str, Any]]
) -> NoneParameters¶
middlewares: Optional[List[HttpMiddlewareCallback]] (optional)Optional middleware callbacks. Defaults to None.
http_router: Optional[HttpRouter] (optional)Optional router to for http routes. Defaults to None.
web_socket_router: Optional[WebSocketRouter] (optional)Optional router for web routes. Defaults to None.
startup_handlers: Optional[List[LifespanHandler]] (optional)Optional handlers to run at startup. Defaults to None.
shutdown_handlers: Optional[List[LifespanHandler]] (optional)Optional handlers to run at shutdown. Defaults to None.
not_found_response: Optional[HttpResponse] (optional)Optional not found (404) response. Defaults to None.
info: Optional[MutableMapping[str, Any]] (optional)Optional dictionary for user data. Defaults to None.
property Application.info ¶
Summary¶
A place to sto application specific data.
info -> MutableMapping[str, Any]
property Application.middlewares ¶
Summary¶
The middlewares.
middlewares -> List[HttpMiddlewareCallback]
property Application.shutdown_handlers ¶
Summary¶
Handlers run on shutdown
shutdown_handlers -> List[LifespanHandler]
method Application.on_http_request ¶
Summary¶
A decorator to add an http route handler to the application
Application.on_http_request(
methods: AbstractSet[str],
path: str
) -> Callable[[HttpRequestCallback], HttpRequestCallback]method Application.on_shutdown ¶
Summary¶
A decorator to add a startup handler to the application
Application.on_shutdown(
callback: LifespanHandler
) -> LifespanHandlermethod Application.on_startup ¶
Summary¶
A decorator to add a startup handler to the application
Application.on_startup(
callback: LifespanHandler
) -> LifespanHandler