WebSocketGateway
class¶
This is the reference for the WebSocketGateway
that contains all the parameters,
attributes and functions.
How to import¶
from esmerald import WebSocketGateway
esmerald.WebSocketGateway
¶
WebSocketGateway(path=None, *, handler, name=None, parent=None, dependencies=None, middleware=None, interceptors=None, permissions=None, exception_handlers=None, is_from_router=False)
Bases: WebSocketPath
, Dispatcher
, BaseMiddleware
WebSocketGateway
object class used by Esmerald routes.
The WebSocketGateway act as a brigde between the router handlers and the main Esmerald routing system.
Read more about WebSocketGateway and how to use it.
Example
from esmerald import Esmerald. websocket
@websocket()
async def world_socket(socket: Websocket) -> None:
await socket.accept()
msg = await socket.receive_json()
assert msg
assert socket
await socket.close()
WebSocketGateway(path="/ws", handler=home)
PARAMETER | DESCRIPTION |
---|---|
path |
Relative path of the Example
Example with parameters
TYPE:
|
handler |
An instance of handler.
TYPE:
|
name |
The name for the Gateway. The name can be reversed by
TYPE:
|
parent |
Who owns the Gateway. If not specified, the application automatically it assign it. This is directly related with the application levels.
TYPE:
|
dependencies |
A dictionary of string and Inject instances enable application level dependency injection.
TYPE:
|
middleware |
A list of middleware to run for every request. The middlewares of a Gateway will be checked from top-down or Lilya Middleware as they are both converted internally. Read more about Python Protocols.
TYPE:
|
interceptors |
A list of interceptors to serve the application incoming requests (HTTP and Websockets).
TYPE:
|
permissions |
A list of permissions to serve the application incoming requests (HTTP and Websockets).
TYPE:
|
exception_handlers |
A dictionary of exception types (or custom exceptions) and the handler functions on an application top level. Exception handler callables should be of the form of
TYPE:
|
is_from_router |
Used by the
TYPE:
|
Source code in esmerald/routing/gateways.py
393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 |
|
exception_handlers
instance-attribute
¶
exception_handlers = {} if exception_handlers is None else dict(exception_handlers)