Response
class¶
esmerald.Response ¶
Response(content, *, status_code=status.HTTP_200_OK, media_type=MediaType.JSON, background=None, headers=None, cookies=None)
Bases: Response
, Generic[T]
Default Response
object from Esmerald where it can be as the
return annotation of a handler.
Esmerakd automatically will understand what time of response is going to be used and parse all the details automatically.
Example
from pydantic import BaseModel
from esmerald import Esmerald, Gateway, Response, get
from esmerald.datastructures import Cookie
@get(path="/me")
async def home() -> Response:
return Response(
Item(id=1, sku="sku1238"),
headers={"SKY-HEADER": "sku-xyz"},
cookies=[Cookie(key="sku", value="a-value")],
)
Esmerald(routes=[Gateway(handler=home)])
PARAMETER | DESCRIPTION |
---|---|
content |
Any content being sent to the response.
TYPE:
|
status_code |
The response status code.
TYPE:
|
media_type |
The media type used in the response.
TYPE:
|
background |
Any instance of a BackgroundTask or BackgroundTasks.
TYPE:
|
headers |
Any additional headers being passed to the response.
TYPE:
|
cookies |
A sequence of Read more about the Cookies. Example
TYPE:
|
Source code in esmerald/responses/base.py
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 98 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 |
|
init_headers ¶
init_headers(headers=None)
PARAMETER | DESCRIPTION |
---|---|
headers |
TYPE:
|
Source code in .venv/lib/python3.8/site-packages/starlette/responses.py
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 |
|
set_cookie ¶
set_cookie(key, value='', max_age=None, expires=None, path='/', domain=None, secure=False, httponly=False, samesite='lax')
PARAMETER | DESCRIPTION |
---|---|
key |
TYPE:
|
value |
TYPE:
|
max_age |
TYPE:
|
expires |
TYPE:
|
path |
TYPE:
|
domain |
TYPE:
|
secure |
TYPE:
|
httponly |
TYPE:
|
samesite |
TYPE:
|
Source code in .venv/lib/python3.8/site-packages/starlette/responses.py
86 87 88 89 90 91 92 93 94 95 96 97 98 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 |
|
delete_cookie ¶
delete_cookie(key, path='/', domain=None, secure=False, httponly=False, samesite='lax')
PARAMETER | DESCRIPTION |
---|---|
key |
TYPE:
|
path |
TYPE:
|
domain |
TYPE:
|
secure |
TYPE:
|
httponly |
TYPE:
|
samesite |
TYPE:
|
Source code in .venv/lib/python3.8/site-packages/starlette/responses.py
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
|
transform
staticmethod
¶
transform(value)
The transformation of the data being returned.
It supports Pydantic models, dataclasses
and msgspec.Struct
.
PARAMETER | DESCRIPTION |
---|---|
value |
TYPE:
|
Source code in esmerald/responses/base.py
139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
|
render ¶
render(content)
PARAMETER | DESCRIPTION |
---|---|
content |
TYPE:
|
Source code in esmerald/responses/base.py
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
|