View
class¶
Warning
The current page still doesn't have a translation for this language.
But you can help translating it: Contributing.
This is the reference for the View
that contains all the parameters,
attributes and functions.
The View
server as the base of alll object oriented views of Esmerald such as
APIView
, SimpleAPIView
and all the generics.
esmerald.routing.views.View
¶
View(parent)
View
class object acts as the base of all the object
oriented views used by Esmerald
.
The View
contains all the available parameters that
can be applied on a global level when subclassing it.
Example
from esmerald.routing.views import View
class CustomView(View):
...
PARAMETER | DESCRIPTION |
---|---|
parent
|
TYPE:
|
Source code in esmerald/routing/apis/base.py
251 252 253 254 255 256 257 258 259 260 261 |
|
path
instance-attribute
¶
path = clean_path(path or '/')
Relative path of the Gateway
.
The path can contain parameters in a dictionary like format.
dependencies
instance-attribute
¶
dependencies
A dictionary of string and Inject instances enable application level dependency injection.
exception_handlers
instance-attribute
¶
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 handler(request, exc) -> response
and may be be either standard functions, or async functions.
permissions
instance-attribute
¶
permissions
A list of permissions to serve the application incoming requests (HTTP and Websockets).
interceptors
instance-attribute
¶
interceptors
A list of interceptors to serve the application incoming requests (HTTP and Websockets).
middleware
instance-attribute
¶
middleware
A list of middleware to run for every request. The middlewares of an Include will be checked from top-down or Lilya Middleware as they are both converted internally. Read more about Python Protocols.
parent
instance-attribute
¶
parent = parent
Used internally by Esmerald to recognise and build the application levels.
Tip
Unless you know what are you doing, it is advisable not to touch this.
response_class
instance-attribute
¶
response_class
Default response class to be used within the Esmerald application.
Read more about the Responses and how to use them.
Example
from esmerald import APIView, JSONResponse
class MyView(APIView):
response_class = JSONResponse
response_cookies
instance-attribute
¶
response_cookies
A sequence of esmerald.datastructures.Cookie
objects.
Read more about the Cookies.
Example
from esmerald import APIView
from esmerald.datastructures import Cookie
response_cookies=[
Cookie(
key="csrf",
value="CIwNZNlR4XbisJF39I8yWnWX9wX4WFoz",
max_age=3000,
httponly=True,
)
]
class MyView(APIView):
response_cookies = response_cookies
response_headers
instance-attribute
¶
response_headers
A mapping of esmerald.datastructures.ResponseHeader
objects.
Read more about the ResponseHeader.
Example
from esmerald import APIView
from esmerald.datastructures import ResponseHeader
response_headers={
"authorize": ResponseHeader(value="granted")
}
class MyView(APIView):
response_headers = response_headers
tags
instance-attribute
¶
tags
A list of strings tags to be applied to the path operation.
It will be added to the generated OpenAPI documentation.
Note almost everything in Esmerald can be done in levels, which means these tags on a Esmerald instance, means it will be added to every route even if those routes also contain tags.
include_in_schema
instance-attribute
¶
include_in_schema
Boolean flag indicating if it should be added to the OpenAPI docs.
security
instance-attribute
¶
security
Used by OpenAPI definition, the security must be compliant with the norms. Esmerald offers some out of the box solutions where this is implemented.
The Esmerald security is available to automatically used.
The security can be applied also on a level basis.
For custom security objects, you must subclass
esmerald.openapi.security.base.HTTPBase
object.
deprecated
instance-attribute
¶
deprecated
Boolean flag for indicating the deprecation of the Include and all of its routes and to display it in the OpenAPI documentation..
get_route_middleware
¶
get_route_middleware(handler)
Gets the list of extended middlewares for the handler starting from the last to the first by reversing the list
PARAMETER | DESCRIPTION |
---|---|
handler
|
The handler being checked against.
TYPE:
|
Source code in esmerald/routing/apis/base.py
322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 |
|
get_exception_handlers
¶
get_exception_handlers(handler)
Gets the dict of extended exception handlers for the handler starting from the last to the first by reversing the list
PARAMETER | DESCRIPTION |
---|---|
handler
|
TYPE:
|
Source code in esmerald/routing/apis/base.py
340 341 342 343 344 345 346 347 348 |
|
get_routes
¶
get_routes(path=None, name=None, middleware=None, permissions=None, interceptors=None, exception_handlers=None, include_in_schema=None)
Builds the routes and wraps them in a list containing the Gateway and WebSocketGateway.
PARAMETER | DESCRIPTION |
---|---|
path
|
TYPE:
|
name
|
TYPE:
|
middleware
|
TYPE:
|
permissions
|
TYPE:
|
interceptors
|
TYPE:
|
exception_handlers
|
TYPE:
|
include_in_schema
|
TYPE:
|
Source code in esmerald/routing/apis/base.py
360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 |
|
esmerald.APIView
¶
APIView(parent)
Bases: View
The Esmerald APIView class.
The parameters available are the ones provided by the parent,
View
class.
Example
from esmerald.permissions import DenyAll, IsAuthenticated
from esmerald.requests import Request
from esmerald.responses import JSONResponse
from esmerald.routing.apis.views import APIView
from esmerald.routing.handlers import delete, get, post
class UserAPIView(APIView):
path = "/users"
permissions = [IsAuthenticated]
@get(path="/")
async def all_users(self, request: Request) -> JSONResponse:
# logic to get all users here
users = ...
return JSONResponse({"users": users})
@get(path="/deny", permissions=[DenyAll], description="API description")
async def all_usersa(self, request: Request) -> JSONResponse:
...
@get(path="/allow")
async def all_usersb(self, request: Request) -> JSONResponse:
users = ...
return JSONResponse({"Total Users": users.count()})
@post(path="/create")
async def create_user(self, request: Request) -> None:
# logic to create a user goes here
...
@delete(path="/delete/{user_id}")
async def delete_user(self, request: Request, user_id: str) -> None:
# logic to delete a user goes here
...
PARAMETER | DESCRIPTION |
---|---|
parent
|
TYPE:
|
Source code in esmerald/routing/apis/base.py
251 252 253 254 255 256 257 258 259 260 261 |
|
path
instance-attribute
¶
path = clean_path(path or '/')
Relative path of the Gateway
.
The path can contain parameters in a dictionary like format.
dependencies
instance-attribute
¶
dependencies
A dictionary of string and Inject instances enable application level dependency injection.
exception_handlers
instance-attribute
¶
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 handler(request, exc) -> response
and may be be either standard functions, or async functions.
permissions
instance-attribute
¶
permissions
A list of permissions to serve the application incoming requests (HTTP and Websockets).
interceptors
instance-attribute
¶
interceptors
A list of interceptors to serve the application incoming requests (HTTP and Websockets).
middleware
instance-attribute
¶
middleware
A list of middleware to run for every request. The middlewares of an Include will be checked from top-down or Lilya Middleware as they are both converted internally. Read more about Python Protocols.
parent
instance-attribute
¶
parent = parent
Used internally by Esmerald to recognise and build the application levels.
Tip
Unless you know what are you doing, it is advisable not to touch this.
response_class
instance-attribute
¶
response_class
Default response class to be used within the Esmerald application.
Read more about the Responses and how to use them.
Example
from esmerald import APIView, JSONResponse
class MyView(APIView):
response_class = JSONResponse
response_cookies
instance-attribute
¶
response_cookies
A sequence of esmerald.datastructures.Cookie
objects.
Read more about the Cookies.
Example
from esmerald import APIView
from esmerald.datastructures import Cookie
response_cookies=[
Cookie(
key="csrf",
value="CIwNZNlR4XbisJF39I8yWnWX9wX4WFoz",
max_age=3000,
httponly=True,
)
]
class MyView(APIView):
response_cookies = response_cookies
response_headers
instance-attribute
¶
response_headers
A mapping of esmerald.datastructures.ResponseHeader
objects.
Read more about the ResponseHeader.
Example
from esmerald import APIView
from esmerald.datastructures import ResponseHeader
response_headers={
"authorize": ResponseHeader(value="granted")
}
class MyView(APIView):
response_headers = response_headers
tags
instance-attribute
¶
tags
A list of strings tags to be applied to the path operation.
It will be added to the generated OpenAPI documentation.
Note almost everything in Esmerald can be done in levels, which means these tags on a Esmerald instance, means it will be added to every route even if those routes also contain tags.
include_in_schema
instance-attribute
¶
include_in_schema
Boolean flag indicating if it should be added to the OpenAPI docs.
security
instance-attribute
¶
security
Used by OpenAPI definition, the security must be compliant with the norms. Esmerald offers some out of the box solutions where this is implemented.
The Esmerald security is available to automatically used.
The security can be applied also on a level basis.
For custom security objects, you must subclass
esmerald.openapi.security.base.HTTPBase
object.
deprecated
instance-attribute
¶
deprecated
Boolean flag for indicating the deprecation of the Include and all of its routes and to display it in the OpenAPI documentation..
get_route_middleware
¶
get_route_middleware(handler)
Gets the list of extended middlewares for the handler starting from the last to the first by reversing the list
PARAMETER | DESCRIPTION |
---|---|
handler
|
The handler being checked against.
TYPE:
|
Source code in esmerald/routing/apis/base.py
322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 |
|
get_exception_handlers
¶
get_exception_handlers(handler)
Gets the dict of extended exception handlers for the handler starting from the last to the first by reversing the list
PARAMETER | DESCRIPTION |
---|---|
handler
|
TYPE:
|
Source code in esmerald/routing/apis/base.py
340 341 342 343 344 345 346 347 348 |
|
get_routes
¶
get_routes(path=None, name=None, middleware=None, permissions=None, interceptors=None, exception_handlers=None, include_in_schema=None)
Builds the routes and wraps them in a list containing the Gateway and WebSocketGateway.
PARAMETER | DESCRIPTION |
---|---|
path
|
TYPE:
|
name
|
TYPE:
|
middleware
|
TYPE:
|
permissions
|
TYPE:
|
interceptors
|
TYPE:
|
exception_handlers
|
TYPE:
|
include_in_schema
|
TYPE:
|
Source code in esmerald/routing/apis/base.py
360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 |
|
esmerald.SimpleAPIView
¶
SimpleAPIView(parent)
Bases: View
, MethodMixin
The Esmerald SimpleAPIView class.
This class has the same available parameters as the parent,
View
.
Example
from esmerald import SimpleAPIView, delete, get, patch, post, put
class UserAPI(SimpleAPIView):
@get()
async def get(self) -> str:
...
@post()
async def post(self) -> str:
...
@put()
async def put(self) -> str:
...
@patch()
async def patch(self) -> str:
...
@delete()
async def delete(self) -> None:
...
PARAMETER | DESCRIPTION |
---|---|
parent
|
TYPE:
|
Source code in esmerald/routing/apis/base.py
251 252 253 254 255 256 257 258 259 260 261 |
|
http_allowed_methods
class-attribute
instance-attribute
¶
http_allowed_methods = ['get', 'post', 'put', 'patch', 'delete', 'head', 'options', 'trace']
Allowed methods for the given base class.
path
instance-attribute
¶
path = clean_path(path or '/')
Relative path of the Gateway
.
The path can contain parameters in a dictionary like format.
dependencies
instance-attribute
¶
dependencies
A dictionary of string and Inject instances enable application level dependency injection.
exception_handlers
instance-attribute
¶
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 handler(request, exc) -> response
and may be be either standard functions, or async functions.
permissions
instance-attribute
¶
permissions
A list of permissions to serve the application incoming requests (HTTP and Websockets).
interceptors
instance-attribute
¶
interceptors
A list of interceptors to serve the application incoming requests (HTTP and Websockets).
middleware
instance-attribute
¶
middleware
A list of middleware to run for every request. The middlewares of an Include will be checked from top-down or Lilya Middleware as they are both converted internally. Read more about Python Protocols.
parent
instance-attribute
¶
parent = parent
Used internally by Esmerald to recognise and build the application levels.
Tip
Unless you know what are you doing, it is advisable not to touch this.
response_class
instance-attribute
¶
response_class
Default response class to be used within the Esmerald application.
Read more about the Responses and how to use them.
Example
from esmerald import APIView, JSONResponse
class MyView(APIView):
response_class = JSONResponse
response_cookies
instance-attribute
¶
response_cookies
A sequence of esmerald.datastructures.Cookie
objects.
Read more about the Cookies.
Example
from esmerald import APIView
from esmerald.datastructures import Cookie
response_cookies=[
Cookie(
key="csrf",
value="CIwNZNlR4XbisJF39I8yWnWX9wX4WFoz",
max_age=3000,
httponly=True,
)
]
class MyView(APIView):
response_cookies = response_cookies
response_headers
instance-attribute
¶
response_headers
A mapping of esmerald.datastructures.ResponseHeader
objects.
Read more about the ResponseHeader.
Example
from esmerald import APIView
from esmerald.datastructures import ResponseHeader
response_headers={
"authorize": ResponseHeader(value="granted")
}
class MyView(APIView):
response_headers = response_headers
tags
instance-attribute
¶
tags
A list of strings tags to be applied to the path operation.
It will be added to the generated OpenAPI documentation.
Note almost everything in Esmerald can be done in levels, which means these tags on a Esmerald instance, means it will be added to every route even if those routes also contain tags.
include_in_schema
instance-attribute
¶
include_in_schema
Boolean flag indicating if it should be added to the OpenAPI docs.
security
instance-attribute
¶
security
Used by OpenAPI definition, the security must be compliant with the norms. Esmerald offers some out of the box solutions where this is implemented.
The Esmerald security is available to automatically used.
The security can be applied also on a level basis.
For custom security objects, you must subclass
esmerald.openapi.security.base.HTTPBase
object.
deprecated
instance-attribute
¶
deprecated
Boolean flag for indicating the deprecation of the Include and all of its routes and to display it in the OpenAPI documentation..
is_method_allowed
classmethod
¶
is_method_allowed(name, base, method, error_message=None)
PARAMETER | DESCRIPTION |
---|---|
name
|
String referring to the http verb (method) being validated. Example:
TYPE:
|
base
|
The base class being checked against.
Internally, Esmerald checks against the bases of the class
upon the
TYPE:
|
method
|
Uusally referred to a handler being validated.
TYPE:
|
error_message
|
An error message to be displayed upon the error being thrown.
TYPE:
|
Source code in esmerald/routing/apis/_mixins.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
|
is_signature_valid
classmethod
¶
is_signature_valid(name, base, method, signature_type)
Validates if the signature of a given function is of type signature_type
.
PARAMETER | DESCRIPTION |
---|---|
name
|
The name of the function
TYPE:
|
base
|
The base class being checked against.
Internally, Esmerald checks against the bases of the class
upon the
TYPE:
|
method
|
Uusally referred to a handler being validated.
TYPE:
|
signature_type
|
The annotation being checked against.
TYPE:
|
Source code in esmerald/routing/apis/_mixins.py
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
|
get_route_middleware
¶
get_route_middleware(handler)
Gets the list of extended middlewares for the handler starting from the last to the first by reversing the list
PARAMETER | DESCRIPTION |
---|---|
handler
|
The handler being checked against.
TYPE:
|
Source code in esmerald/routing/apis/base.py
322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 |
|
get_exception_handlers
¶
get_exception_handlers(handler)
Gets the dict of extended exception handlers for the handler starting from the last to the first by reversing the list
PARAMETER | DESCRIPTION |
---|---|
handler
|
TYPE:
|
Source code in esmerald/routing/apis/base.py
340 341 342 343 344 345 346 347 348 |
|
get_routes
¶
get_routes(path=None, name=None, middleware=None, permissions=None, interceptors=None, exception_handlers=None, include_in_schema=None)
Builds the routes and wraps them in a list containing the Gateway and WebSocketGateway.
PARAMETER | DESCRIPTION |
---|---|
path
|
TYPE:
|
name
|
TYPE:
|
middleware
|
TYPE:
|
permissions
|
TYPE:
|
interceptors
|
TYPE:
|
exception_handlers
|
TYPE:
|
include_in_schema
|
TYPE:
|
Source code in esmerald/routing/apis/base.py
360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 |
|
esmerald.routing.apis.generics.CreateAPIView
¶
CreateAPIView(parent)
Bases: GenericMixin
, SimpleAPIView
This class has the same available parameters as the parent,
View
but subclassing the SimpleAPIView
.
from esmerald.routing.apis.generics import CreateAPIView
Example
from esmerald import patch, post, put
from esmerald.routing.apis.generics import CreateAPIView
class UserAPI(CreateAPIView):
'''
CreateAPIView only allows the `post`, `put` and `patch`
to be used by default.
'''
@post()
async def post(self) -> str:
...
@put()
async def put(self) -> str:
...
@patch()
async def patch(self) -> str:
...
PARAMETER | DESCRIPTION |
---|---|
parent
|
TYPE:
|
Source code in esmerald/routing/apis/base.py
251 252 253 254 255 256 257 258 259 260 261 |
|
path
instance-attribute
¶
path = clean_path(path or '/')
Relative path of the Gateway
.
The path can contain parameters in a dictionary like format.
dependencies
instance-attribute
¶
dependencies
A dictionary of string and Inject instances enable application level dependency injection.
exception_handlers
instance-attribute
¶
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 handler(request, exc) -> response
and may be be either standard functions, or async functions.
permissions
instance-attribute
¶
permissions
A list of permissions to serve the application incoming requests (HTTP and Websockets).
interceptors
instance-attribute
¶
interceptors
A list of interceptors to serve the application incoming requests (HTTP and Websockets).
middleware
instance-attribute
¶
middleware
A list of middleware to run for every request. The middlewares of an Include will be checked from top-down or Lilya Middleware as they are both converted internally. Read more about Python Protocols.
parent
instance-attribute
¶
parent = parent
Used internally by Esmerald to recognise and build the application levels.
Tip
Unless you know what are you doing, it is advisable not to touch this.
response_class
instance-attribute
¶
response_class
Default response class to be used within the Esmerald application.
Read more about the Responses and how to use them.
Example
from esmerald import APIView, JSONResponse
class MyView(APIView):
response_class = JSONResponse
response_cookies
instance-attribute
¶
response_cookies
A sequence of esmerald.datastructures.Cookie
objects.
Read more about the Cookies.
Example
from esmerald import APIView
from esmerald.datastructures import Cookie
response_cookies=[
Cookie(
key="csrf",
value="CIwNZNlR4XbisJF39I8yWnWX9wX4WFoz",
max_age=3000,
httponly=True,
)
]
class MyView(APIView):
response_cookies = response_cookies
response_headers
instance-attribute
¶
response_headers
A mapping of esmerald.datastructures.ResponseHeader
objects.
Read more about the ResponseHeader.
Example
from esmerald import APIView
from esmerald.datastructures import ResponseHeader
response_headers={
"authorize": ResponseHeader(value="granted")
}
class MyView(APIView):
response_headers = response_headers
tags
instance-attribute
¶
tags
A list of strings tags to be applied to the path operation.
It will be added to the generated OpenAPI documentation.
Note almost everything in Esmerald can be done in levels, which means these tags on a Esmerald instance, means it will be added to every route even if those routes also contain tags.
include_in_schema
instance-attribute
¶
include_in_schema
Boolean flag indicating if it should be added to the OpenAPI docs.
security
instance-attribute
¶
security
Used by OpenAPI definition, the security must be compliant with the norms. Esmerald offers some out of the box solutions where this is implemented.
The Esmerald security is available to automatically used.
The security can be applied also on a level basis.
For custom security objects, you must subclass
esmerald.openapi.security.base.HTTPBase
object.
deprecated
instance-attribute
¶
deprecated
Boolean flag for indicating the deprecation of the Include and all of its routes and to display it in the OpenAPI documentation..
http_allowed_methods
class-attribute
instance-attribute
¶
http_allowed_methods = ['post', 'put', 'patch']
Allowed methods for the given base class.
is_method_allowed
classmethod
¶
is_method_allowed(name, base, method, error_message=None)
PARAMETER | DESCRIPTION |
---|---|
name
|
String referring to the http verb (method) being validated. Example:
TYPE:
|
base
|
The base class being checked against.
Internally, Esmerald checks against the bases of the class
upon the
TYPE:
|
method
|
Uusally referred to a handler being validated.
TYPE:
|
error_message
|
An error message to be displayed upon the error being thrown.
TYPE:
|
Source code in esmerald/routing/apis/_mixins.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
|
is_signature_valid
classmethod
¶
is_signature_valid(name, base, method, signature_type)
Validates if the signature of a given function is of type signature_type
.
PARAMETER | DESCRIPTION |
---|---|
name
|
The name of the function
TYPE:
|
base
|
The base class being checked against.
Internally, Esmerald checks against the bases of the class
upon the
TYPE:
|
method
|
Uusally referred to a handler being validated.
TYPE:
|
signature_type
|
The annotation being checked against.
TYPE:
|
Source code in esmerald/routing/apis/_mixins.py
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
|
get_route_middleware
¶
get_route_middleware(handler)
Gets the list of extended middlewares for the handler starting from the last to the first by reversing the list
PARAMETER | DESCRIPTION |
---|---|
handler
|
The handler being checked against.
TYPE:
|
Source code in esmerald/routing/apis/base.py
322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 |
|
get_exception_handlers
¶
get_exception_handlers(handler)
Gets the dict of extended exception handlers for the handler starting from the last to the first by reversing the list
PARAMETER | DESCRIPTION |
---|---|
handler
|
TYPE:
|
Source code in esmerald/routing/apis/base.py
340 341 342 343 344 345 346 347 348 |
|
get_routes
¶
get_routes(path=None, name=None, middleware=None, permissions=None, interceptors=None, exception_handlers=None, include_in_schema=None)
Builds the routes and wraps them in a list containing the Gateway and WebSocketGateway.
PARAMETER | DESCRIPTION |
---|---|
path
|
TYPE:
|
name
|
TYPE:
|
middleware
|
TYPE:
|
permissions
|
TYPE:
|
interceptors
|
TYPE:
|
exception_handlers
|
TYPE:
|
include_in_schema
|
TYPE:
|
Source code in esmerald/routing/apis/base.py
360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 |
|
esmerald.routing.apis.generics.ReadAPIView
¶
ReadAPIView(parent)
Bases: GenericMixin
, SimpleAPIView
This class has the same available parameters as the parent,
View
but subclassing the SimpleAPIView
.
from esmerald.routing.apis.generics import ReadAPIView
Example
from esmerald import get
from esmerald.routing.apis.generics import ReadAPIView
class UserAPI(ReadAPIView):
'''
ReadAPIView only allows the `get` to be used by default..
'''
@get()
async def get(self) -> None:
...
PARAMETER | DESCRIPTION |
---|---|
parent
|
TYPE:
|
Source code in esmerald/routing/apis/base.py
251 252 253 254 255 256 257 258 259 260 261 |
|
path
instance-attribute
¶
path = clean_path(path or '/')
Relative path of the Gateway
.
The path can contain parameters in a dictionary like format.
dependencies
instance-attribute
¶
dependencies
A dictionary of string and Inject instances enable application level dependency injection.
exception_handlers
instance-attribute
¶
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 handler(request, exc) -> response
and may be be either standard functions, or async functions.
permissions
instance-attribute
¶
permissions
A list of permissions to serve the application incoming requests (HTTP and Websockets).
interceptors
instance-attribute
¶
interceptors
A list of interceptors to serve the application incoming requests (HTTP and Websockets).
middleware
instance-attribute
¶
middleware
A list of middleware to run for every request. The middlewares of an Include will be checked from top-down or Lilya Middleware as they are both converted internally. Read more about Python Protocols.
parent
instance-attribute
¶
parent = parent
Used internally by Esmerald to recognise and build the application levels.
Tip
Unless you know what are you doing, it is advisable not to touch this.
response_class
instance-attribute
¶
response_class
Default response class to be used within the Esmerald application.
Read more about the Responses and how to use them.
Example
from esmerald import APIView, JSONResponse
class MyView(APIView):
response_class = JSONResponse
response_cookies
instance-attribute
¶
response_cookies
A sequence of esmerald.datastructures.Cookie
objects.
Read more about the Cookies.
Example
from esmerald import APIView
from esmerald.datastructures import Cookie
response_cookies=[
Cookie(
key="csrf",
value="CIwNZNlR4XbisJF39I8yWnWX9wX4WFoz",
max_age=3000,
httponly=True,
)
]
class MyView(APIView):
response_cookies = response_cookies
response_headers
instance-attribute
¶
response_headers
A mapping of esmerald.datastructures.ResponseHeader
objects.
Read more about the ResponseHeader.
Example
from esmerald import APIView
from esmerald.datastructures import ResponseHeader
response_headers={
"authorize": ResponseHeader(value="granted")
}
class MyView(APIView):
response_headers = response_headers
tags
instance-attribute
¶
tags
A list of strings tags to be applied to the path operation.
It will be added to the generated OpenAPI documentation.
Note almost everything in Esmerald can be done in levels, which means these tags on a Esmerald instance, means it will be added to every route even if those routes also contain tags.
include_in_schema
instance-attribute
¶
include_in_schema
Boolean flag indicating if it should be added to the OpenAPI docs.
security
instance-attribute
¶
security
Used by OpenAPI definition, the security must be compliant with the norms. Esmerald offers some out of the box solutions where this is implemented.
The Esmerald security is available to automatically used.
The security can be applied also on a level basis.
For custom security objects, you must subclass
esmerald.openapi.security.base.HTTPBase
object.
deprecated
instance-attribute
¶
deprecated
Boolean flag for indicating the deprecation of the Include and all of its routes and to display it in the OpenAPI documentation..
http_allowed_methods
class-attribute
instance-attribute
¶
http_allowed_methods = ['get']
Allowed methods for the given base class.
is_method_allowed
classmethod
¶
is_method_allowed(name, base, method, error_message=None)
PARAMETER | DESCRIPTION |
---|---|
name
|
String referring to the http verb (method) being validated. Example:
TYPE:
|
base
|
The base class being checked against.
Internally, Esmerald checks against the bases of the class
upon the
TYPE:
|
method
|
Uusally referred to a handler being validated.
TYPE:
|
error_message
|
An error message to be displayed upon the error being thrown.
TYPE:
|
Source code in esmerald/routing/apis/_mixins.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
|
get_route_middleware
¶
get_route_middleware(handler)
Gets the list of extended middlewares for the handler starting from the last to the first by reversing the list
PARAMETER | DESCRIPTION |
---|---|
handler
|
The handler being checked against.
TYPE:
|
Source code in esmerald/routing/apis/base.py
322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 |
|
get_exception_handlers
¶
get_exception_handlers(handler)
Gets the dict of extended exception handlers for the handler starting from the last to the first by reversing the list
PARAMETER | DESCRIPTION |
---|---|
handler
|
TYPE:
|
Source code in esmerald/routing/apis/base.py
340 341 342 343 344 345 346 347 348 |
|
get_routes
¶
get_routes(path=None, name=None, middleware=None, permissions=None, interceptors=None, exception_handlers=None, include_in_schema=None)
Builds the routes and wraps them in a list containing the Gateway and WebSocketGateway.
PARAMETER | DESCRIPTION |
---|---|
path
|
TYPE:
|
name
|
TYPE:
|
middleware
|
TYPE:
|
permissions
|
TYPE:
|
interceptors
|
TYPE:
|
exception_handlers
|
TYPE:
|
include_in_schema
|
TYPE:
|
Source code in esmerald/routing/apis/base.py
360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 |
|
esmerald.routing.apis.generics.DeleteAPIView
¶
DeleteAPIView(parent)
Bases: GenericMixin
, SimpleAPIView
This class has the same available parameters as the parent,
View
but subclassing the SimpleAPIView
.
from esmerald.routing.apis.generics import CreateAPIView
Example
from esmerald import delete
from esmerald.routing.apis.generics import DeleteAPIView
class UserAPI(DeleteAPIView):
'''
DeleteAPIView only allows the `delete` to be used by default.
'''
@delete()
async def delete(self) -> None:
...
PARAMETER | DESCRIPTION |
---|---|
parent
|
TYPE:
|
Source code in esmerald/routing/apis/base.py
251 252 253 254 255 256 257 258 259 260 261 |
|
path
instance-attribute
¶
path = clean_path(path or '/')
Relative path of the Gateway
.
The path can contain parameters in a dictionary like format.
dependencies
instance-attribute
¶
dependencies
A dictionary of string and Inject instances enable application level dependency injection.
exception_handlers
instance-attribute
¶
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 handler(request, exc) -> response
and may be be either standard functions, or async functions.
permissions
instance-attribute
¶
permissions
A list of permissions to serve the application incoming requests (HTTP and Websockets).
interceptors
instance-attribute
¶
interceptors
A list of interceptors to serve the application incoming requests (HTTP and Websockets).
middleware
instance-attribute
¶
middleware
A list of middleware to run for every request. The middlewares of an Include will be checked from top-down or Lilya Middleware as they are both converted internally. Read more about Python Protocols.
parent
instance-attribute
¶
parent = parent
Used internally by Esmerald to recognise and build the application levels.
Tip
Unless you know what are you doing, it is advisable not to touch this.
response_class
instance-attribute
¶
response_class
Default response class to be used within the Esmerald application.
Read more about the Responses and how to use them.
Example
from esmerald import APIView, JSONResponse
class MyView(APIView):
response_class = JSONResponse
response_cookies
instance-attribute
¶
response_cookies
A sequence of esmerald.datastructures.Cookie
objects.
Read more about the Cookies.
Example
from esmerald import APIView
from esmerald.datastructures import Cookie
response_cookies=[
Cookie(
key="csrf",
value="CIwNZNlR4XbisJF39I8yWnWX9wX4WFoz",
max_age=3000,
httponly=True,
)
]
class MyView(APIView):
response_cookies = response_cookies
response_headers
instance-attribute
¶
response_headers
A mapping of esmerald.datastructures.ResponseHeader
objects.
Read more about the ResponseHeader.
Example
from esmerald import APIView
from esmerald.datastructures import ResponseHeader
response_headers={
"authorize": ResponseHeader(value="granted")
}
class MyView(APIView):
response_headers = response_headers
tags
instance-attribute
¶
tags
A list of strings tags to be applied to the path operation.
It will be added to the generated OpenAPI documentation.
Note almost everything in Esmerald can be done in levels, which means these tags on a Esmerald instance, means it will be added to every route even if those routes also contain tags.
include_in_schema
instance-attribute
¶
include_in_schema
Boolean flag indicating if it should be added to the OpenAPI docs.
security
instance-attribute
¶
security
Used by OpenAPI definition, the security must be compliant with the norms. Esmerald offers some out of the box solutions where this is implemented.
The Esmerald security is available to automatically used.
The security can be applied also on a level basis.
For custom security objects, you must subclass
esmerald.openapi.security.base.HTTPBase
object.
deprecated
instance-attribute
¶
deprecated
Boolean flag for indicating the deprecation of the Include and all of its routes and to display it in the OpenAPI documentation..
http_allowed_methods
class-attribute
instance-attribute
¶
http_allowed_methods = ['delete']
Allowed methods for the given base class.
is_method_allowed
classmethod
¶
is_method_allowed(name, base, method, error_message=None)
PARAMETER | DESCRIPTION |
---|---|
name
|
String referring to the http verb (method) being validated. Example:
TYPE:
|
base
|
The base class being checked against.
Internally, Esmerald checks against the bases of the class
upon the
TYPE:
|
method
|
Uusally referred to a handler being validated.
TYPE:
|
error_message
|
An error message to be displayed upon the error being thrown.
TYPE:
|
Source code in esmerald/routing/apis/_mixins.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
|
get_route_middleware
¶
get_route_middleware(handler)
Gets the list of extended middlewares for the handler starting from the last to the first by reversing the list
PARAMETER | DESCRIPTION |
---|---|
handler
|
The handler being checked against.
TYPE:
|
Source code in esmerald/routing/apis/base.py
322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 |
|
get_exception_handlers
¶
get_exception_handlers(handler)
Gets the dict of extended exception handlers for the handler starting from the last to the first by reversing the list
PARAMETER | DESCRIPTION |
---|---|
handler
|
TYPE:
|
Source code in esmerald/routing/apis/base.py
340 341 342 343 344 345 346 347 348 |
|
get_routes
¶
get_routes(path=None, name=None, middleware=None, permissions=None, interceptors=None, exception_handlers=None, include_in_schema=None)
Builds the routes and wraps them in a list containing the Gateway and WebSocketGateway.
PARAMETER | DESCRIPTION |
---|---|
path
|
TYPE:
|
name
|
TYPE:
|
middleware
|
TYPE:
|
permissions
|
TYPE:
|
interceptors
|
TYPE:
|
exception_handlers
|
TYPE:
|
include_in_schema
|
TYPE:
|
Source code in esmerald/routing/apis/base.py
360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 |
|
esmerald.routing.apis.generics.ListAPIView
¶
ListAPIView(parent)
Bases: GenericMixin
, ListView
Only allows the return to be lists.
PARAMETER | DESCRIPTION |
---|---|
parent
|
TYPE:
|
Source code in esmerald/routing/apis/base.py
251 252 253 254 255 256 257 258 259 260 261 |
|
http_allowed_methods
class-attribute
instance-attribute
¶
http_allowed_methods = ['get', 'post', 'put', 'patch', 'delete', 'head', 'options', 'trace']
Allowed methods for the given base class.
path
instance-attribute
¶
path = clean_path(path or '/')
Relative path of the Gateway
.
The path can contain parameters in a dictionary like format.
dependencies
instance-attribute
¶
dependencies
A dictionary of string and Inject instances enable application level dependency injection.
exception_handlers
instance-attribute
¶
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 handler(request, exc) -> response
and may be be either standard functions, or async functions.
permissions
instance-attribute
¶
permissions
A list of permissions to serve the application incoming requests (HTTP and Websockets).
interceptors
instance-attribute
¶
interceptors
A list of interceptors to serve the application incoming requests (HTTP and Websockets).
middleware
instance-attribute
¶
middleware
A list of middleware to run for every request. The middlewares of an Include will be checked from top-down or Lilya Middleware as they are both converted internally. Read more about Python Protocols.
parent
instance-attribute
¶
parent = parent
Used internally by Esmerald to recognise and build the application levels.
Tip
Unless you know what are you doing, it is advisable not to touch this.
response_class
instance-attribute
¶
response_class
Default response class to be used within the Esmerald application.
Read more about the Responses and how to use them.
Example
from esmerald import APIView, JSONResponse
class MyView(APIView):
response_class = JSONResponse
response_cookies
instance-attribute
¶
response_cookies
A sequence of esmerald.datastructures.Cookie
objects.
Read more about the Cookies.
Example
from esmerald import APIView
from esmerald.datastructures import Cookie
response_cookies=[
Cookie(
key="csrf",
value="CIwNZNlR4XbisJF39I8yWnWX9wX4WFoz",
max_age=3000,
httponly=True,
)
]
class MyView(APIView):
response_cookies = response_cookies
response_headers
instance-attribute
¶
response_headers
A mapping of esmerald.datastructures.ResponseHeader
objects.
Read more about the ResponseHeader.
Example
from esmerald import APIView
from esmerald.datastructures import ResponseHeader
response_headers={
"authorize": ResponseHeader(value="granted")
}
class MyView(APIView):
response_headers = response_headers
tags
instance-attribute
¶
tags
A list of strings tags to be applied to the path operation.
It will be added to the generated OpenAPI documentation.
Note almost everything in Esmerald can be done in levels, which means these tags on a Esmerald instance, means it will be added to every route even if those routes also contain tags.
include_in_schema
instance-attribute
¶
include_in_schema
Boolean flag indicating if it should be added to the OpenAPI docs.
security
instance-attribute
¶
security
Used by OpenAPI definition, the security must be compliant with the norms. Esmerald offers some out of the box solutions where this is implemented.
The Esmerald security is available to automatically used.
The security can be applied also on a level basis.
For custom security objects, you must subclass
esmerald.openapi.security.base.HTTPBase
object.
deprecated
instance-attribute
¶
deprecated
Boolean flag for indicating the deprecation of the Include and all of its routes and to display it in the OpenAPI documentation..
is_method_allowed
classmethod
¶
is_method_allowed(name, base, method, error_message=None)
PARAMETER | DESCRIPTION |
---|---|
name
|
String referring to the http verb (method) being validated. Example:
TYPE:
|
base
|
The base class being checked against.
Internally, Esmerald checks against the bases of the class
upon the
TYPE:
|
method
|
Uusally referred to a handler being validated.
TYPE:
|
error_message
|
An error message to be displayed upon the error being thrown.
TYPE:
|
Source code in esmerald/routing/apis/_mixins.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
|
get_route_middleware
¶
get_route_middleware(handler)
Gets the list of extended middlewares for the handler starting from the last to the first by reversing the list
PARAMETER | DESCRIPTION |
---|---|
handler
|
The handler being checked against.
TYPE:
|
Source code in esmerald/routing/apis/base.py
322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 |
|
get_exception_handlers
¶
get_exception_handlers(handler)
Gets the dict of extended exception handlers for the handler starting from the last to the first by reversing the list
PARAMETER | DESCRIPTION |
---|---|
handler
|
TYPE:
|
Source code in esmerald/routing/apis/base.py
340 341 342 343 344 345 346 347 348 |
|
get_routes
¶
get_routes(path=None, name=None, middleware=None, permissions=None, interceptors=None, exception_handlers=None, include_in_schema=None)
Builds the routes and wraps them in a list containing the Gateway and WebSocketGateway.
PARAMETER | DESCRIPTION |
---|---|
path
|
TYPE:
|
name
|
TYPE:
|
middleware
|
TYPE:
|
permissions
|
TYPE:
|
interceptors
|
TYPE:
|
exception_handlers
|
TYPE:
|
include_in_schema
|
TYPE:
|
Source code in esmerald/routing/apis/base.py
360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 |
|