Browse Source

๐ŸŒ ๐Ÿ”  ๐Ÿ“„ ๐Ÿข Translate docs to Emoji ๐Ÿฅณ ๐ŸŽ‰ ๐Ÿ’ฅ ๐Ÿคฏ ๐Ÿคฏ (#5385)

* ๐ŸŒ ๐Ÿ’ฌ  ๐Ÿฉบ  ๐Ÿฆฒ

* ๐ŸŽจ [pre-commit.ci] Auto format from pre-commit.com hooks

* ๐Ÿ› ๏ธ๐Ÿ˜Š

* โ™ป๏ธ Rename emoji lang from emj to em, and main docs name as ๐Ÿ˜‰

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Axd1x8a <[email protected]>
Co-authored-by: Sebastiรกn Ramรญrez <[email protected]>
pull/9342/head
LeeeeT 2 years ago
committed by GitHub
parent
commit
d4e85da18b
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      docs/az/mkdocs.yml
  2. 3
      docs/de/mkdocs.yml
  3. 240
      docs/em/docs/advanced/additional-responses.md
  4. 37
      docs/em/docs/advanced/additional-status-codes.md
  5. 70
      docs/em/docs/advanced/advanced-dependencies.md
  6. 162
      docs/em/docs/advanced/async-sql-databases.md
  7. 92
      docs/em/docs/advanced/async-tests.md
  8. 346
      docs/em/docs/advanced/behind-a-proxy.md
  9. 58
      docs/em/docs/advanced/conditional-openapi.md
  10. 109
      docs/em/docs/advanced/custom-request-and-route.md
  11. 300
      docs/em/docs/advanced/custom-response.md
  12. 98
      docs/em/docs/advanced/dataclasses.md
  13. 160
      docs/em/docs/advanced/events.md
  14. 314
      docs/em/docs/advanced/extending-openapi.md
  15. 267
      docs/em/docs/advanced/generate-clients.md
  16. 56
      docs/em/docs/advanced/graphql.md
  17. 24
      docs/em/docs/advanced/index.md
  18. 99
      docs/em/docs/advanced/middleware.md
  19. 156
      docs/em/docs/advanced/nosql-databases.md
  20. 179
      docs/em/docs/advanced/openapi-callbacks.md
  21. 170
      docs/em/docs/advanced/path-operation-advanced-configuration.md
  22. 33
      docs/em/docs/advanced/response-change-status-code.md
  23. 49
      docs/em/docs/advanced/response-cookies.md
  24. 63
      docs/em/docs/advanced/response-directly.md
  25. 42
      docs/em/docs/advanced/response-headers.md
  26. 113
      docs/em/docs/advanced/security/http-basic-auth.md
  27. 16
      docs/em/docs/advanced/security/index.md
  28. 269
      docs/em/docs/advanced/security/oauth2-scopes.md
  29. 382
      docs/em/docs/advanced/settings.md
  30. 529
      docs/em/docs/advanced/sql-databases-peewee.md
  31. 73
      docs/em/docs/advanced/sub-applications.md
  32. 77
      docs/em/docs/advanced/templates.md
  33. 95
      docs/em/docs/advanced/testing-database.md
  34. 49
      docs/em/docs/advanced/testing-dependencies.md
  35. 7
      docs/em/docs/advanced/testing-events.md
  36. 12
      docs/em/docs/advanced/testing-websockets.md
  37. 52
      docs/em/docs/advanced/using-request-directly.md
  38. 184
      docs/em/docs/advanced/websockets.md
  39. 37
      docs/em/docs/advanced/wsgi.md
  40. 414
      docs/em/docs/alternatives.md
  41. 430
      docs/em/docs/async.md
  42. 34
      docs/em/docs/benchmarks.md
  43. 465
      docs/em/docs/contributing.md
  44. 311
      docs/em/docs/deployment/concepts.md
  45. 258
      docs/em/docs/deployment/deta.md
  46. 698
      docs/em/docs/deployment/docker.md
  47. 190
      docs/em/docs/deployment/https.md
  48. 21
      docs/em/docs/deployment/index.md
  49. 145
      docs/em/docs/deployment/manually.md
  50. 178
      docs/em/docs/deployment/server-workers.md
  51. 87
      docs/em/docs/deployment/versions.md
  52. 91
      docs/em/docs/external-links.md
  53. 178
      docs/em/docs/fastapi-people.md
  54. 200
      docs/em/docs/features.md
  55. 265
      docs/em/docs/help-fastapi.md
  56. 79
      docs/em/docs/history-design-future.md
  57. 469
      docs/em/docs/index.md
  58. 84
      docs/em/docs/project-generation.md
  59. 490
      docs/em/docs/python-types.md
  60. 102
      docs/em/docs/tutorial/background-tasks.md
  61. 488
      docs/em/docs/tutorial/bigger-applications.md
  62. 68
      docs/em/docs/tutorial/body-fields.md
  63. 213
      docs/em/docs/tutorial/body-multiple-params.md
  64. 382
      docs/em/docs/tutorial/body-nested-models.md
  65. 155
      docs/em/docs/tutorial/body-updates.md
  66. 213
      docs/em/docs/tutorial/body.md
  67. 49
      docs/em/docs/tutorial/cookie-params.md
  68. 84
      docs/em/docs/tutorial/cors.md
  69. 112
      docs/em/docs/tutorial/debugging.md
  70. 247
      docs/em/docs/tutorial/dependencies/classes-as-dependencies.md
  71. 71
      docs/em/docs/tutorial/dependencies/dependencies-in-path-operation-decorators.md
  72. 219
      docs/em/docs/tutorial/dependencies/dependencies-with-yield.md
  73. 17
      docs/em/docs/tutorial/dependencies/global-dependencies.md
  74. 233
      docs/em/docs/tutorial/dependencies/index.md
  75. 110
      docs/em/docs/tutorial/dependencies/sub-dependencies.md
  76. 42
      docs/em/docs/tutorial/encoder.md
  77. 82
      docs/em/docs/tutorial/extra-data-types.md
  78. 252
      docs/em/docs/tutorial/extra-models.md
  79. 333
      docs/em/docs/tutorial/first-steps.md
  80. 261
      docs/em/docs/tutorial/handling-errors.md
  81. 128
      docs/em/docs/tutorial/header-params.md
  82. 80
      docs/em/docs/tutorial/index.md
  83. 112
      docs/em/docs/tutorial/metadata.md
  84. 61
      docs/em/docs/tutorial/middleware.md
  85. 179
      docs/em/docs/tutorial/path-operation-configuration.md
  86. 138
      docs/em/docs/tutorial/path-params-numeric-validations.md
  87. 252
      docs/em/docs/tutorial/path-params.md
  88. 467
      docs/em/docs/tutorial/query-params-str-validations.md
  89. 225
      docs/em/docs/tutorial/query-params.md
  90. 186
      docs/em/docs/tutorial/request-files.md
  91. 35
      docs/em/docs/tutorial/request-forms-and-files.md
  92. 58
      docs/em/docs/tutorial/request-forms.md
  93. 481
      docs/em/docs/tutorial/response-model.md
  94. 89
      docs/em/docs/tutorial/response-status-code.md
  95. 141
      docs/em/docs/tutorial/schema-extra-example.md
  96. 182
      docs/em/docs/tutorial/security/first-steps.md
  97. 151
      docs/em/docs/tutorial/security/get-current-user.md
  98. 101
      docs/em/docs/tutorial/security/index.md
  99. 297
      docs/em/docs/tutorial/security/oauth2-jwt.md
  100. 315
      docs/em/docs/tutorial/security/simple-oauth2.md

3
docs/az/mkdocs.yml

@ -41,6 +41,7 @@ nav:
- en: / - en: /
- az: /az/ - az: /az/
- de: /de/ - de: /de/
- em: /em/
- es: /es/ - es: /es/
- fa: /fa/ - fa: /fa/
- fr: /fr/ - fr: /fr/
@ -105,6 +106,8 @@ extra:
name: az name: az
- link: /de/ - link: /de/
name: de name: de
- link: /em/
name: ๐Ÿ˜‰
- link: /es/ - link: /es/
name: es - espaรฑol name: es - espaรฑol
- link: /fa/ - link: /fa/

3
docs/de/mkdocs.yml

@ -41,6 +41,7 @@ nav:
- en: / - en: /
- az: /az/ - az: /az/
- de: /de/ - de: /de/
- em: /em/
- es: /es/ - es: /es/
- fa: /fa/ - fa: /fa/
- fr: /fr/ - fr: /fr/
@ -106,6 +107,8 @@ extra:
name: az name: az
- link: /de/ - link: /de/
name: de name: de
- link: /em/
name: ๐Ÿ˜‰
- link: /es/ - link: /es/
name: es - espaรฑol name: es - espaรฑol
- link: /fa/ - link: /fa/

240
docs/em/docs/advanced/additional-responses.md

@ -0,0 +1,240 @@
# ๐ŸŒ– ๐Ÿ“จ ๐Ÿ—„
!!! warning
๐Ÿ‘‰ ๐Ÿ‘ ๐Ÿง โ”.
๐Ÿšฅ ๐Ÿ‘† โ–ถ๏ธ โฎ๏ธ **FastAPI**, ๐Ÿ‘† ๐Ÿ’ช ๐Ÿšซ ๐Ÿ’ช ๐Ÿ‘‰.
๐Ÿ‘† ๐Ÿ’ช ๐Ÿ“ฃ ๐ŸŒ– ๐Ÿ“จ, โฎ๏ธ ๐ŸŒ– ๐Ÿ‘” ๐Ÿ“Ÿ, ๐Ÿ”‰ ๐Ÿ†Ž, ๐Ÿ“›, โ™’๏ธ.
๐Ÿ‘ˆ ๐ŸŒ– ๐Ÿ“จ ๐Ÿ”œ ๐Ÿ”Œ ๐Ÿ—„ ๐Ÿ”—, ๐Ÿ‘ซ ๐Ÿ”œ ๐Ÿ˜‘ ๐Ÿ› ๏ธ ๐Ÿฉบ.
โœ‹๏ธ ๐Ÿ‘ˆ ๐ŸŒ– ๐Ÿ“จ ๐Ÿ‘† โœ”๏ธ โš’ ๐Ÿ’ญ ๐Ÿ‘† ๐Ÿ“จ `Response` ๐Ÿ’– `JSONResponse` ๐Ÿ”—, โฎ๏ธ ๐Ÿ‘† ๐Ÿ‘” ๐Ÿ“Ÿ &amp; ๐ŸŽš.
## ๐ŸŒ– ๐Ÿ“จ โฎ๏ธ `model`
๐Ÿ‘† ๐Ÿ’ช ๐Ÿšถโ€โ™€๏ธ ๐Ÿ‘† *โžก ๐Ÿ› ๏ธ ๐Ÿ‘จโ€๐ŸŽจ* ๐Ÿ”ข `responses`.
โšซ๏ธ ๐Ÿ“จ `dict`, ๐Ÿ”‘ ๐Ÿ‘” ๐Ÿ“Ÿ ๐Ÿ”  ๐Ÿ“จ, ๐Ÿ’– `200`, &amp; ๐Ÿ’ฒ ๐ŸŽ `dict`โ“‚ โฎ๏ธ โ„น ๐Ÿ”  ๐Ÿ‘ซ.
๐Ÿ”  ๐Ÿ‘ˆ ๐Ÿ“จ `dict`โ“‚ ๐Ÿ’ช โœ”๏ธ ๐Ÿ”‘ `model`, โš— Pydantic ๐Ÿท, ๐Ÿ’– `response_model`.
**FastAPI** ๐Ÿ”œ โœŠ ๐Ÿ‘ˆ ๐Ÿท, ๐Ÿ— ๐Ÿšฎ ๐ŸŽป ๐Ÿ”— &amp; ๐Ÿ”Œ โšซ๏ธ โ˜‘ ๐Ÿฅ‰ ๐Ÿ—„.
๐Ÿ–ผ, ๐Ÿ“ฃ โž•1๏ธโƒฃ ๐Ÿ“จ โฎ๏ธ ๐Ÿ‘” ๐Ÿ“Ÿ `404` &amp; Pydantic ๐Ÿท `Message`, ๐Ÿ‘† ๐Ÿ’ช โœ:
```Python hl_lines="18 22"
{!../../../docs_src/additional_responses/tutorial001.py!}
```
!!! note
โœ”๏ธ ๐Ÿคฏ ๐Ÿ‘ˆ ๐Ÿ‘† โœ”๏ธ ๐Ÿ“จ `JSONResponse` ๐Ÿ”—.
!!! info
`model` ๐Ÿ”‘ ๐Ÿšซ ๐Ÿ• ๐Ÿ—„.
**FastAPI** ๐Ÿ”œ โœŠ Pydantic ๐Ÿท โšช๏ธโžก๏ธ ๐Ÿ“ค, ๐Ÿ— `JSON Schema`, &amp; ๐Ÿšฎ โšซ๏ธ โ˜‘ ๐Ÿฅ‰.
โ˜‘ ๐Ÿฅ‰:
* ๐Ÿ”‘ `content`, ๐Ÿ‘ˆ โœ”๏ธ ๐Ÿ’ฒ โž•1๏ธโƒฃ ๐ŸŽป ๐ŸŽš (`dict`) ๐Ÿ‘ˆ ๐Ÿ”Œ:
* ๐Ÿ”‘ โฎ๏ธ ๐Ÿ“ป ๐Ÿ†Ž, โœ… `application/json`, ๐Ÿ‘ˆ ๐Ÿ”Œ ๐Ÿ’ฒ โž•1๏ธโƒฃ ๐ŸŽป ๐ŸŽš, ๐Ÿ‘ˆ ๐Ÿ”Œ:
* ๐Ÿ”‘ `schema`, ๐Ÿ‘ˆ โœ”๏ธ ๐Ÿ’ฒ ๐ŸŽป ๐Ÿ”— โšช๏ธโžก๏ธ ๐Ÿท, ๐Ÿ“ฅ โ˜‘ ๐Ÿฅ‰.
* **FastAPI** ๐Ÿšฎ ๐Ÿ”— ๐Ÿ“ฅ ๐ŸŒ ๐ŸŽป ๐Ÿ”— โž•1๏ธโƒฃ ๐Ÿฅ‰ ๐Ÿ‘† ๐Ÿ—„ โ†ฉ๏ธ โœ… โšซ๏ธ ๐Ÿ”—. ๐Ÿ‘‰ ๐ŸŒŒ, ๐ŸŽ ๐Ÿˆธ &amp; ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ’ช โš™๏ธ ๐Ÿ‘ˆ ๐ŸŽป ๐Ÿ”— ๐Ÿ”—, ๐Ÿšš ๐Ÿ‘ป ๐Ÿ“Ÿ โšก ๐Ÿงฐ, โ™’๏ธ.
๐Ÿ— ๐Ÿ“จ ๐Ÿ—„ ๐Ÿ‘‰ *โžก ๐Ÿ› ๏ธ* ๐Ÿ”œ:
```JSON hl_lines="3-12"
{
"responses": {
"404": {
"description": "Additional Response",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Message"
}
}
}
},
"200": {
"description": "Successful Response",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Item"
}
}
}
},
"422": {
"description": "Validation Error",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/HTTPValidationError"
}
}
}
}
}
}
```
๐Ÿ”— ๐Ÿ”— โž•1๏ธโƒฃ ๐Ÿฅ‰ ๐Ÿ”˜ ๐Ÿ—„ ๐Ÿ”—:
```JSON hl_lines="4-16"
{
"components": {
"schemas": {
"Message": {
"title": "Message",
"required": [
"message"
],
"type": "object",
"properties": {
"message": {
"title": "Message",
"type": "string"
}
}
},
"Item": {
"title": "Item",
"required": [
"id",
"value"
],
"type": "object",
"properties": {
"id": {
"title": "Id",
"type": "string"
},
"value": {
"title": "Value",
"type": "string"
}
}
},
"ValidationError": {
"title": "ValidationError",
"required": [
"loc",
"msg",
"type"
],
"type": "object",
"properties": {
"loc": {
"title": "Location",
"type": "array",
"items": {
"type": "string"
}
},
"msg": {
"title": "Message",
"type": "string"
},
"type": {
"title": "Error Type",
"type": "string"
}
}
},
"HTTPValidationError": {
"title": "HTTPValidationError",
"type": "object",
"properties": {
"detail": {
"title": "Detail",
"type": "array",
"items": {
"$ref": "#/components/schemas/ValidationError"
}
}
}
}
}
}
}
```
## ๐ŸŒ– ๐Ÿ”‰ ๐Ÿ†Ž ๐Ÿ‘‘ ๐Ÿ“จ
๐Ÿ‘† ๐Ÿ’ช โš™๏ธ ๐Ÿ‘‰ ๐ŸŽ `responses` ๐Ÿ”ข ๐Ÿšฎ ๐ŸŽ ๐Ÿ”‰ ๐Ÿ†Ž ๐ŸŽ ๐Ÿ‘‘ ๐Ÿ“จ.
๐Ÿ–ผ, ๐Ÿ‘† ๐Ÿ’ช ๐Ÿšฎ ๐ŸŒ– ๐Ÿ“ป ๐Ÿ†Ž `image/png`, ๐Ÿ“ฃ ๐Ÿ‘ˆ ๐Ÿ‘† *โžก ๐Ÿ› ๏ธ* ๐Ÿ’ช ๐Ÿ“จ ๐ŸŽป ๐ŸŽš (โฎ๏ธ ๐Ÿ“ป ๐Ÿ†Ž `application/json`) โš–๏ธ ๐Ÿ‡ฉ๐Ÿ‡ด ๐Ÿ–ผ:
```Python hl_lines="19-24 28"
{!../../../docs_src/additional_responses/tutorial002.py!}
```
!!! note
๐Ÿ‘€ ๐Ÿ‘ˆ ๐Ÿ‘† โœ”๏ธ ๐Ÿ“จ ๐Ÿ–ผ โš™๏ธ `FileResponse` ๐Ÿ”—.
!!! info
๐Ÿšฅ ๐Ÿ‘† โœ” ๐ŸŽ ๐Ÿ“ป ๐Ÿ†Ž ๐ŸŽฏ ๐Ÿ‘† `responses` ๐Ÿ”ข, FastAPI ๐Ÿ”œ ๐Ÿค” ๐Ÿ“จ โœ”๏ธ ๐ŸŽ ๐Ÿ“ป ๐Ÿ†Ž ๐Ÿ‘‘ ๐Ÿ“จ ๐ŸŽ“ (๐Ÿ”ข `application/json`).
โœ‹๏ธ ๐Ÿšฅ ๐Ÿ‘† โœ”๏ธ โœ” ๐Ÿ›ƒ ๐Ÿ“จ ๐ŸŽ“ โฎ๏ธ `None` ๐Ÿšฎ ๐Ÿ“ป ๐Ÿ†Ž, FastAPI ๐Ÿ”œ โš™๏ธ `application/json` ๐Ÿ™† ๐ŸŒ– ๐Ÿ“จ ๐Ÿ‘ˆ โœ”๏ธ ๐Ÿ‘จโ€๐Ÿ’ผ ๐Ÿท.
## ๐ŸŒ€ โ„น
๐Ÿ‘† ๐Ÿ’ช ๐ŸŒ€ ๐Ÿ“จ โ„น โšช๏ธโžก๏ธ ๐Ÿ’— ๐Ÿฅ‰, ๐Ÿ”Œ `response_model`, `status_code`, &amp; `responses` ๐Ÿ”ข.
๐Ÿ‘† ๐Ÿ’ช ๐Ÿ“ฃ `response_model`, โš™๏ธ ๐Ÿ”ข ๐Ÿ‘” ๐Ÿ“Ÿ `200` (โš–๏ธ ๐Ÿ›ƒ 1๏ธโƒฃ ๐Ÿšฅ ๐Ÿ‘† ๐Ÿ’ช), &amp; โคด๏ธ ๐Ÿ“ฃ ๐ŸŒ– โ„น ๐Ÿ‘ˆ ๐ŸŽ ๐Ÿ“จ `responses`, ๐Ÿ”— ๐Ÿ—„ ๐Ÿ”—.
**FastAPI** ๐Ÿ”œ ๐Ÿšง ๐ŸŒ– โ„น โšช๏ธโžก๏ธ `responses`, &amp; ๐ŸŒ€ โšซ๏ธ โฎ๏ธ ๐ŸŽป ๐Ÿ”— โšช๏ธโžก๏ธ ๐Ÿ‘† ๐Ÿท.
๐Ÿ–ผ, ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ“ฃ ๐Ÿ“จ โฎ๏ธ ๐Ÿ‘” ๐Ÿ“Ÿ `404` ๐Ÿ‘ˆ โš™๏ธ Pydantic ๐Ÿท &amp; โœ”๏ธ ๐Ÿ›ƒ `description`.
&amp; ๐Ÿ“จ โฎ๏ธ ๐Ÿ‘” ๐Ÿ“Ÿ `200` ๐Ÿ‘ˆ โš™๏ธ ๐Ÿ‘† `response_model`, โœ‹๏ธ ๐Ÿ”Œ ๐Ÿ›ƒ `example`:
```Python hl_lines="20-31"
{!../../../docs_src/additional_responses/tutorial003.py!}
```
โšซ๏ธ ๐Ÿ”œ ๐ŸŒ ๐ŸŒ€ &amp; ๐Ÿ”Œ ๐Ÿ‘† ๐Ÿ—„, &amp; ๐ŸŽฆ ๐Ÿ› ๏ธ ๐Ÿฉบ:
<img src="/img/tutorial/additional-responses/image01.png">
## ๐ŸŒ€ ๐Ÿ”ข ๐Ÿ“จ &amp; ๐Ÿ›ƒ ๐Ÿ•
๐Ÿ‘† ๐Ÿ’ช ๐Ÿ’š โœ”๏ธ ๐Ÿ” ๐Ÿ“จ ๐Ÿ‘ˆ โœ” ๐Ÿ“š *โžก ๐Ÿ› ๏ธ*, โœ‹๏ธ ๐Ÿ‘† ๐Ÿ’š ๐ŸŒ€ ๐Ÿ‘ซ โฎ๏ธ ๐Ÿ›ƒ ๐Ÿ“จ ๐Ÿ’š ๐Ÿ”  *โžก ๐Ÿ› ๏ธ*.
๐Ÿ“š ๐Ÿ’ผ, ๐Ÿ‘† ๐Ÿ’ช โš™๏ธ ๐Ÿ โš’ "๐Ÿ—" `dict` โฎ๏ธ `**dict_to_unpack`:
```Python
old_dict = {
"old key": "old value",
"second old key": "second old value",
}
new_dict = {**old_dict, "new key": "new value"}
```
๐Ÿ“ฅ, `new_dict` ๐Ÿ”œ ๐Ÿ”Œ ๐ŸŒ ๐Ÿ”‘-๐Ÿ’ฒ ๐Ÿ‘ซ โšช๏ธโžก๏ธ `old_dict` โž• ๐Ÿ†• ๐Ÿ”‘-๐Ÿ’ฒ ๐Ÿ‘ซ:
```Python
{
"old key": "old value",
"second old key": "second old value",
"new key": "new value",
}
```
๐Ÿ‘† ๐Ÿ’ช โš™๏ธ ๐Ÿ‘ˆ โš’ ๐Ÿค-โš™๏ธ ๐Ÿ”ข ๐Ÿ“จ ๐Ÿ‘† *โžก ๐Ÿ› ๏ธ* &amp; ๐ŸŒ€ ๐Ÿ‘ซ โฎ๏ธ ๐ŸŒ– ๐Ÿ›ƒ ๐Ÿ•.
๐Ÿ–ผ:
```Python hl_lines="13-17 26"
{!../../../docs_src/additional_responses/tutorial004.py!}
```
## ๐ŸŒ– โ„น ๐Ÿ”ƒ ๐Ÿ—„ ๐Ÿ“จ
๐Ÿ‘€ โšซ๏ธโ” โšซ๏ธโ” ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ”Œ ๐Ÿ“จ, ๐Ÿ‘† ๐Ÿ’ช โœ… ๐Ÿ‘‰ ๐Ÿ“„ ๐Ÿ—„ ๐Ÿ”ง:
* <a href="https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#responsesObject" class="external-link" target="_blank">๐Ÿ—„ ๐Ÿ“จ ๐ŸŽš</a>, โšซ๏ธ ๐Ÿ”Œ `Response Object`.
* <a href="https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#responseObject" class="external-link" target="_blank">๐Ÿ—„ ๐Ÿ“จ ๐ŸŽš</a>, ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ”Œ ๐Ÿ•ณ โšช๏ธโžก๏ธ ๐Ÿ‘‰ ๐Ÿ”— ๐Ÿ”  ๐Ÿ“จ ๐Ÿ”˜ ๐Ÿ‘† `responses` ๐Ÿ”ข. โœ… `description`, `headers`, `content` (๐Ÿ”˜ ๐Ÿ‘‰ ๐Ÿ‘ˆ ๐Ÿ‘† ๐Ÿ“ฃ ๐ŸŽ ๐Ÿ”‰ ๐Ÿ†Ž &amp; ๐ŸŽป ๐Ÿ”—), &amp; `links`.

37
docs/em/docs/advanced/additional-status-codes.md

@ -0,0 +1,37 @@
# ๐ŸŒ– ๐Ÿ‘” ๐Ÿ“Ÿ
๐Ÿ”ข, **FastAPI** ๐Ÿ”œ ๐Ÿ“จ ๐Ÿ“จ โš™๏ธ `JSONResponse`, ๐Ÿšฎ ๐ŸŽš ๐Ÿ‘† ๐Ÿ“จ โšช๏ธโžก๏ธ ๐Ÿ‘† *โžก ๐Ÿ› ๏ธ* ๐Ÿ”˜ ๐Ÿ‘ˆ `JSONResponse`.
โšซ๏ธ ๐Ÿ”œ โš™๏ธ ๐Ÿ”ข ๐Ÿ‘” ๐Ÿ“Ÿ โš–๏ธ 1๏ธโƒฃ ๐Ÿ‘† โš’ ๐Ÿ‘† *โžก ๐Ÿ› ๏ธ*.
## ๐ŸŒ– ๐Ÿ‘” ๐Ÿ“Ÿ
๐Ÿšฅ ๐Ÿ‘† ๐Ÿ’š ๐Ÿ“จ ๐ŸŒ– ๐Ÿ‘” ๐Ÿ“Ÿ โ†–๏ธ โšช๏ธโžก๏ธ ๐Ÿ‘‘ 1๏ธโƒฃ, ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ‘ˆ ๐Ÿ›ฌ `Response` ๐Ÿ”—, ๐Ÿ’– `JSONResponse`, &amp; โš’ ๐ŸŒ– ๐Ÿ‘” ๐Ÿ“Ÿ ๐Ÿ”—.
๐Ÿ–ผ, โžก๏ธ ๐Ÿ’ฌ ๐Ÿ‘ˆ ๐Ÿ‘† ๐Ÿ’š โœ”๏ธ *โžก ๐Ÿ› ๏ธ* ๐Ÿ‘ˆ โœ” โ„น ๐Ÿฌ, &amp; ๐Ÿ“จ ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ” ๐Ÿ‘” ๐Ÿ“Ÿ 2๏ธโƒฃ0๏ธโƒฃ0๏ธโƒฃ "๐Ÿ‘Œ" ๐Ÿ•โ” ๐Ÿ†.
โœ‹๏ธ ๐Ÿ‘† ๐Ÿ’š โšซ๏ธ ๐Ÿšซ ๐Ÿ†• ๐Ÿฌ. &amp; ๐Ÿ•โ” ๐Ÿฌ ๐Ÿšซ ๐Ÿ”€ โญ, โšซ๏ธ โœ ๐Ÿ‘ซ, &amp; ๐Ÿ“จ ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ” ๐Ÿ‘” ๐Ÿ“Ÿ 2๏ธโƒฃ0๏ธโƒฃ1๏ธโƒฃ "โœ".
๐Ÿ† ๐Ÿ‘ˆ, ๐Ÿ—„ `JSONResponse`, &amp; ๐Ÿ“จ ๐Ÿ‘† ๐ŸŽš ๐Ÿ“ค ๐Ÿ”—, โš’ `status_code` ๐Ÿ‘ˆ ๐Ÿ‘† ๐Ÿ’š:
```Python hl_lines="4 25"
{!../../../docs_src/additional_status_codes/tutorial001.py!}
```
!!! warning
๐Ÿ•โ” ๐Ÿ‘† ๐Ÿ“จ `Response` ๐Ÿ”—, ๐Ÿ’– ๐Ÿ–ผ ๐Ÿ”›, โšซ๏ธ ๐Ÿ”œ ๐Ÿ“จ ๐Ÿ”—.
โšซ๏ธ ๐Ÿ† ๐Ÿšซ ๐ŸŽป โฎ๏ธ ๐Ÿท, โ™’๏ธ.
โš’ ๐Ÿ’ญ โšซ๏ธ โœ”๏ธ ๐Ÿ“Š ๐Ÿ‘† ๐Ÿ’š โšซ๏ธ โœ”๏ธ, &amp; ๐Ÿ‘ˆ ๐Ÿ’ฒ โ˜‘ ๐ŸŽป (๐Ÿšฅ ๐Ÿ‘† โš™๏ธ `JSONResponse`).
!!! note "๐Ÿ“ก โ„น"
๐Ÿ‘† ๐Ÿ’ช โš™๏ธ `from starlette.responses import JSONResponse`.
**FastAPI** ๐Ÿšš ๐ŸŽ `starlette.responses` `fastapi.responses` ๐Ÿช ๐Ÿ‘†, ๐Ÿ‘ฉโ€๐Ÿ’ป. โœ‹๏ธ ๐ŸŒ… ๐Ÿ’ช ๐Ÿ“จ ๐Ÿ‘Ÿ ๐Ÿ”— โšช๏ธโžก๏ธ ๐Ÿ’ƒ. ๐ŸŽ โฎ๏ธ `status`.
## ๐Ÿ—„ &amp; ๐Ÿ› ๏ธ ๐Ÿฉบ
๐Ÿšฅ ๐Ÿ‘† ๐Ÿ“จ ๐ŸŒ– ๐Ÿ‘” ๐Ÿ“Ÿ &amp; ๐Ÿ“จ ๐Ÿ”—, ๐Ÿ‘ซ ๐Ÿ† ๐Ÿšซ ๐Ÿ”Œ ๐Ÿ—„ ๐Ÿ”— (๐Ÿ› ๏ธ ๐Ÿฉบ), โ†ฉ๏ธ FastAPI ๐Ÿšซ โœ”๏ธ ๐ŸŒŒ ๐Ÿ’ญ โช โšซ๏ธโ” ๐Ÿ‘† ๐Ÿšถ ๐Ÿ“จ.
โœ‹๏ธ ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ“„ ๐Ÿ‘ˆ ๐Ÿ‘† ๐Ÿ“Ÿ, โš™๏ธ: [๐ŸŒ– ๐Ÿ“จ](additional-responses.md){.internal-link target=_blank}.

70
docs/em/docs/advanced/advanced-dependencies.md

@ -0,0 +1,70 @@
# ๐Ÿง ๐Ÿ”—
## ๐Ÿ”— ๐Ÿ”—
๐ŸŒ ๐Ÿ”— ๐Ÿ‘ฅ โœ”๏ธ ๐Ÿ‘€ ๐Ÿ”ง ๐Ÿ”ข โš–๏ธ ๐ŸŽ“.
โœ‹๏ธ ๐Ÿ“ค ๐Ÿ’ช ๐Ÿ’ผ ๐ŸŒโ” ๐Ÿ‘† ๐Ÿ’š ๐Ÿ’ช โš’ ๐Ÿ”ข ๐Ÿ”› ๐Ÿ”—, ๐Ÿต โœ”๏ธ ๐Ÿ“ฃ ๐Ÿ“š ๐ŸŽ ๐Ÿ”ข โš–๏ธ ๐ŸŽ“.
โžก๏ธ ๐ŸŒˆ ๐Ÿ‘ˆ ๐Ÿ‘ฅ ๐Ÿ’š โœ”๏ธ ๐Ÿ”— ๐Ÿ‘ˆ โœ… ๐Ÿšฅ ๐Ÿ”ข ๐Ÿ”ข `q` ๐Ÿ”Œ ๐Ÿ”ง ๐ŸŽš.
โœ‹๏ธ ๐Ÿ‘ฅ ๐Ÿ’š ๐Ÿ’ช ๐Ÿ”— ๐Ÿ‘ˆ ๐Ÿ”ง ๐ŸŽš.
## "๐Ÿ‡ง๐Ÿ‡ฒ" ๐Ÿ‘
๐Ÿ ๐Ÿ“ค ๐ŸŒŒ โš’ ๐Ÿ‘ ๐ŸŽ“ "๐Ÿ‡ง๐Ÿ‡ฒ".
๐Ÿšซ ๐ŸŽ“ โšซ๏ธ (โ” โช ๐Ÿ‡ง๐Ÿ‡ฒ), โœ‹๏ธ ๐Ÿ‘ ๐Ÿ‘ˆ ๐ŸŽ“.
๐Ÿ‘ˆ, ๐Ÿ‘ฅ ๐Ÿ“ฃ ๐Ÿ‘ฉโ€๐Ÿ”ฌ `__call__`:
```Python hl_lines="10"
{!../../../docs_src/dependencies/tutorial011.py!}
```
๐Ÿ‘‰ ๐Ÿ’ผ, ๐Ÿ‘‰ `__call__` โšซ๏ธโ” **FastAPI** ๐Ÿ”œ โš™๏ธ โœ… ๐ŸŒ– ๐Ÿ”ข &amp; ๐ŸŽง-๐Ÿ”—, &amp; ๐Ÿ‘‰ โšซ๏ธโ” ๐Ÿ”œ ๐Ÿค™ ๐Ÿšถโ€โ™€๏ธ ๐Ÿ’ฒ ๐Ÿ”ข ๐Ÿ‘† *โžก ๐Ÿ› ๏ธ ๐Ÿ”ข* โช.
## ๐Ÿ”— ๐Ÿ‘
&amp; ๐Ÿ”œ, ๐Ÿ‘ฅ ๐Ÿ’ช โš™๏ธ `__init__` ๐Ÿ“ฃ ๐Ÿ”ข ๐Ÿ‘ ๐Ÿ‘ˆ ๐Ÿ‘ฅ ๐Ÿ’ช โš™๏ธ "๐Ÿ”—" ๐Ÿ”—:
```Python hl_lines="7"
{!../../../docs_src/dependencies/tutorial011.py!}
```
๐Ÿ‘‰ ๐Ÿ’ผ, **FastAPI** ๐Ÿ† ๐Ÿšซ โฑ ๐Ÿ‘† โš–๏ธ ๐Ÿ’… ๐Ÿ”ƒ `__init__`, ๐Ÿ‘ฅ ๐Ÿ”œ โš™๏ธ โšซ๏ธ ๐Ÿ”— ๐Ÿ‘† ๐Ÿ“Ÿ.
## โœ ๐Ÿ‘
๐Ÿ‘ฅ ๐Ÿ’ช โœ ๐Ÿ‘ ๐Ÿ‘‰ ๐ŸŽ“ โฎ๏ธ:
```Python hl_lines="16"
{!../../../docs_src/dependencies/tutorial011.py!}
```
&amp; ๐Ÿ‘ˆ ๐ŸŒŒ ๐Ÿ‘ฅ ๐Ÿ’ช "๐Ÿ”—" ๐Ÿ‘† ๐Ÿ”—, ๐Ÿ‘ˆ ๐Ÿ”œ โœ”๏ธ `"bar"` ๐Ÿ”˜ โšซ๏ธ, ๐Ÿ”ข `checker.fixed_content`.
## โš™๏ธ ๐Ÿ‘ ๐Ÿ”—
โคด๏ธ, ๐Ÿ‘ฅ ๐Ÿ’ช โš™๏ธ ๐Ÿ‘‰ `checker` `Depends(checker)`, โ†ฉ๏ธ `Depends(FixedContentQueryChecker)`, โ†ฉ๏ธ ๐Ÿ”— ๐Ÿ‘, `checker`, ๐Ÿšซ ๐ŸŽ“ โšซ๏ธ.
&amp; ๐Ÿ•โ” โŽ ๐Ÿ”—, **FastAPI** ๐Ÿ”œ ๐Ÿค™ ๐Ÿ‘‰ `checker` ๐Ÿ’–:
```Python
checker(q="somequery")
```
...&amp; ๐Ÿšถโ€โ™€๏ธ โšซ๏ธโ” ๐Ÿ‘ˆ ๐Ÿ“จ ๐Ÿ’ฒ ๐Ÿ”— ๐Ÿ‘† *โžก ๐Ÿ› ๏ธ ๐Ÿ”ข* ๐Ÿ”ข `fixed_content_included`:
```Python hl_lines="20"
{!../../../docs_src/dependencies/tutorial011.py!}
```
!!! tip
๐ŸŒ ๐Ÿ‘‰ ๐Ÿ’ช ๐Ÿ˜‘ ๐ŸŽญ. &amp; โšซ๏ธ ๐Ÿ’ช ๐Ÿšซ ๐Ÿ“ถ ๐Ÿ†‘ โ” โšซ๏ธ โš .
๐Ÿ‘ซ ๐Ÿ–ผ ๐Ÿ˜ซ ๐Ÿ™…, โœ‹๏ธ ๐ŸŽฆ โ” โšซ๏ธ ๐ŸŒ ๐Ÿ‘ท.
๐Ÿ“ƒ ๐Ÿ”ƒ ๐Ÿ’‚โ€โ™‚, ๐Ÿ“ค ๐Ÿš™ ๐Ÿ”ข ๐Ÿ‘ˆ ๐Ÿ› ๏ธ ๐Ÿ‘‰ ๐ŸŽ ๐ŸŒŒ.
๐Ÿšฅ ๐Ÿ‘† ๐Ÿค” ๐ŸŒ ๐Ÿ‘‰, ๐Ÿ‘† โช ๐Ÿ’ญ โ” ๐Ÿ‘ˆ ๐Ÿš™ ๐Ÿงฐ ๐Ÿ’‚โ€โ™‚ ๐Ÿ‘ท ๐Ÿ”˜.

162
docs/em/docs/advanced/async-sql-databases.md

@ -0,0 +1,162 @@
# ๐Ÿ” ๐Ÿ—„ (๐Ÿ”—) ๐Ÿ’ฝ
๐Ÿ‘† ๐Ÿ’ช โš™๏ธ <a href="https://github.com/encode/databases" class="external-link" target="_blank">`encode/databases`</a> โฎ๏ธ **FastAPI** ๐Ÿ”— ๐Ÿ’ฝ โš™๏ธ `async` &amp; `await`.
โšซ๏ธ ๐Ÿ”— โฎ๏ธ:
* โœณ
* โœณ
* ๐Ÿ—„
๐Ÿ‘‰ ๐Ÿ–ผ, ๐Ÿ‘ฅ ๐Ÿ”œ โš™๏ธ **๐Ÿ—„**, โ†ฉ๏ธ โšซ๏ธ โš™๏ธ ๐Ÿ‘ ๐Ÿ“ &amp; ๐Ÿ โœ”๏ธ ๐Ÿ› ๏ธ ๐Ÿ•โ€๐Ÿฆบ. , ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ“ ๐Ÿ‘‰ ๐Ÿ–ผ &amp; ๐Ÿƒ โšซ๏ธ.
โช, ๐Ÿ‘† ๐Ÿญ ๐Ÿˆธ, ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ’š โš™๏ธ ๐Ÿ’ฝ ๐Ÿ’ฝ ๐Ÿ’– **โœณ**.
!!! tip
๐Ÿ‘† ๐Ÿ’ช ๐Ÿ› ๏ธ ๐Ÿ’ญ โšช๏ธโžก๏ธ ๐Ÿ“„ ๐Ÿ”ƒ ๐Ÿ‡ธ๐Ÿ‡ฒ ๐Ÿœ ([๐Ÿ—„ (๐Ÿ”—) ๐Ÿ’ฝ](../tutorial/sql-databases.md){.internal-link target=_blank}), ๐Ÿ’– โš™๏ธ ๐Ÿš™ ๐Ÿ”ข ๐ŸŽญ ๐Ÿ› ๏ธ ๐Ÿ’ฝ, ๐Ÿ”ฌ ๐Ÿ‘† **FastAPI** ๐Ÿ“Ÿ.
๐Ÿ‘‰ ๐Ÿ“„ ๐Ÿšซ โœ” ๐Ÿ“š ๐Ÿ’ญ, ๐ŸŒ“ ๐Ÿ˜‘ <a href="https://www.starlette.io/database/" class="external-link" target="_blank">๐Ÿ’ƒ</a>.
## ๐Ÿ—„ &amp; โš’ ๐Ÿ†™ `SQLAlchemy`
* ๐Ÿ—„ `SQLAlchemy`.
* โœ `metadata` ๐ŸŽš.
* โœ ๐Ÿ“ `notes` โš™๏ธ `metadata` ๐ŸŽš.
```Python hl_lines="4 14 16-22"
{!../../../docs_src/async_sql_databases/tutorial001.py!}
```
!!! tip
๐Ÿ‘€ ๐Ÿ‘ˆ ๐ŸŒ ๐Ÿ‘‰ ๐Ÿ“Ÿ ๐Ÿ˜ ๐Ÿ‡ธ๐Ÿ‡ฒ ๐Ÿš.
`databases` ๐Ÿšซ ๐Ÿ”จ ๐Ÿ•ณ ๐Ÿ“ฅ.
## ๐Ÿ—„ &amp; โš’ ๐Ÿ†™ `databases`
* ๐Ÿ—„ `databases`.
* โœ `DATABASE_URL`.
* โœ `database` ๐ŸŽš.
```Python hl_lines="3 9 12"
{!../../../docs_src/async_sql_databases/tutorial001.py!}
```
!!! tip
๐Ÿšฅ ๐Ÿ‘† ๐Ÿ”— ๐ŸŽ ๐Ÿ’ฝ (โœ… โœณ), ๐Ÿ‘† ๐Ÿ”œ ๐Ÿ’ช ๐Ÿ”€ `DATABASE_URL`.
## โœ ๐Ÿ“
๐Ÿ‘‰ ๐Ÿ’ผ, ๐Ÿ‘ฅ ๐Ÿ— ๐Ÿ“ ๐ŸŽ ๐Ÿ ๐Ÿ“, โœ‹๏ธ ๐Ÿญ, ๐Ÿ‘† ๐Ÿ”œ ๐ŸŽฒ ๐Ÿ’š โœ ๐Ÿ‘ซ โฎ๏ธ โš—, ๐Ÿ› ๏ธ โฎ๏ธ ๐Ÿ› ๏ธ, โ™’๏ธ.
๐Ÿ“ฅ, ๐Ÿ‘‰ ๐Ÿ“„ ๐Ÿ”œ ๐Ÿƒ ๐Ÿ”—, โ–ถ๏ธ๏ธ โญ โ–ถ๏ธ ๐Ÿ‘† **FastAPI** ๐Ÿˆธ.
* โœ `engine`.
* โœ ๐ŸŒ ๐Ÿ“ โšช๏ธโžก๏ธ `metadata` ๐ŸŽš.
```Python hl_lines="25-28"
{!../../../docs_src/async_sql_databases/tutorial001.py!}
```
## โœ ๐Ÿท
โœ Pydantic ๐Ÿท:
* ๐Ÿ—’ โœ (`NoteIn`).
* ๐Ÿ—’ ๐Ÿ“จ (`Note`).
```Python hl_lines="31-33 36-39"
{!../../../docs_src/async_sql_databases/tutorial001.py!}
```
๐Ÿ— ๐Ÿ‘ซ Pydantic ๐Ÿท, ๐Ÿ”ข ๐Ÿ’ฝ ๐Ÿ”œ โœ”, ๐ŸŽป (๐Ÿ—œ), &amp; โœ (๐Ÿ“„).
, ๐Ÿ‘† ๐Ÿ”œ ๐Ÿ’ช ๐Ÿ‘€ โšซ๏ธ ๐ŸŒ ๐ŸŽ“ ๐Ÿ› ๏ธ ๐Ÿฉบ.
## ๐Ÿ”— &amp; ๐Ÿ”Œ
* โœ ๐Ÿ‘† `FastAPI` ๐Ÿˆธ.
* โœ ๐ŸŽ‰ ๐Ÿ•โ€๐Ÿฆบ ๐Ÿ”— &amp; ๐Ÿ”Œ โšช๏ธโžก๏ธ ๐Ÿ’ฝ.
```Python hl_lines="42 45-47 50-52"
{!../../../docs_src/async_sql_databases/tutorial001.py!}
```
## โœ ๐Ÿ—’
โœ *โžก ๐Ÿ› ๏ธ ๐Ÿ”ข* โœ ๐Ÿ—’:
```Python hl_lines="55-58"
{!../../../docs_src/async_sql_databases/tutorial001.py!}
```
!!! Note
๐Ÿ‘€ ๐Ÿ‘ˆ ๐Ÿ‘ฅ ๐Ÿ”— โฎ๏ธ ๐Ÿ’ฝ โš™๏ธ `await`, *โžก ๐Ÿ› ๏ธ ๐Ÿ”ข* ๐Ÿ“ฃ โฎ๏ธ `async`.
### ๐Ÿ‘€ `response_model=List[Note]`
โšซ๏ธ โš™๏ธ `typing.List`.
๐Ÿ‘ˆ ๐Ÿ“„ (&amp; โœ”, ๐ŸŽป, โ›ฝ) ๐Ÿ”ข ๐Ÿ’ฝ, `list` `Note`โ“‚.
## โœ ๐Ÿ—’
โœ *โžก ๐Ÿ› ๏ธ ๐Ÿ”ข* โœ ๐Ÿ—’:
```Python hl_lines="61-65"
{!../../../docs_src/async_sql_databases/tutorial001.py!}
```
!!! Note
๐Ÿ‘€ ๐Ÿ‘ˆ ๐Ÿ‘ฅ ๐Ÿ”— โฎ๏ธ ๐Ÿ’ฝ โš™๏ธ `await`, *โžก ๐Ÿ› ๏ธ ๐Ÿ”ข* ๐Ÿ“ฃ โฎ๏ธ `async`.
### ๐Ÿ”ƒ `{**note.dict(), "id": last_record_id}`
`note` Pydantic `Note` ๐ŸŽš.
`note.dict()` ๐Ÿ“จ `dict` โฎ๏ธ ๐Ÿšฎ ๐Ÿ’ฝ, ๐Ÿ•ณ ๐Ÿ’–:
```Python
{
"text": "Some note",
"completed": False,
}
```
โœ‹๏ธ โšซ๏ธ ๐Ÿšซ โœ”๏ธ `id` ๐Ÿ‘.
๐Ÿ‘ฅ โœ ๐Ÿ†• `dict`, ๐Ÿ‘ˆ ๐Ÿ”Œ ๐Ÿ”‘-๐Ÿ’ฒ ๐Ÿ‘ซ โšช๏ธโžก๏ธ `note.dict()` โฎ๏ธ:
```Python
{**note.dict()}
```
`**note.dict()` "unpacks" the key value pairs directly, so, `{**note.dict()}` would be, more or less, a copy of `note.dict()`.
&amp; โคด๏ธ, ๐Ÿ‘ฅ โ†” ๐Ÿ‘ˆ ๐Ÿ“ `dict`, โŽ โž•1๏ธโƒฃ ๐Ÿ”‘-๐Ÿ’ฒ ๐Ÿ‘ซ: `"id": last_record_id`:
```Python
{**note.dict(), "id": last_record_id}
```
, ๐Ÿ ๐Ÿ ๐Ÿ“จ ๐Ÿ”œ ๐Ÿ•ณ ๐Ÿ’–:
```Python
{
"id": 1,
"text": "Some note",
"completed": False,
}
```
## โœ… โšซ๏ธ
๐Ÿ‘† ๐Ÿ’ช ๐Ÿ“ ๐Ÿ‘‰ ๐Ÿ“Ÿ, &amp; ๐Ÿ‘€ ๐Ÿฉบ <a href="http://127.0.0.1:8000/docs" class="external-link" target="_blank">http://127.0.0.1:8000/docs</a>.
๐Ÿ“ค ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ‘€ ๐ŸŒ ๐Ÿ‘† ๐Ÿ› ๏ธ ๐Ÿ“„ &amp; ๐Ÿ”— โฎ๏ธ โšซ๏ธ:
<img src="/img/tutorial/async-sql-databases/image01.png">
## ๐ŸŒ… โ„น
๐Ÿ‘† ๐Ÿ’ช โœ ๐ŸŒ… ๐Ÿ”ƒ <a href="https://github.com/encode/databases" class="external-link" target="_blank">`encode/databases` ๐Ÿšฎ ๐Ÿ“‚ ๐Ÿ“ƒ</a>.

92
docs/em/docs/advanced/async-tests.md

@ -0,0 +1,92 @@
# ๐Ÿ” ๐Ÿ’ฏ
๐Ÿ‘† โœ”๏ธ โช ๐Ÿ‘€ โ” ๐Ÿ’ฏ ๐Ÿ‘† **FastAPI** ๐Ÿˆธ โš™๏ธ ๐Ÿšš `TestClient`. ๐Ÿ†™ ๐Ÿ”œ, ๐Ÿ‘† โœ”๏ธ ๐Ÿ•ด ๐Ÿ‘€ โ” โœ ๐Ÿ” ๐Ÿ’ฏ, ๐Ÿต โš™๏ธ `async` ๐Ÿ”ข.
โž– ๐Ÿ’ช โš™๏ธ ๐Ÿ” ๐Ÿ”ข ๐Ÿ‘† ๐Ÿ’ฏ ๐Ÿ’ช โš , ๐Ÿ–ผ, ๐Ÿ•โ” ๐Ÿ‘† ๐Ÿ”ฌ ๐Ÿ‘† ๐Ÿ’ฝ ๐Ÿ”. ๐ŸŒˆ ๐Ÿ‘† ๐Ÿ’š ๐Ÿ’ฏ ๐Ÿ“จ ๐Ÿ“จ ๐Ÿ‘† FastAPI ๐Ÿˆธ &amp; โคด๏ธ โœ” ๐Ÿ‘ˆ ๐Ÿ‘† ๐Ÿ‘ฉโ€๐Ÿ’ป โช โœ โ˜‘ ๐Ÿ’ฝ ๐Ÿ’ฝ, โช โš™๏ธ ๐Ÿ” ๐Ÿ’ฝ ๐Ÿ—ƒ.
โžก๏ธ ๐Ÿ‘€ โ” ๐Ÿ‘ฅ ๐Ÿ’ช โš’ ๐Ÿ‘ˆ ๐Ÿ‘ท.
## pytest.mark.anyio
๐Ÿšฅ ๐Ÿ‘ฅ ๐Ÿ’š ๐Ÿค™ ๐Ÿ” ๐Ÿ”ข ๐Ÿ‘† ๐Ÿ’ฏ, ๐Ÿ‘† ๐Ÿ’ฏ ๐Ÿ”ข โœ”๏ธ ๐Ÿ”. AnyIO ๐Ÿšš ๐Ÿ‘Œ ๐Ÿ“ ๐Ÿ‘‰, ๐Ÿ‘ˆ โœ” ๐Ÿ‘ฅ โœ” ๐Ÿ‘ˆ ๐Ÿ’ฏ ๐Ÿ”ข ๐Ÿค™ ๐Ÿ”.
## ๐Ÿ‡ธ๐Ÿ‡ฒ
๐Ÿšฅ ๐Ÿ‘† **FastAPI** ๐Ÿˆธ โš™๏ธ ๐Ÿ˜ `def` ๐Ÿ”ข โ†ฉ๏ธ `async def`, โšซ๏ธ `async` ๐Ÿˆธ ๐Ÿ”˜.
`TestClient` ๐Ÿ”จ ๐ŸŽฑ ๐Ÿ”˜ ๐Ÿค™ ๐Ÿ” FastAPI ๐Ÿˆธ ๐Ÿ‘† ๐Ÿ˜ `def` ๐Ÿ’ฏ ๐Ÿ”ข, โš™๏ธ ๐Ÿฉ โœณ. โœ‹๏ธ ๐Ÿ‘ˆ ๐ŸŽฑ ๐Ÿšซ ๐Ÿ‘ท ๐Ÿšซ๐Ÿ”œ ๐Ÿ•โ” ๐Ÿ‘ฅ โš™๏ธ โšซ๏ธ ๐Ÿ”˜ ๐Ÿ” ๐Ÿ”ข. ๐Ÿƒ ๐Ÿ‘† ๐Ÿ’ฏ ๐Ÿ”, ๐Ÿ‘ฅ ๐Ÿ’ช ๐Ÿ™…โ€โ™‚ ๐Ÿ“ โš™๏ธ `TestClient` ๐Ÿ”˜ ๐Ÿ‘† ๐Ÿ’ฏ ๐Ÿ”ข.
`TestClient` โš“๏ธ ๐Ÿ”› <a href="https://www.python-httpx.org" class="external-link" target="_blank">๐Ÿ‡ธ๐Ÿ‡ฒ</a>, &amp; โ†ฉ๏ธ, ๐Ÿ‘ฅ ๐Ÿ’ช โš™๏ธ โšซ๏ธ ๐Ÿ”— ๐Ÿ’ฏ ๐Ÿ› ๏ธ.
## ๐Ÿ–ผ
๐Ÿ™… ๐Ÿ–ผ, โžก๏ธ ๐Ÿค” ๐Ÿ“ ๐Ÿ“Š ๐ŸŽ 1๏ธโƒฃ ๐Ÿ”ฌ [๐Ÿฆ ๐Ÿˆธ](../tutorial/bigger-applications.md){.internal-link target=_blank} &amp; [๐Ÿ”ฌ](../tutorial/testing.md){.internal-link target=_blank}:
```
.
โ”œโ”€โ”€ app
โ”‚ย ย  โ”œโ”€โ”€ __init__.py
โ”‚ย ย  โ”œโ”€โ”€ main.py
โ”‚ย ย  โ””โ”€โ”€ test_main.py
```
๐Ÿ“ `main.py` ๐Ÿ”œ โœ”๏ธ:
```Python
{!../../../docs_src/async_tests/main.py!}
```
๐Ÿ“ `test_main.py` ๐Ÿ”œ โœ”๏ธ ๐Ÿ’ฏ `main.py`, โšซ๏ธ ๐Ÿ’ช ๐Ÿ‘€ ๐Ÿ’– ๐Ÿ‘‰ ๐Ÿ”œ:
```Python
{!../../../docs_src/async_tests/test_main.py!}
```
## ๐Ÿƒ โšซ๏ธ
๐Ÿ‘† ๐Ÿ’ช ๐Ÿƒ ๐Ÿ‘† ๐Ÿ’ฏ ๐ŸŒ ๐Ÿ“จ:
<div class="termy">
```console
$ pytest
---> 100%
```
</div>
## โ„น
๐Ÿ“‘ `@pytest.mark.anyio` ๐Ÿ’ฌ โœณ ๐Ÿ‘ˆ ๐Ÿ‘‰ ๐Ÿ’ฏ ๐Ÿ”ข ๐Ÿ”œ ๐Ÿค™ ๐Ÿ”:
```Python hl_lines="7"
{!../../../docs_src/async_tests/test_main.py!}
```
!!! tip
๐Ÿ—’ ๐Ÿ‘ˆ ๐Ÿ’ฏ ๐Ÿ”ข ๐Ÿ”œ `async def` โ†ฉ๏ธ `def` โญ ๐Ÿ•โ” โš™๏ธ `TestClient`.
โคด๏ธ ๐Ÿ‘ฅ ๐Ÿ’ช โœ `AsyncClient` โฎ๏ธ ๐Ÿ“ฑ, &amp; ๐Ÿ“จ ๐Ÿ” ๐Ÿ“จ โšซ๏ธ, โš™๏ธ `await`.
```Python hl_lines="9-10"
{!../../../docs_src/async_tests/test_main.py!}
```
๐Ÿ‘‰ ๐ŸŒ“:
```Python
response = client.get('/')
```
...๐Ÿ‘ˆ ๐Ÿ‘ฅ โš™๏ธ โš’ ๐Ÿ‘† ๐Ÿ“จ โฎ๏ธ `TestClient`.
!!! tip
๐Ÿ—’ ๐Ÿ‘ˆ ๐Ÿ‘ฅ โš™๏ธ ๐Ÿ”/โŒ› โฎ๏ธ ๐Ÿ†• `AsyncClient` - ๐Ÿ“จ ๐Ÿ”.
## ๐ŸŽ ๐Ÿ” ๐Ÿ”ข ๐Ÿค™
๐Ÿ”ฌ ๐Ÿ”ข ๐Ÿ”œ ๐Ÿ”, ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ”œ ๐Ÿค™ (&amp; `await`) ๐ŸŽ `async` ๐Ÿ”ข โ†–๏ธ โšช๏ธโžก๏ธ ๐Ÿ“จ ๐Ÿ“จ ๐Ÿ‘† FastAPI ๐Ÿˆธ ๐Ÿ‘† ๐Ÿ’ฏ, โšซ๏ธโ” ๐Ÿ‘† ๐Ÿ”œ ๐Ÿค™ ๐Ÿ‘ซ ๐Ÿ™† ๐Ÿ™† ๐Ÿ‘† ๐Ÿ“Ÿ.
!!! tip
๐Ÿšฅ ๐Ÿ‘† โš” `RuntimeError: Task attached to a different loop` ๐Ÿ•โ” ๐Ÿ› ๏ธ ๐Ÿ” ๐Ÿ”ข ๐Ÿค™ ๐Ÿ‘† ๐Ÿ’ฏ (โœ… ๐Ÿ•โ” โš™๏ธ <a href="https://stackoverflow.com/questions/41584243/runtimeerror-task-attached-to-a-different-loop" class="external-link" target="_blank">โœณ MotorClient</a>) ๐Ÿ’ญ ๐Ÿ”— ๐ŸŽš ๐Ÿ‘ˆ ๐Ÿ’ช ๐ŸŽ‰ โžฐ ๐Ÿ•ด ๐Ÿž ๐Ÿ” ๐Ÿ”ข, โœ… `'@app.on_event("startup")` โฒ.

346
docs/em/docs/advanced/behind-a-proxy.md

@ -0,0 +1,346 @@
# โ›… ๐Ÿ—ณ
โš , ๐Ÿ‘† 5๏ธโƒฃ๐Ÿ“† ๐Ÿ’ช โš™๏ธ **๐Ÿ—ณ** ๐Ÿ’ฝ ๐Ÿ’– Traefik โš–๏ธ ๐Ÿ‘Œ โฎ๏ธ ๐Ÿ“ณ ๐Ÿ‘ˆ ๐Ÿšฎ โž• โžก ๐Ÿ”ก ๐Ÿ‘ˆ ๐Ÿšซ ๐Ÿ‘€ ๐Ÿ‘† ๐Ÿˆธ.
๐Ÿ‘ซ ๐Ÿ’ผ ๐Ÿ‘† ๐Ÿ’ช โš™๏ธ `root_path` ๐Ÿ”— ๐Ÿ‘† ๐Ÿˆธ.
`root_path` ๐Ÿ› ๏ธ ๐Ÿšš ๐Ÿ”ซ ๐Ÿ”ง (๐Ÿ‘ˆ FastAPI ๐Ÿ— ๐Ÿ”›, ๐Ÿ”˜ ๐Ÿ’ƒ).
`root_path` โš™๏ธ ๐Ÿต ๐Ÿ‘ซ ๐ŸŽฏ ๐Ÿ’ผ.
&amp; โšซ๏ธ โš™๏ธ ๐Ÿ”˜ ๐Ÿ•โ” ๐Ÿ—œ ๐ŸŽง-๐Ÿˆธ.
## ๐Ÿ—ณ โฎ๏ธ ๐ŸŽž โžก ๐Ÿ”ก
โœ”๏ธ ๐Ÿ—ณ โฎ๏ธ ๐ŸŽž โžก ๐Ÿ”ก, ๐Ÿ‘‰ ๐Ÿ’ผ, โ›“ ๐Ÿ‘ˆ ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ“ฃ โžก `/app` ๐Ÿ‘† ๐Ÿ“Ÿ, โœ‹๏ธ โคด๏ธ, ๐Ÿ‘† ๐Ÿšฎ ๐Ÿงฝ ๐Ÿ”› ๐Ÿ” (๐Ÿ—ณ) ๐Ÿ‘ˆ ๐Ÿ”œ ๐Ÿšฎ ๐Ÿ‘† **FastAPI** ๐Ÿˆธ ๐Ÿ”ฝ โžก ๐Ÿ’– `/api/v1`.
๐Ÿ‘‰ ๐Ÿ’ผ, โฎ๏ธ โžก `/app` ๐Ÿ”œ ๐Ÿค™ ๐Ÿฆ `/api/v1/app`.
โœ‹๏ธ ๐ŸŒ ๐Ÿ‘† ๐Ÿ“Ÿ โœ ๐Ÿค” ๐Ÿ“ค `/app`.
&amp; ๐Ÿ—ณ ๐Ÿ”œ **"โŽ"** **โžก ๐Ÿ”ก** ๐Ÿ”› โœˆ โญ ๐Ÿ“ถ ๐Ÿ“จ Uvicorn, ๐Ÿšง ๐Ÿ‘† ๐Ÿˆธ ๐Ÿค” ๐Ÿ‘ˆ โšซ๏ธ ๐Ÿฆ `/app`, ๐Ÿ‘ˆ ๐Ÿ‘† ๐Ÿšซ โœ”๏ธ โ„น ๐ŸŒ ๐Ÿ‘† ๐Ÿ“Ÿ ๐Ÿ”Œ ๐Ÿ”ก `/api/v1`.
๐Ÿ†™ ๐Ÿ“ฅ, ๐ŸŒ ๐Ÿ”œ ๐Ÿ‘ท ๐Ÿ›Ž.
โœ‹๏ธ โคด๏ธ, ๐Ÿ•โ” ๐Ÿ‘† ๐Ÿ“‚ ๐Ÿ› ๏ธ ๐Ÿฉบ ๐ŸŽš (๐Ÿ•ธ), โšซ๏ธ ๐Ÿ”œ โŒ› ๐Ÿคš ๐Ÿ—„ ๐Ÿ”— `/openapi.json`, โ†ฉ๏ธ `/api/v1/openapi.json`.
, ๐Ÿ•ธ (๐Ÿ‘ˆ ๐Ÿƒ ๐Ÿ–ฅ) ๐Ÿ”œ ๐Ÿ”„ ๐Ÿ† `/openapi.json` &amp; ๐Ÿšซ๐Ÿ”œ ๐Ÿ’ช ๐Ÿคš ๐Ÿ—„ ๐Ÿ”—.
โ†ฉ๏ธ ๐Ÿ‘ฅ โœ”๏ธ ๐Ÿ—ณ โฎ๏ธ โžก ๐Ÿ”ก `/api/v1` ๐Ÿ‘† ๐Ÿ“ฑ, ๐Ÿ•ธ ๐Ÿ’ช โ˜• ๐Ÿ—„ ๐Ÿ”— `/api/v1/openapi.json`.
```mermaid
graph LR
browser("Browser")
proxy["Proxy on http://0.0.0.0:9999/api/v1/app"]
server["Server on http://127.0.0.1:8000/app"]
browser --> proxy
proxy --> server
```
!!! tip
๐Ÿ“ข `0.0.0.0` ๐Ÿ›Ž โš™๏ธ โ›“ ๐Ÿ‘ˆ ๐Ÿ“‹ ๐Ÿ‘‚ ๐Ÿ”› ๐ŸŒ ๐Ÿ“ข ๐Ÿ’ช ๐Ÿ‘ˆ ๐ŸŽฐ/๐Ÿ’ฝ.
๐Ÿฉบ ๐ŸŽš ๐Ÿ”œ ๐Ÿ’ช ๐Ÿ—„ ๐Ÿ”— ๐Ÿ“ฃ ๐Ÿ‘ˆ ๐Ÿ‘‰ ๐Ÿ› ๏ธ `server` ๐Ÿ”Ž `/api/v1` (โ›… ๐Ÿ—ณ). ๐Ÿ–ผ:
```JSON hl_lines="4-8"
{
"openapi": "3.0.2",
// More stuff here
"servers": [
{
"url": "/api/v1"
}
],
"paths": {
// More stuff here
}
}
```
๐Ÿ‘‰ ๐Ÿ–ผ, "๐Ÿ—ณ" ๐Ÿ’ช ๐Ÿ•ณ ๐Ÿ’– **Traefik**. &amp; ๐Ÿ’ฝ ๐Ÿ”œ ๐Ÿ•ณ ๐Ÿ’– **Uvicorn**, ๐Ÿƒโ€โ™‚ ๐Ÿ‘† FastAPI ๐Ÿˆธ.
### ๐Ÿšš `root_path`
๐Ÿ† ๐Ÿ‘‰, ๐Ÿ‘† ๐Ÿ’ช โš™๏ธ ๐Ÿ“‹ โธ ๐ŸŽ› `--root-path` ๐Ÿ’–:
<div class="termy">
```console
$ uvicorn main:app --root-path /api/v1
<span style="color: green;">INFO</span>: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
```
</div>
๐Ÿšฅ ๐Ÿ‘† โš™๏ธ Hypercorn, โšซ๏ธ โœ”๏ธ ๐ŸŽ› `--root-path`.
!!! note "๐Ÿ“ก โ„น"
๐Ÿ”ซ ๐Ÿ”ง ๐Ÿ”ฌ `root_path` ๐Ÿ‘‰ โš™๏ธ ๐Ÿ’ผ.
&amp; `--root-path` ๐Ÿ“‹ โธ ๐ŸŽ› ๐Ÿšš ๐Ÿ‘ˆ `root_path`.
### โœ… โฎ๏ธ `root_path`
๐Ÿ‘† ๐Ÿ’ช ๐Ÿคš โฎ๏ธ `root_path` โš™๏ธ ๐Ÿ‘† ๐Ÿˆธ ๐Ÿ”  ๐Ÿ“จ, โšซ๏ธ ๐Ÿ• `scope` ๐Ÿ“– (๐Ÿ‘ˆ ๐Ÿ• ๐Ÿ”ซ ๐Ÿ”Œ).
๐Ÿ“ฅ ๐Ÿ‘ฅ โœ… โšซ๏ธ ๐Ÿ“ง ๐ŸŽฆ ๐ŸŽฏ.
```Python hl_lines="8"
{!../../../docs_src/behind_a_proxy/tutorial001.py!}
```
โคด๏ธ, ๐Ÿšฅ ๐Ÿ‘† โ–ถ๏ธ Uvicorn โฎ๏ธ:
<div class="termy">
```console
$ uvicorn main:app --root-path /api/v1
<span style="color: green;">INFO</span>: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
```
</div>
๐Ÿ“จ ๐Ÿ”œ ๐Ÿ•ณ ๐Ÿ’–:
```JSON
{
"message": "Hello World",
"root_path": "/api/v1"
}
```
### โš’ `root_path` FastAPI ๐Ÿ“ฑ
๐Ÿ‘, ๐Ÿšฅ ๐Ÿ‘† ๐Ÿšซ โœ”๏ธ ๐ŸŒŒ ๐Ÿšš ๐Ÿ“‹ โธ ๐ŸŽ› ๐Ÿ’– `--root-path` โš–๏ธ ๐ŸŒ“, ๐Ÿ‘† ๐Ÿ’ช โš’ `root_path` ๐Ÿ”ข ๐Ÿ•โ” ๐Ÿ— ๐Ÿ‘† FastAPI ๐Ÿ“ฑ:
```Python hl_lines="3"
{!../../../docs_src/behind_a_proxy/tutorial002.py!}
```
๐Ÿšถโ€โ™€๏ธ `root_path` `FastAPI` ๐Ÿ”œ ๐ŸŒ“ ๐Ÿšถโ€โ™€๏ธ `--root-path` ๐Ÿ“‹ โธ ๐ŸŽ› Uvicorn โš–๏ธ Hypercorn.
### ๐Ÿ”ƒ `root_path`
โœ”๏ธ ๐Ÿคฏ ๐Ÿ‘ˆ ๐Ÿ’ฝ (Uvicorn) ๐Ÿ† ๐Ÿšซ โš™๏ธ ๐Ÿ‘ˆ `root_path` ๐Ÿ•ณ ๐Ÿ™† ๐ŸŒ˜ ๐Ÿšถโ€โ™€๏ธ โšซ๏ธ ๐Ÿ“ฑ.
โœ‹๏ธ ๐Ÿšฅ ๐Ÿ‘† ๐Ÿšถ โฎ๏ธ ๐Ÿ‘† ๐Ÿ–ฅ <a href="http://127.0.0.1:8000" class="external-link" target="_blank">http://127.0.0.1:8000/app</a> ๐Ÿ‘† ๐Ÿ”œ ๐Ÿ‘€ ๐Ÿ˜ ๐Ÿ“จ:
```JSON
{
"message": "Hello World",
"root_path": "/api/v1"
}
```
, โšซ๏ธ ๐Ÿ† ๐Ÿšซ โŒ› ๐Ÿ” `http://127.0.0.1:8000/api/v1/app`.
Uvicorn ๐Ÿ”œ โŒ› ๐Ÿ—ณ ๐Ÿ” Uvicorn `http://127.0.0.1:8000/app`, &amp; โคด๏ธ โšซ๏ธ ๐Ÿ”œ ๐Ÿ—ณ ๐ŸŽฏ ๐Ÿšฎ โž• `/api/v1` ๐Ÿ”ก ๐Ÿ”› ๐Ÿ”.
## ๐Ÿ”ƒ ๐Ÿ—ณ โฎ๏ธ ๐ŸŽž โžก ๐Ÿ”ก
โœ”๏ธ ๐Ÿคฏ ๐Ÿ‘ˆ ๐Ÿ—ณ โฎ๏ธ ๐ŸŽž โžก ๐Ÿ”ก ๐Ÿ•ด 1๏ธโƒฃ ๐ŸŒŒ ๐Ÿ”— โšซ๏ธ.
๐ŸŽฒ ๐Ÿ“š ๐Ÿ’ผ ๐Ÿ”ข ๐Ÿ”œ ๐Ÿ‘ˆ ๐Ÿ—ณ ๐Ÿšซ โœ”๏ธ ๐Ÿš โžก ๐Ÿ”ก.
๐Ÿ’ผ ๐Ÿ’– ๐Ÿ‘ˆ (๐Ÿต ๐ŸŽž โžก ๐Ÿ”ก), ๐Ÿ—ณ ๐Ÿ”œ ๐Ÿ‘‚ ๐Ÿ”› ๐Ÿ•ณ ๐Ÿ’– `https://myawesomeapp.com`, &amp; โคด๏ธ ๐Ÿšฅ ๐Ÿ–ฅ ๐Ÿšถ `https://myawesomeapp.com/api/v1/app` &amp; ๐Ÿ‘† ๐Ÿ’ฝ (โœ… Uvicorn) ๐Ÿ‘‚ ๐Ÿ”› `http://127.0.0.1:8000` ๐Ÿ—ณ (๐Ÿต ๐ŸŽž โžก ๐Ÿ”ก) ๐Ÿ”œ ๐Ÿ” Uvicorn ๐ŸŽ โžก: `http://127.0.0.1:8000/api/v1/app`.
## ๐Ÿ”ฌ ๐ŸŒ โฎ๏ธ Traefik
๐Ÿ‘† ๐Ÿ’ช ๐Ÿ’ช ๐Ÿƒ ๐Ÿฅผ ๐ŸŒ โฎ๏ธ ๐ŸŽž โžก ๐Ÿ”ก โš™๏ธ <a href="https://docs.traefik.io/" class="external-link" target="_blank">Traefik</a>.
<a href="https://github.com/containous/traefik/releases" class="external-link" target="_blank">โฌ Traefik</a>, โšซ๏ธ ๐Ÿ‘ ๐Ÿ’ฑ, ๐Ÿ‘† ๐Ÿ’ช โš— ๐Ÿ—œ ๐Ÿ“ &amp; ๐Ÿƒ โšซ๏ธ ๐Ÿ”— โšช๏ธโžก๏ธ ๐Ÿ“ถ.
โคด๏ธ โœ ๐Ÿ“ `traefik.toml` โฎ๏ธ:
```TOML hl_lines="3"
[entryPoints]
[entryPoints.http]
address = ":9999"
[providers]
[providers.file]
filename = "routes.toml"
```
๐Ÿ‘‰ ๐Ÿ’ฌ Traefik ๐Ÿ‘‚ ๐Ÿ”› โ›ด 9๏ธโƒฃ9๏ธโƒฃ9๏ธโƒฃ9๏ธโƒฃ &amp; โš™๏ธ โž•1๏ธโƒฃ ๐Ÿ“ `routes.toml`.
!!! tip
๐Ÿ‘ฅ โš™๏ธ โ›ด 9๏ธโƒฃ9๏ธโƒฃ9๏ธโƒฃ9๏ธโƒฃ โ†ฉ๏ธ ๐Ÿฉ ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ” โ›ด 8๏ธโƒฃ0๏ธโƒฃ ๐Ÿ‘ˆ ๐Ÿ‘† ๐Ÿšซ โœ”๏ธ ๐Ÿƒ โšซ๏ธ โฎ๏ธ ๐Ÿ“ก (`sudo`) ๐Ÿ˜Œ.
๐Ÿ”œ โœ ๐Ÿ‘ˆ ๐ŸŽ ๐Ÿ“ `routes.toml`:
```TOML hl_lines="5 12 20"
[http]
[http.middlewares]
[http.middlewares.api-stripprefix.stripPrefix]
prefixes = ["/api/v1"]
[http.routers]
[http.routers.app-http]
entryPoints = ["http"]
service = "app"
rule = "PathPrefix(`/api/v1`)"
middlewares = ["api-stripprefix"]
[http.services]
[http.services.app]
[http.services.app.loadBalancer]
[[http.services.app.loadBalancer.servers]]
url = "http://127.0.0.1:8000"
```
๐Ÿ‘‰ ๐Ÿ“ ๐Ÿ”— Traefik โš™๏ธ โžก ๐Ÿ”ก `/api/v1`.
&amp; โคด๏ธ โšซ๏ธ ๐Ÿ”œ โŽ ๐Ÿšฎ ๐Ÿ“จ ๐Ÿ‘† Uvicorn ๐Ÿƒโ€โ™‚ ๐Ÿ”› `http://127.0.0.1:8000`.
๐Ÿ”œ โ–ถ๏ธ Traefik:
<div class="termy">
```console
$ ./traefik --configFile=traefik.toml
INFO[0000] Configuration loaded from file: /home/user/awesomeapi/traefik.toml
```
</div>
&amp; ๐Ÿ”œ โ–ถ๏ธ ๐Ÿ‘† ๐Ÿ“ฑ โฎ๏ธ Uvicorn, โš™๏ธ `--root-path` ๐ŸŽ›:
<div class="termy">
```console
$ uvicorn main:app --root-path /api/v1
<span style="color: green;">INFO</span>: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
```
</div>
### โœ… ๐Ÿ“จ
๐Ÿ”œ, ๐Ÿšฅ ๐Ÿ‘† ๐Ÿšถ ๐Ÿ“› โฎ๏ธ โ›ด Uvicorn: <a href="http://127.0.0.1:8000/app" class="external-link" target="_blank">http://127.0.0.1:8000/app</a>, ๐Ÿ‘† ๐Ÿ”œ ๐Ÿ‘€ ๐Ÿ˜ ๐Ÿ“จ:
```JSON
{
"message": "Hello World",
"root_path": "/api/v1"
}
```
!!! tip
๐Ÿ‘€ ๐Ÿ‘ˆ โœ‹๏ธ ๐Ÿ‘† ๐Ÿ” โšซ๏ธ `http://127.0.0.1:8000/app` โšซ๏ธ ๐ŸŽฆ `root_path` `/api/v1`, โœŠ โšช๏ธโžก๏ธ ๐ŸŽ› `--root-path`.
&amp; ๐Ÿ”œ ๐Ÿ“‚ ๐Ÿ“› โฎ๏ธ โ›ด Traefik, โœ… โžก ๐Ÿ”ก: <a href="http://127.0.0.1:9999/api/v1/app" class="external-link" target="_blank">http://127.0.0.1:9999/api/v1/app</a>.
๐Ÿ‘ฅ ๐Ÿคš ๐ŸŽ ๐Ÿ“จ:
```JSON
{
"message": "Hello World",
"root_path": "/api/v1"
}
```
โœ‹๏ธ ๐Ÿ‘‰ ๐Ÿ•ฐ ๐Ÿ“› โฎ๏ธ ๐Ÿ”ก โžก ๐Ÿšš ๐Ÿ—ณ: `/api/v1`.
โ†—๏ธ, ๐Ÿ’ญ ๐Ÿ“ฅ ๐Ÿ‘ˆ ๐Ÿ‘ฑ ๐Ÿ”œ ๐Ÿ” ๐Ÿ“ฑ ๐Ÿ”˜ ๐Ÿ—ณ, โฌ โฎ๏ธ โžก ๐Ÿ”ก `/app/v1` "โ˜‘" 1๏ธโƒฃ.
&amp; โฌ ๐Ÿต โžก ๐Ÿ”ก (`http://127.0.0.1:8000/app`), ๐Ÿšš Uvicorn ๐Ÿ”—, ๐Ÿ”œ ๐ŸŽฏ _๐Ÿ—ณ_ (Traefik) ๐Ÿ” โšซ๏ธ.
๐Ÿ‘ˆ ๐ŸŽฆ โ” ๐Ÿ—ณ (Traefik) โš™๏ธ โžก ๐Ÿ”ก &amp; โ” ๐Ÿ’ฝ (Uvicorn) โš™๏ธ `root_path` โšช๏ธโžก๏ธ ๐ŸŽ› `--root-path`.
### โœ… ๐Ÿฉบ ๐ŸŽš
โœ‹๏ธ ๐Ÿ“ฅ ๐ŸŽŠ ๐Ÿ•. ๐Ÿ‘ถ
"๐Ÿ›‚" ๐ŸŒŒ ๐Ÿ” ๐Ÿ“ฑ ๐Ÿ”œ ๐Ÿ”˜ ๐Ÿ—ณ โฎ๏ธ โžก ๐Ÿ”ก ๐Ÿ‘ˆ ๐Ÿ‘ฅ ๐Ÿ”ฌ. , ๐Ÿ‘ฅ ๐Ÿ”œ โŒ›, ๐Ÿšฅ ๐Ÿ‘† ๐Ÿ”„ ๐Ÿฉบ ๐ŸŽš ๐Ÿฆ Uvicorn ๐Ÿ”—, ๐Ÿต โžก ๐Ÿ”ก ๐Ÿ“›, โšซ๏ธ ๐Ÿ† ๐Ÿšซ ๐Ÿ‘ท, โ†ฉ๏ธ โšซ๏ธ โŒ› ๐Ÿ” ๐Ÿ”˜ ๐Ÿ—ณ.
๐Ÿ‘† ๐Ÿ’ช โœ… โšซ๏ธ <a href="http://127.0.0.1:8000/docs" class="external-link" target="_blank">http://127.0.0.1:8000/docs</a>:
<img src="/img/tutorial/behind-a-proxy/image01.png">
โœ‹๏ธ ๐Ÿšฅ ๐Ÿ‘ฅ ๐Ÿ” ๐Ÿฉบ ๐ŸŽš "๐Ÿ›‚" ๐Ÿ“› โš™๏ธ ๐Ÿ—ณ โฎ๏ธ โ›ด `9999`, `/api/v1/docs`, โšซ๏ธ ๐Ÿ‘ท โ˜‘ โ— ๐Ÿ‘ถ
๐Ÿ‘† ๐Ÿ’ช โœ… โšซ๏ธ <a href="http://127.0.0.1:9999/api/v1/docs" class="external-link" target="_blank">http://127.0.0.1:9999/api/v1/docs</a>:
<img src="/img/tutorial/behind-a-proxy/image02.png">
โ–ถ๏ธ๏ธ ๐Ÿ‘ฅ ๐Ÿ’š โšซ๏ธ. ๐Ÿ‘ถ ๐Ÿ‘ถ
๐Ÿ‘‰ โ†ฉ๏ธ FastAPI โš™๏ธ ๐Ÿ‘‰ `root_path` โœ ๐Ÿ”ข `server` ๐Ÿ—„ โฎ๏ธ ๐Ÿ“› ๐Ÿšš `root_path`.
## ๐ŸŒ– ๐Ÿ’ฝ
!!! warning
๐Ÿ‘‰ ๐ŸŒ… ๐Ÿง โš™๏ธ ๐Ÿ’ผ. ๐Ÿ’ญ ๐Ÿ†“ ๐Ÿšถ โšซ๏ธ.
๐Ÿ”ข, **FastAPI** ๐Ÿ”œ โœ `server` ๐Ÿ—„ ๐Ÿ”— โฎ๏ธ ๐Ÿ“› `root_path`.
โœ‹๏ธ ๐Ÿ‘† ๐Ÿ’ช ๐Ÿšš ๐ŸŽ ๐ŸŽ› `servers`, ๐Ÿ–ผ ๐Ÿšฅ ๐Ÿ‘† ๐Ÿ’š *๐ŸŽ* ๐Ÿฉบ ๐ŸŽš ๐Ÿ”— โฎ๏ธ ๐Ÿ— &amp; ๐Ÿญ ๐ŸŒ.
๐Ÿšฅ ๐Ÿ‘† ๐Ÿšถโ€โ™€๏ธ ๐Ÿ›ƒ ๐Ÿ“‡ `servers` &amp; ๐Ÿ“ค `root_path` (โ†ฉ๏ธ ๐Ÿ‘† ๐Ÿ› ๏ธ ๐Ÿ‘จโ€โคโ€๐Ÿ‘จ โ›… ๐Ÿ—ณ), **FastAPI** ๐Ÿ”œ ๐Ÿ“ฉ "๐Ÿ’ฝ" โฎ๏ธ ๐Ÿ‘‰ `root_path` โ–ถ๏ธ ๐Ÿ“‡.
๐Ÿ–ผ:
```Python hl_lines="4-7"
{!../../../docs_src/behind_a_proxy/tutorial003.py!}
```
๐Ÿ”œ ๐Ÿ— ๐Ÿ—„ ๐Ÿ”— ๐Ÿ’–:
```JSON hl_lines="5-7"
{
"openapi": "3.0.2",
// More stuff here
"servers": [
{
"url": "/api/v1"
},
{
"url": "https://stag.example.com",
"description": "Staging environment"
},
{
"url": "https://prod.example.com",
"description": "Production environment"
}
],
"paths": {
// More stuff here
}
}
```
!!! tip
๐Ÿ‘€ ๐Ÿš˜-๐Ÿ— ๐Ÿ’ฝ โฎ๏ธ `url` ๐Ÿ’ฒ `/api/v1`, โœŠ โšช๏ธโžก๏ธ `root_path`.
๐Ÿฉบ ๐ŸŽš <a href="http://127.0.0.1:9999/api/v1/docs" class="external-link" target="_blank">http://127.0.0.1:9999/api/v1/docs</a> โšซ๏ธ ๐Ÿ”œ ๐Ÿ‘€ ๐Ÿ’–:
<img src="/img/tutorial/behind-a-proxy/image03.png">
!!! tip
๐Ÿฉบ ๐ŸŽš ๐Ÿ”œ ๐Ÿ”— โฎ๏ธ ๐Ÿ’ฝ ๐Ÿ‘ˆ ๐Ÿ‘† ๐Ÿ–Š.
### โŽ ๐Ÿง ๐Ÿ’ฝ โšช๏ธโžก๏ธ `root_path`
๐Ÿšฅ ๐Ÿ‘† ๐Ÿšซ ๐Ÿ’š **FastAPI** ๐Ÿ”Œ ๐Ÿง ๐Ÿ’ฝ โš™๏ธ `root_path`, ๐Ÿ‘† ๐Ÿ’ช โš™๏ธ ๐Ÿ”ข `root_path_in_servers=False`:
```Python hl_lines="9"
{!../../../docs_src/behind_a_proxy/tutorial004.py!}
```
&amp; โคด๏ธ โšซ๏ธ ๐Ÿ† ๐Ÿšซ ๐Ÿ”Œ โšซ๏ธ ๐Ÿ—„ ๐Ÿ”—.
## ๐Ÿ—œ ๐ŸŽง-๐Ÿˆธ
๐Ÿšฅ ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ—ป ๐ŸŽง-๐Ÿˆธ (๐Ÿ”ฌ [๐ŸŽง ๐Ÿˆธ - ๐Ÿ—ป](./sub-applications.md){.internal-link target=_blank}) โช โš™๏ธ ๐Ÿ—ณ โฎ๏ธ `root_path`, ๐Ÿ‘† ๐Ÿ’ช โšซ๏ธ ๐Ÿ›Ž, ๐Ÿ‘† ๐Ÿ”œ โŒ›.
FastAPI ๐Ÿ”œ ๐Ÿ”˜ โš™๏ธ `root_path` ๐ŸŽ†, โšซ๏ธ ๐Ÿ”œ ๐Ÿ‘ท. ๐Ÿ‘ถ

58
docs/em/docs/advanced/conditional-openapi.md

@ -0,0 +1,58 @@
# ๐ŸŽฒ ๐Ÿ—„
๐Ÿšฅ ๐Ÿ‘† ๐Ÿ’ช, ๐Ÿ‘† ๐Ÿ’ช โš™๏ธ โš’ &amp; ๐ŸŒ ๐Ÿ”ข ๐Ÿ”— ๐Ÿ—„ โœ” โš“๏ธ ๐Ÿ”› ๐ŸŒ, &amp; โŽ โšซ๏ธ ๐Ÿ•.
## ๐Ÿ”ƒ ๐Ÿ’‚โ€โ™‚, ๐Ÿ”—, &amp; ๐Ÿฉบ
๐Ÿ•ตโ€โ™‚ ๐Ÿ‘† ๐Ÿงพ ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ”ข ๐Ÿญ *๐Ÿšซ๐Ÿ”œ ๐Ÿšซ* ๐ŸŒŒ ๐Ÿ›ก ๐Ÿ‘† ๐Ÿ› ๏ธ.
๐Ÿ‘ˆ ๐Ÿšซ ๐Ÿšฎ ๐Ÿ™† โž• ๐Ÿ’‚โ€โ™‚ ๐Ÿ‘† ๐Ÿ› ๏ธ, *โžก ๐Ÿ› ๏ธ* ๐Ÿ”œ ๐Ÿ’ช ๐ŸŒโ” ๐Ÿ‘ซ.
๐Ÿšฅ ๐Ÿ“ค ๐Ÿ’‚โ€โ™‚ โš  ๐Ÿ‘† ๐Ÿ“Ÿ, โšซ๏ธ ๐Ÿ”œ ๐Ÿ”€.
๐Ÿ•ตโ€โ™‚ ๐Ÿงพ โš’ โšซ๏ธ ๐ŸŒ… โš  ๐Ÿค” โ” ๐Ÿ”— โฎ๏ธ ๐Ÿ‘† ๐Ÿ› ๏ธ, &amp; ๐Ÿ’ช โš’ โšซ๏ธ ๐ŸŒ… โš  ๐Ÿ‘† โ„น โšซ๏ธ ๐Ÿญ. โšซ๏ธ ๐Ÿ’ช ๐Ÿค” ๐ŸŽฏ ๐Ÿ“จ <a href="https://en.wikipedia.org/wiki/Security_through_obscurity" class="external-link" target="_blank">๐Ÿ’‚โ€โ™‚ ๐Ÿ”˜ ๐ŸŒŒ</a>.
๐Ÿšฅ ๐Ÿ‘† ๐Ÿ’š ๐Ÿ” ๐Ÿ‘† ๐Ÿ› ๏ธ, ๐Ÿ“ค ๐Ÿ“š ๐Ÿ‘ ๐Ÿ‘œ ๐Ÿ‘† ๐Ÿ’ช, ๐Ÿ–ผ:
* โš’ ๐Ÿ’ญ ๐Ÿ‘† โœ”๏ธ ๐Ÿ‘ ๐Ÿ”ฌ Pydantic ๐Ÿท ๐Ÿ‘† ๐Ÿ“จ ๐Ÿ’ช &amp; ๐Ÿ“จ.
* ๐Ÿ”— ๐Ÿ™† โœ” โœ” &amp; ๐Ÿ”‘ โš™๏ธ ๐Ÿ”—.
* ๐Ÿ™… ๐Ÿช ๐Ÿ”ข ๐Ÿ”, ๐Ÿ•ด ๐Ÿ”#๏ธโƒฃ.
* ๐Ÿ› ๏ธ &amp; โš™๏ธ ๐Ÿ‘-๐Ÿ’ญ ๐Ÿ” ๐Ÿงฐ, ๐Ÿ’– ๐Ÿ‡ธ๐Ÿ‡ฒ &amp; ๐Ÿฅ™ ๐Ÿค, โ™’๏ธ.
* ๐Ÿšฎ ๐ŸŒ… ๐Ÿงฝ โœ” ๐ŸŽ› โฎ๏ธ Oauth2๏ธโƒฃ โ†” ๐ŸŒโ” ๐Ÿ’ช.
* ...โ™’๏ธ.
๐Ÿ‘, ๐Ÿ‘† 5๏ธโƒฃ๐Ÿ“† โœ”๏ธ ๐Ÿ“ถ ๐ŸŽฏ โš™๏ธ ๐Ÿ’ผ ๐ŸŒโ” ๐Ÿ‘† ๐Ÿค™ ๐Ÿ’ช โŽ ๐Ÿ› ๏ธ ๐Ÿฉบ ๐ŸŒ (โœ… ๐Ÿญ) โš–๏ธ โš“๏ธ ๐Ÿ”› ๐Ÿ“ณ โšช๏ธโžก๏ธ ๐ŸŒ ๐Ÿ”ข.
## ๐ŸŽฒ ๐Ÿ—„ โšช๏ธโžก๏ธ โš’ &amp; ๐Ÿ‡จ๐Ÿ‡ป {
๐Ÿ‘† ๐Ÿ’ช ๐Ÿ’ช โš™๏ธ ๐ŸŽ Pydantic โš’ ๐Ÿ”— ๐Ÿ‘† ๐Ÿ— ๐Ÿ—„ &amp; ๐Ÿฉบ โšœ.
๐Ÿ–ผ:
```Python hl_lines="6 11"
{!../../../docs_src/conditional_openapi/tutorial001.py!}
```
๐Ÿ“ฅ ๐Ÿ‘ฅ ๐Ÿ“ฃ โš’ `openapi_url` โฎ๏ธ ๐ŸŽ ๐Ÿ”ข `"/openapi.json"`.
&amp; โคด๏ธ ๐Ÿ‘ฅ โš™๏ธ โšซ๏ธ ๐Ÿ•โ” ๐Ÿ— `FastAPI` ๐Ÿ“ฑ.
โคด๏ธ ๐Ÿ‘† ๐Ÿ’ช โŽ ๐Ÿ—„ (โœ… ๐ŸŽš ๐Ÿฉบ) โš’ ๐ŸŒ ๐Ÿ”ข `OPENAPI_URL` ๐Ÿ› ๐ŸŽป, ๐Ÿ’–:
<div class="termy">
```console
$ OPENAPI_URL= uvicorn main:app
<span style="color: green;">INFO</span>: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
```
</div>
โคด๏ธ ๐Ÿšฅ ๐Ÿ‘† ๐Ÿšถ ๐Ÿ“› `/openapi.json`, `/docs`, โš–๏ธ `/redoc` ๐Ÿ‘† ๐Ÿ”œ ๐Ÿคš `404 Not Found` โŒ ๐Ÿ’–:
```JSON
{
"detail": "Not Found"
}
```

109
docs/em/docs/advanced/custom-request-and-route.md

@ -0,0 +1,109 @@
# ๐Ÿ›ƒ ๐Ÿ“จ &amp; APIRoute ๐ŸŽ“
๐Ÿ’ผ, ๐Ÿ‘† 5๏ธโƒฃ๐Ÿ“† ๐Ÿ’š ๐Ÿ” โš› โš™๏ธ `Request` &amp; `APIRoute` ๐ŸŽ“.
๐ŸŽฏ, ๐Ÿ‘‰ 5๏ธโƒฃ๐Ÿ“† ๐Ÿ‘ ๐ŸŽ› โš› ๐Ÿ› ๏ธ.
๐Ÿ–ผ, ๐Ÿšฅ ๐Ÿ‘† ๐Ÿ’š โœ โš–๏ธ ๐Ÿ”ฌ ๐Ÿ“จ ๐Ÿ’ช โญ โšซ๏ธ ๐Ÿ› ๏ธ ๐Ÿ‘† ๐Ÿˆธ.
!!! danger
๐Ÿ‘‰ "๐Ÿง" โš’.
๐Ÿšฅ ๐Ÿ‘† โ–ถ๏ธ โฎ๏ธ **FastAPI** ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ’š ๐Ÿšถ ๐Ÿ‘‰ ๐Ÿ“„.
## โš™๏ธ ๐Ÿ’ผ
โš™๏ธ ๐Ÿ’ผ ๐Ÿ”Œ:
* ๐Ÿญ ๐Ÿšซ-๐ŸŽป ๐Ÿ“จ ๐Ÿ’ช ๐ŸŽป (โœ… <a href="https://msgpack.org/index.html" class="external-link" target="_blank">`msgpack`</a>).
* ๐Ÿ—œ ๐Ÿ—œ-๐Ÿ—œ ๐Ÿ“จ ๐Ÿ’ช.
* ๐Ÿ” ๐Ÿšจ ๐ŸŒ ๐Ÿ“จ ๐Ÿ’ช.
## ๐Ÿšš ๐Ÿ›ƒ ๐Ÿ“จ ๐Ÿ’ช ๐Ÿ”ข
โžก๏ธ ๐Ÿ‘€ โ” โš’ โš™๏ธ ๐Ÿ›ƒ `Request` ๐Ÿฟ ๐Ÿ—œ ๐Ÿ—œ ๐Ÿ“จ.
&amp; `APIRoute` ๐Ÿฟ โš™๏ธ ๐Ÿ‘ˆ ๐Ÿ›ƒ ๐Ÿ“จ ๐ŸŽ“.
### โœ ๐Ÿ›ƒ `GzipRequest` ๐ŸŽ“
!!! tip
๐Ÿ‘‰ ๐Ÿงธ ๐Ÿ–ผ ๐ŸŽฆ โ” โšซ๏ธ ๐Ÿ‘ท, ๐Ÿšฅ ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ—œ ๐Ÿ•โ€๐Ÿฆบ, ๐Ÿ‘† ๐Ÿ’ช โš™๏ธ ๐Ÿšš [`GzipMiddleware`](./middleware.md#gzipmiddleware){.internal-link target=_blank}.
๐Ÿฅ‡, ๐Ÿ‘ฅ โœ `GzipRequest` ๐ŸŽ“, โ” ๐Ÿ”œ ๐Ÿ“ `Request.body()` ๐Ÿ‘ฉโ€๐Ÿ”ฌ ๐Ÿ—œ ๐Ÿ’ช ๐Ÿ” โ˜‘ ๐ŸŽš.
๐Ÿšฅ ๐Ÿ“ค ๐Ÿ™…โ€โ™‚ `gzip` ๐ŸŽš, โšซ๏ธ ๐Ÿ”œ ๐Ÿšซ ๐Ÿ”„ ๐Ÿ—œ ๐Ÿ’ช.
๐Ÿ‘ˆ ๐ŸŒŒ, ๐ŸŽ ๐Ÿ›ฃ ๐ŸŽ“ ๐Ÿ’ช ๐Ÿต ๐Ÿ—œ ๐Ÿ—œ โš–๏ธ ๐Ÿ—œ ๐Ÿ“จ.
```Python hl_lines="8-15"
{!../../../docs_src/custom_request_and_route/tutorial001.py!}
```
### โœ ๐Ÿ›ƒ `GzipRoute` ๐ŸŽ“
โญ, ๐Ÿ‘ฅ โœ ๐Ÿ›ƒ ๐Ÿฟ `fastapi.routing.APIRoute` ๐Ÿ‘ˆ ๐Ÿ”œ โš’ โš™๏ธ `GzipRequest`.
๐Ÿ‘‰ ๐Ÿ•ฐ, โšซ๏ธ ๐Ÿ”œ ๐Ÿ“ ๐Ÿ‘ฉโ€๐Ÿ”ฌ `APIRoute.get_route_handler()`.
๐Ÿ‘‰ ๐Ÿ‘ฉโ€๐Ÿ”ฌ ๐Ÿ“จ ๐Ÿ”ข. &amp; ๐Ÿ‘ˆ ๐Ÿ”ข โšซ๏ธโ” ๐Ÿ”œ ๐Ÿ“จ ๐Ÿ“จ &amp; ๐Ÿ“จ ๐Ÿ“จ.
๐Ÿ“ฅ ๐Ÿ‘ฅ โš™๏ธ โšซ๏ธ โœ `GzipRequest` โšช๏ธโžก๏ธ โฎ๏ธ ๐Ÿ“จ.
```Python hl_lines="18-26"
{!../../../docs_src/custom_request_and_route/tutorial001.py!}
```
!!! note "๐Ÿ“ก โ„น"
`Request` โœ”๏ธ `request.scope` ๐Ÿ”ข, ๐Ÿ‘ˆ ๐Ÿ `dict` โš— ๐Ÿ—ƒ ๐Ÿ”— ๐Ÿ“จ.
`Request` โœ”๏ธ `request.receive`, ๐Ÿ‘ˆ ๐Ÿ”ข "๐Ÿ“จ" ๐Ÿ’ช ๐Ÿ“จ.
`scope` `dict` &amp; `receive` ๐Ÿ”ข ๐Ÿ‘ฏโ€โ™‚๏ธ ๐Ÿ• ๐Ÿ”ซ ๐Ÿ”ง.
&amp; ๐Ÿ‘ˆ 2๏ธโƒฃ ๐Ÿ‘œ, `scope` &amp; `receive`, โšซ๏ธโ” ๐Ÿ’ช โœ ๐Ÿ†• `Request` ๐Ÿ‘.
๐Ÿ’ก ๐ŸŒ… ๐Ÿ”ƒ `Request` โœ… <a href="https://www.starlette.io/requests/" class="external-link" target="_blank">๐Ÿ’ƒ ๐Ÿฉบ ๐Ÿ”ƒ ๐Ÿ“จ</a>.
๐Ÿ•ด ๐Ÿ‘œ ๐Ÿ”ข ๐Ÿ“จ `GzipRequest.get_route_handler` ๐Ÿ”จ ๐ŸŽ ๐Ÿ—œ `Request` `GzipRequest`.
๐Ÿ”จ ๐Ÿ‘‰, ๐Ÿ‘† `GzipRequest` ๐Ÿ”œ โœŠ ๐Ÿ’… ๐Ÿ—œ ๐Ÿ“Š (๐Ÿšฅ ๐Ÿ’ช) โญ ๐Ÿšถโ€โ™€๏ธ โšซ๏ธ ๐Ÿ‘† *โžก ๐Ÿ› ๏ธ*.
โฎ๏ธ ๐Ÿ‘ˆ, ๐ŸŒ ๐Ÿญ โš› ๐ŸŽ.
โœ‹๏ธ โ†ฉ๏ธ ๐Ÿ‘† ๐Ÿ”€ `GzipRequest.body`, ๐Ÿ“จ ๐Ÿ’ช ๐Ÿ”œ ๐Ÿ” ๐Ÿ—œ ๐Ÿ•โ” โšซ๏ธ ๐Ÿ“ **FastAPI** ๐Ÿ•โ” ๐Ÿ’ช.
## ๐Ÿ” ๐Ÿ“จ ๐Ÿ’ช โš  ๐Ÿ•โ€๐Ÿฆบ
!!! tip
โŽ ๐Ÿ‘‰ ๐ŸŽ โš , โšซ๏ธ ๐ŸŽฒ ๐Ÿ“š โฉ โš™๏ธ `body` ๐Ÿ›ƒ ๐Ÿ•โ€๐Ÿฆบ `RequestValidationError` ([๐Ÿšš โŒ](../tutorial/handling-errors.md#use-the-requestvalidationerror-body){.internal-link target=_blank}).
โœ‹๏ธ ๐Ÿ‘‰ ๐Ÿ–ผ โ˜‘ &amp; โšซ๏ธ ๐ŸŽฆ โ” ๐Ÿ”— โฎ๏ธ ๐Ÿ”— ๐Ÿฆฒ.
๐Ÿ‘ฅ ๐Ÿ’ช โš™๏ธ ๐Ÿ‘‰ ๐ŸŽ ๐ŸŽฏ ๐Ÿ” ๐Ÿ“จ ๐Ÿ’ช โš  ๐Ÿ•โ€๐Ÿฆบ.
๐ŸŒ ๐Ÿ‘ฅ ๐Ÿ’ช ๐Ÿต ๐Ÿ“จ ๐Ÿ”˜ `try`/`except` ๐Ÿซ:
```Python hl_lines="13 15"
{!../../../docs_src/custom_request_and_route/tutorial002.py!}
```
๐Ÿšฅ โš  ๐Ÿ“‰, `Request` ๐Ÿ‘ ๐Ÿ”œ โ†”, ๐Ÿ‘ฅ ๐Ÿ’ช โœ &amp; โš’ โš™๏ธ ๐Ÿ“จ ๐Ÿ’ช ๐Ÿ•โ” ๐Ÿšš โŒ:
```Python hl_lines="16-18"
{!../../../docs_src/custom_request_and_route/tutorial002.py!}
```
## ๐Ÿ›ƒ `APIRoute` ๐ŸŽ“ ๐Ÿ“ป
๐Ÿ‘† ๐Ÿ’ช โš’ `route_class` ๐Ÿ”ข `APIRouter`:
```Python hl_lines="26"
{!../../../docs_src/custom_request_and_route/tutorial003.py!}
```
๐Ÿ‘‰ ๐Ÿ–ผ, *โžก ๐Ÿ› ๏ธ* ๐Ÿ”ฝ `router` ๐Ÿ”œ โš™๏ธ ๐Ÿ›ƒ `TimedRoute` ๐ŸŽ“, &amp; ๐Ÿ”œ โœ”๏ธ โž• `X-Response-Time` ๐ŸŽš ๐Ÿ“จ โฎ๏ธ ๐Ÿ•ฐ โšซ๏ธ โœŠ ๐Ÿ— ๐Ÿ“จ:
```Python hl_lines="13-20"
{!../../../docs_src/custom_request_and_route/tutorial003.py!}
```

300
docs/em/docs/advanced/custom-response.md

@ -0,0 +1,300 @@
# ๐Ÿ›ƒ ๐Ÿ“จ - ๐Ÿ•ธ, ๐ŸŽ, ๐Ÿ“, ๐ŸŽ
๐Ÿ”ข, **FastAPI** ๐Ÿ”œ ๐Ÿ“จ ๐Ÿ“จ โš™๏ธ `JSONResponse`.
๐Ÿ‘† ๐Ÿ’ช ๐Ÿ” โšซ๏ธ ๐Ÿ›ฌ `Response` ๐Ÿ”— ๐Ÿ‘€ [๐Ÿ“จ ๐Ÿ“จ ๐Ÿ”—](response-directly.md){.internal-link target=_blank}.
โœ‹๏ธ ๐Ÿšฅ ๐Ÿ‘† ๐Ÿ“จ `Response` ๐Ÿ”—, ๐Ÿ“Š ๐Ÿ† ๐Ÿšซ ๐Ÿ” ๐Ÿ—œ, &amp; ๐Ÿงพ ๐Ÿ† ๐Ÿšซ ๐Ÿ” ๐Ÿ— (๐Ÿ–ผ, ๐Ÿ”Œ ๐ŸŽฏ "๐Ÿ“ป ๐Ÿ†Ž", ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ” ๐ŸŽš `Content-Type` ๐Ÿ• ๐Ÿ— ๐Ÿ—„).
โœ‹๏ธ ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ“ฃ `Response` ๐Ÿ‘ˆ ๐Ÿ‘† ๐Ÿ’š โš™๏ธ, *โžก ๐Ÿ› ๏ธ ๐Ÿ‘จโ€๐ŸŽจ*.
๐ŸŽš ๐Ÿ‘ˆ ๐Ÿ‘† ๐Ÿ“จ โšช๏ธโžก๏ธ ๐Ÿ‘† *โžก ๐Ÿ› ๏ธ ๐Ÿ”ข* ๐Ÿ”œ ๐Ÿšฎ ๐Ÿ”˜ ๐Ÿ‘ˆ `Response`.
&amp; ๐Ÿšฅ ๐Ÿ‘ˆ `Response` โœ”๏ธ ๐ŸŽป ๐Ÿ“ป ๐Ÿ†Ž (`application/json`), ๐Ÿ’– ๐Ÿ’ผ โฎ๏ธ `JSONResponse` &amp; `UJSONResponse`, ๐Ÿ’ฝ ๐Ÿ‘† ๐Ÿ“จ ๐Ÿ”œ ๐Ÿ” ๐Ÿ—œ (&amp; โ›ฝ) โฎ๏ธ ๐Ÿ™† Pydantic `response_model` ๐Ÿ‘ˆ ๐Ÿ‘† ๐Ÿ“ฃ *โžก ๐Ÿ› ๏ธ ๐Ÿ‘จโ€๐ŸŽจ*.
!!! note
๐Ÿšฅ ๐Ÿ‘† โš™๏ธ ๐Ÿ“จ ๐ŸŽ“ โฎ๏ธ ๐Ÿ™…โ€โ™‚ ๐Ÿ“ป ๐Ÿ†Ž, FastAPI ๐Ÿ”œ โŒ› ๐Ÿ‘† ๐Ÿ“จ โœ”๏ธ ๐Ÿ™…โ€โ™‚ ๐ŸŽš, โšซ๏ธ ๐Ÿ”œ ๐Ÿšซ ๐Ÿ“„ ๐Ÿ“จ ๐Ÿ“ ๐Ÿšฎ ๐Ÿ— ๐Ÿ—„ ๐Ÿฉบ.
## โš™๏ธ `ORJSONResponse`
๐Ÿ–ผ, ๐Ÿšฅ ๐Ÿ‘† โœŠ ๐ŸŽญ, ๐Ÿ‘† ๐Ÿ’ช โŽ &amp; โš™๏ธ <a href="https://github.com/ijl/orjson" class="external-link" target="_blank">`orjson`</a> &amp; โš’ ๐Ÿ“จ `ORJSONResponse`.
๐Ÿ—„ `Response` ๐ŸŽ“ (๐ŸŽง-๐ŸŽ“) ๐Ÿ‘† ๐Ÿ’š โš™๏ธ &amp; ๐Ÿ“ฃ โšซ๏ธ *โžก ๐Ÿ› ๏ธ ๐Ÿ‘จโ€๐ŸŽจ*.
โญ• ๐Ÿ“จ, ๐Ÿ“จ `Response` ๐Ÿ”— ๐ŸŒ… โฉ ๐ŸŒ˜ ๐Ÿ›ฌ ๐Ÿ“–.
๐Ÿ‘‰ โ†ฉ๏ธ ๐Ÿ”ข, FastAPI ๐Ÿ”œ โœ” ๐Ÿ”  ๐Ÿฌ ๐Ÿ”˜ &amp; โš’ ๐Ÿ’ญ โšซ๏ธ ๐ŸŽป โฎ๏ธ ๐ŸŽป, โš™๏ธ ๐ŸŽ [๐ŸŽป ๐Ÿ”— ๐Ÿ”ข](../tutorial/encoder.md){.internal-link target=_blank} ๐Ÿ”ฌ ๐Ÿ”ฐ. ๐Ÿ‘‰ โšซ๏ธโ” โœ” ๐Ÿ‘† ๐Ÿ“จ **โŒ ๐ŸŽš**, ๐Ÿ–ผ ๐Ÿ’ฝ ๐Ÿท.
โœ‹๏ธ ๐Ÿšฅ ๐Ÿ‘† ๐ŸŽฏ ๐Ÿ‘ˆ ๐ŸŽš ๐Ÿ‘ˆ ๐Ÿ‘† ๐Ÿ›ฌ **๐ŸŽป โฎ๏ธ ๐ŸŽป**, ๐Ÿ‘† ๐Ÿ’ช ๐Ÿšถโ€โ™€๏ธ โšซ๏ธ ๐Ÿ”— ๐Ÿ“จ ๐ŸŽ“ &amp; โŽ โž• ๐ŸŒฅ ๐Ÿ‘ˆ FastAPI ๐Ÿ”œ โœ”๏ธ ๐Ÿšถโ€โ™€๏ธ ๐Ÿ‘† ๐Ÿ“จ ๐ŸŽš ๐Ÿ”˜ `jsonable_encoder` โญ ๐Ÿšถโ€โ™€๏ธ โšซ๏ธ ๐Ÿ“จ ๐ŸŽ“.
```Python hl_lines="2 7"
{!../../../docs_src/custom_response/tutorial001b.py!}
```
!!! info
๐Ÿ”ข `response_class` ๐Ÿ”œ โš™๏ธ ๐Ÿ”ฌ "๐Ÿ“ป ๐Ÿ†Ž" ๐Ÿ“จ.
๐Ÿ‘‰ ๐Ÿ’ผ, ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ” ๐ŸŽš `Content-Type` ๐Ÿ”œ โš’ `application/json`.
&amp; โšซ๏ธ ๐Ÿ”œ ๐Ÿ“„ โœ… ๐Ÿ—„.
!!! tip
`ORJSONResponse` โณ ๐Ÿ•ด ๐Ÿ’ช FastAPI, ๐Ÿšซ ๐Ÿ’ƒ.
## ๐Ÿ•ธ ๐Ÿ“จ
๐Ÿ“จ ๐Ÿ“จ โฎ๏ธ ๐Ÿ•ธ ๐Ÿ”— โšช๏ธโžก๏ธ **FastAPI**, โš™๏ธ `HTMLResponse`.
* ๐Ÿ—„ `HTMLResponse`.
* ๐Ÿšถโ€โ™€๏ธ `HTMLResponse` ๐Ÿ”ข `response_class` ๐Ÿ‘† *โžก ๐Ÿ› ๏ธ ๐Ÿ‘จโ€๐ŸŽจ*.
```Python hl_lines="2 7"
{!../../../docs_src/custom_response/tutorial002.py!}
```
!!! info
๐Ÿ”ข `response_class` ๐Ÿ”œ โš™๏ธ ๐Ÿ”ฌ "๐Ÿ“ป ๐Ÿ†Ž" ๐Ÿ“จ.
๐Ÿ‘‰ ๐Ÿ’ผ, ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ” ๐ŸŽš `Content-Type` ๐Ÿ”œ โš’ `text/html`.
&amp; โšซ๏ธ ๐Ÿ”œ ๐Ÿ“„ โœ… ๐Ÿ—„.
### ๐Ÿ“จ `Response`
๐Ÿ‘€ [๐Ÿ“จ ๐Ÿ“จ ๐Ÿ”—](response-directly.md){.internal-link target=_blank}, ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ” ๐Ÿ“จ ๐Ÿ”— ๐Ÿ‘† *โžก ๐Ÿ› ๏ธ*, ๐Ÿ›ฌ โšซ๏ธ.
๐ŸŽ ๐Ÿ–ผ โšช๏ธโžก๏ธ ๐Ÿ”›, ๐Ÿ›ฌ `HTMLResponse`, ๐Ÿ’ช ๐Ÿ‘€ ๐Ÿ’–:
```Python hl_lines="2 7 19"
{!../../../docs_src/custom_response/tutorial003.py!}
```
!!! warning
`Response` ๐Ÿ“จ ๐Ÿ”— ๐Ÿ‘† *โžก ๐Ÿ› ๏ธ ๐Ÿ”ข* ๐Ÿ† ๐Ÿšซ ๐Ÿ“„ ๐Ÿ—„ (๐Ÿ–ผ, `Content-Type` ๐Ÿ† ๐Ÿšซ ๐Ÿ“„) &amp; ๐Ÿ† ๐Ÿšซ โญ ๐Ÿง ๐ŸŽ“ ๐Ÿฉบ.
!!! info
โ†—๏ธ, โ˜‘ `Content-Type` ๐ŸŽš, ๐Ÿ‘” ๐Ÿ“Ÿ, โ™’๏ธ, ๐Ÿ”œ ๐Ÿ‘Ÿ โšช๏ธโžก๏ธ `Response` ๐ŸŽš ๐Ÿ‘† ๐Ÿ“จ.
### ๐Ÿ“„ ๐Ÿ—„ &amp; ๐Ÿ” `Response`
๐Ÿšฅ ๐Ÿ‘† ๐Ÿ’š ๐Ÿ” ๐Ÿ“จ โšช๏ธโžก๏ธ ๐Ÿ”˜ ๐Ÿ”ข โœ‹๏ธ ๐ŸŽ ๐Ÿ•ฐ ๐Ÿ“„ "๐Ÿ“ป ๐Ÿ†Ž" ๐Ÿ—„, ๐Ÿ‘† ๐Ÿ’ช โš™๏ธ `response_class` ๐Ÿ”ข &amp; ๐Ÿ“จ `Response` ๐ŸŽš.
`response_class` ๐Ÿ”œ โคด๏ธ โš™๏ธ ๐Ÿ•ด ๐Ÿ“„ ๐Ÿ—„ *โžก ๐Ÿ› ๏ธ*, โœ‹๏ธ ๐Ÿ‘† `Response` ๐Ÿ”œ โš™๏ธ.
#### ๐Ÿ“จ `HTMLResponse` ๐Ÿ”—
๐Ÿ–ผ, โšซ๏ธ ๐Ÿ’ช ๐Ÿ•ณ ๐Ÿ’–:
```Python hl_lines="7 21 23"
{!../../../docs_src/custom_response/tutorial004.py!}
```
๐Ÿ‘‰ ๐Ÿ–ผ, ๐Ÿ”ข `generate_html_response()` โช ๐Ÿ— &amp; ๐Ÿ“จ `Response` โ†ฉ๏ธ ๐Ÿ›ฌ ๐Ÿ•ธ `str`.
๐Ÿ›ฌ ๐Ÿ ๐Ÿค™ `generate_html_response()`, ๐Ÿ‘† โช ๐Ÿ›ฌ `Response` ๐Ÿ‘ˆ ๐Ÿ”œ ๐Ÿ” ๐Ÿ”ข **FastAPI** ๐ŸŽญ.
โœ‹๏ธ ๐Ÿ‘† ๐Ÿšถโ€โ™€๏ธ `HTMLResponse` `response_class` ๐Ÿ’โ€โ™‚๏ธ, **FastAPI** ๐Ÿ”œ ๐Ÿ’ญ โ” ๐Ÿ“„ โšซ๏ธ ๐Ÿ—„ &amp; ๐ŸŽ“ ๐Ÿฉบ ๐Ÿ•ธ โฎ๏ธ `text/html`:
<img src="/img/tutorial/custom-response/image01.png">
## ๐Ÿ’ช ๐Ÿ“จ
๐Ÿ“ฅ ๐Ÿ’ช ๐Ÿ“จ.
โœ”๏ธ ๐Ÿคฏ ๐Ÿ‘ˆ ๐Ÿ‘† ๐Ÿ’ช โš™๏ธ `Response` ๐Ÿ“จ ๐Ÿ•ณ ๐Ÿ™†, โš–๏ธ โœ ๐Ÿ›ƒ ๐ŸŽง-๐ŸŽ“.
!!! note "๐Ÿ“ก โ„น"
๐Ÿ‘† ๐Ÿ’ช โš™๏ธ `from starlette.responses import HTMLResponse`.
**FastAPI** ๐Ÿšš ๐ŸŽ `starlette.responses` `fastapi.responses` ๐Ÿช ๐Ÿ‘†, ๐Ÿ‘ฉโ€๐Ÿ’ป. โœ‹๏ธ ๐ŸŒ… ๐Ÿ’ช ๐Ÿ“จ ๐Ÿ‘Ÿ ๐Ÿ”— โšช๏ธโžก๏ธ ๐Ÿ’ƒ.
### `Response`
๐Ÿ‘‘ `Response` ๐ŸŽ“, ๐ŸŒ ๐ŸŽ ๐Ÿ“จ ๐Ÿ˜– โšช๏ธโžก๏ธ โšซ๏ธ.
๐Ÿ‘† ๐Ÿ’ช ๐Ÿ“จ โšซ๏ธ ๐Ÿ”—.
โšซ๏ธ ๐Ÿšซ ๐Ÿ“„ ๐Ÿ”ข:
* `content` - `str` โš–๏ธ `bytes`.
* `status_code` - `int` ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ” ๐Ÿ‘” ๐Ÿ“Ÿ.
* `headers` - `dict` ๐ŸŽป.
* `media_type` - `str` ๐Ÿค ๐Ÿ“ป ๐Ÿ†Ž. ๐Ÿคถ โ“‚. `"text/html"`.
FastAPI (๐Ÿค™ ๐Ÿ’ƒ) ๐Ÿ”œ ๐Ÿ” ๐Ÿ”Œ ๐ŸŽš-๐Ÿ“ ๐ŸŽš. โšซ๏ธ ๐Ÿ”œ ๐Ÿ”Œ ๐ŸŽš-๐Ÿ†Ž ๐ŸŽš, โš“๏ธ ๐Ÿ”› = &amp; ๐Ÿ” = โœ ๐Ÿ†Ž.
```Python hl_lines="1 18"
{!../../../docs_src/response_directly/tutorial002.py!}
```
### `HTMLResponse`
โœŠ โœ โš–๏ธ ๐Ÿ”ข &amp; ๐Ÿ“จ ๐Ÿ•ธ ๐Ÿ“จ, ๐Ÿ‘† โœ ๐Ÿ”›.
### `PlainTextResponse`
โœŠ โœ โš–๏ธ ๐Ÿ”ข &amp; ๐Ÿ“จ โœ… โœ ๐Ÿ“จ.
```Python hl_lines="2 7 9"
{!../../../docs_src/custom_response/tutorial005.py!}
```
### `JSONResponse`
โœŠ ๐Ÿ’ฝ &amp; ๐Ÿ“จ `application/json` ๐Ÿ—œ ๐Ÿ“จ.
๐Ÿ‘‰ ๐Ÿ”ข ๐Ÿ“จ โš™๏ธ **FastAPI**, ๐Ÿ‘† โœ ๐Ÿ”›.
### `ORJSONResponse`
โฉ ๐ŸŽ› ๐ŸŽป ๐Ÿ“จ โš™๏ธ <a href="https://github.com/ijl/orjson" class="external-link" target="_blank">`orjson`</a>, ๐Ÿ‘† โœ ๐Ÿ”›.
### `UJSONResponse`
๐ŸŽ› ๐ŸŽป ๐Ÿ“จ โš™๏ธ <a href="https://github.com/ultrajson/ultrajson" class="external-link" target="_blank">`ujson`</a>.
!!! warning
`ujson` ๐ŸŒ˜ ๐Ÿ’› ๐ŸŒ˜ ๐Ÿ ๐Ÿ—-๐Ÿ› ๏ธ โ” โšซ๏ธ ๐Ÿต ๐Ÿ“-๐Ÿ’ผ.
```Python hl_lines="2 7"
{!../../../docs_src/custom_response/tutorial001.py!}
```
!!! tip
โšซ๏ธ ๐Ÿ’ช ๐Ÿ‘ˆ `ORJSONResponse` ๐Ÿ’ช โฉ ๐ŸŽ›.
### `RedirectResponse`
๐Ÿ“จ ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ” โŽ. โš™๏ธ 3๏ธโƒฃ0๏ธโƒฃ7๏ธโƒฃ ๐Ÿ‘” ๐Ÿ“Ÿ (๐Ÿ• โŽ) ๐Ÿ”ข.
๐Ÿ‘† ๐Ÿ’ช ๐Ÿ“จ `RedirectResponse` ๐Ÿ”—:
```Python hl_lines="2 9"
{!../../../docs_src/custom_response/tutorial006.py!}
```
---
โš–๏ธ ๐Ÿ‘† ๐Ÿ’ช โš™๏ธ โšซ๏ธ `response_class` ๐Ÿ”ข:
```Python hl_lines="2 7 9"
{!../../../docs_src/custom_response/tutorial006b.py!}
```
๐Ÿšฅ ๐Ÿ‘† ๐Ÿ‘ˆ, โคด๏ธ ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ“จ ๐Ÿ“› ๐Ÿ”— โšช๏ธโžก๏ธ ๐Ÿ‘† *โžก ๐Ÿ› ๏ธ* ๐Ÿ”ข.
๐Ÿ‘‰ ๐Ÿ’ผ, `status_code` โš™๏ธ ๐Ÿ”œ ๐Ÿ”ข 1๏ธโƒฃ `RedirectResponse`, โ” `307`.
---
๐Ÿ‘† ๐Ÿ’ช โš™๏ธ `status_code` ๐Ÿ”ข ๐ŸŒ€ โฎ๏ธ `response_class` ๐Ÿ”ข:
```Python hl_lines="2 7 9"
{!../../../docs_src/custom_response/tutorial006c.py!}
```
### `StreamingResponse`
โœŠ ๐Ÿ” ๐Ÿš‚ โš–๏ธ ๐Ÿ˜ ๐Ÿš‚/๐ŸŽป &amp; ๐ŸŽ ๐Ÿ“จ ๐Ÿ’ช.
```Python hl_lines="2 14"
{!../../../docs_src/custom_response/tutorial007.py!}
```
#### โš™๏ธ `StreamingResponse` โฎ๏ธ ๐Ÿ“-๐Ÿ’– ๐ŸŽš
๐Ÿšฅ ๐Ÿ‘† โœ”๏ธ ๐Ÿ“-๐Ÿ’– ๐ŸŽš (โœ… ๐ŸŽš ๐Ÿ“จ `open()`), ๐Ÿ‘† ๐Ÿ’ช โœ ๐Ÿš‚ ๐Ÿ”ข ๐Ÿ” ๐Ÿคญ ๐Ÿ‘ˆ ๐Ÿ“-๐Ÿ’– ๐ŸŽš.
๐Ÿ‘ˆ ๐ŸŒŒ, ๐Ÿ‘† ๐Ÿšซ โœ”๏ธ โœ โšซ๏ธ ๐ŸŒ ๐Ÿฅ‡ ๐Ÿ’พ, &amp; ๐Ÿ‘† ๐Ÿ’ช ๐Ÿšถโ€โ™€๏ธ ๐Ÿ‘ˆ ๐Ÿš‚ ๐Ÿ”ข `StreamingResponse`, &amp; ๐Ÿ“จ โšซ๏ธ.
๐Ÿ‘‰ ๐Ÿ”Œ ๐Ÿ“š ๐Ÿ—ƒ ๐Ÿ”— โฎ๏ธ โ˜ ๐Ÿ’พ, ๐Ÿ“น ๐Ÿญ, &amp; ๐ŸŽ.
```{ .python .annotate hl_lines="2 10-12 14" }
{!../../../docs_src/custom_response/tutorial008.py!}
```
1๏ธโƒฃ. ๐Ÿ‘‰ ๐Ÿš‚ ๐Ÿ”ข. โšซ๏ธ "๐Ÿš‚ ๐Ÿ”ข" โ†ฉ๏ธ โšซ๏ธ ๐Ÿ”Œ `yield` ๐Ÿ“„ ๐Ÿ”˜.
2๏ธโƒฃ. โš™๏ธ `with` ๐Ÿซ, ๐Ÿ‘ฅ โš’ ๐Ÿ’ญ ๐Ÿ‘ˆ ๐Ÿ“-๐Ÿ’– ๐ŸŽš ๐Ÿ“ช โฎ๏ธ ๐Ÿš‚ ๐Ÿ”ข ๐Ÿ”จ. , โฎ๏ธ โšซ๏ธ ๐Ÿ ๐Ÿ“จ ๐Ÿ“จ.
3๏ธโƒฃ. ๐Ÿ‘‰ `yield from` ๐Ÿ’ฌ ๐Ÿ”ข ๐Ÿ” ๐Ÿคญ ๐Ÿ‘ˆ ๐Ÿ‘œ ๐ŸŒŸ `file_like`. &amp; โคด๏ธ, ๐Ÿ”  ๐Ÿ• ๐Ÿ”, ๐ŸŒพ ๐Ÿ‘ˆ ๐Ÿ• ๐Ÿ‘Ÿ โšช๏ธโžก๏ธ ๐Ÿ‘‰ ๐Ÿš‚ ๐Ÿ”ข.
, โšซ๏ธ ๐Ÿš‚ ๐Ÿ”ข ๐Ÿ‘ˆ ๐Ÿ“จ "๐Ÿญ" ๐Ÿ‘ท ๐Ÿ•ณ ๐Ÿ™† ๐Ÿ”˜.
๐Ÿ”จ โšซ๏ธ ๐Ÿ‘‰ ๐ŸŒŒ, ๐Ÿ‘ฅ ๐Ÿ’ช ๐Ÿšฎ โšซ๏ธ `with` ๐Ÿซ, &amp; ๐Ÿ‘ˆ ๐ŸŒŒ, ๐Ÿšš ๐Ÿ‘ˆ โšซ๏ธ ๐Ÿ“ช โฎ๏ธ ๐Ÿ.
!!! tip
๐Ÿ‘€ ๐Ÿ‘ˆ ๐Ÿ“ฅ ๐Ÿ‘ฅ โš™๏ธ ๐Ÿฉ `open()` ๐Ÿ‘ˆ ๐Ÿšซ ๐Ÿ•โ€๐Ÿฆบ `async` &amp; `await`, ๐Ÿ‘ฅ ๐Ÿ“ฃ โžก ๐Ÿ› ๏ธ โฎ๏ธ ๐Ÿ˜ `def`.
### `FileResponse`
๐Ÿ” ๐ŸŽ ๐Ÿ“ ๐Ÿ“จ.
โœŠ ๐ŸŽ โš’ โŒ ๐Ÿ”— ๐ŸŒ˜ ๐ŸŽ ๐Ÿ“จ ๐Ÿ†Ž:
* `path` - ๐Ÿ“ ๐Ÿ“ ๐ŸŽ.
* `headers` - ๐Ÿ™† ๐Ÿ›ƒ ๐ŸŽš ๐Ÿ”Œ, ๐Ÿ“–.
* `media_type` - ๐ŸŽป ๐Ÿค ๐Ÿ“ป ๐Ÿ†Ž. ๐Ÿšฅ ๐Ÿ”ข, ๐Ÿ“ โš–๏ธ โžก ๐Ÿ”œ โš™๏ธ ๐Ÿ”‘ ๐Ÿ“ป ๐Ÿ†Ž.
* `filename` - ๐Ÿšฅ โš’, ๐Ÿ‘‰ ๐Ÿ”œ ๐Ÿ”Œ ๐Ÿ“จ `Content-Disposition`.
๐Ÿ“ ๐Ÿ“จ ๐Ÿ”œ ๐Ÿ”Œ โ˜‘ `Content-Length`, `Last-Modified` &amp; `ETag` ๐ŸŽš.
```Python hl_lines="2 10"
{!../../../docs_src/custom_response/tutorial009.py!}
```
๐Ÿ‘† ๐Ÿ’ช โš™๏ธ `response_class` ๐Ÿ”ข:
```Python hl_lines="2 8 10"
{!../../../docs_src/custom_response/tutorial009b.py!}
```
๐Ÿ‘‰ ๐Ÿ’ผ, ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ“จ ๐Ÿ“ โžก ๐Ÿ”— โšช๏ธโžก๏ธ ๐Ÿ‘† *โžก ๐Ÿ› ๏ธ* ๐Ÿ”ข.
## ๐Ÿ›ƒ ๐Ÿ“จ ๐ŸŽ“
๐Ÿ‘† ๐Ÿ’ช โœ ๐Ÿ‘† ๐Ÿ‘ ๐Ÿ›ƒ ๐Ÿ“จ ๐ŸŽ“, ๐Ÿ˜– โšช๏ธโžก๏ธ `Response` &amp; โš™๏ธ โšซ๏ธ.
๐Ÿ–ผ, โžก๏ธ ๐Ÿ’ฌ ๐Ÿ‘ˆ ๐Ÿ‘† ๐Ÿ’š โš™๏ธ <a href="https://github.com/ijl/orjson" class="external-link" target="_blank">`orjson`</a>, โœ‹๏ธ โฎ๏ธ ๐Ÿ›ƒ โš’ ๐Ÿšซ โš™๏ธ ๐Ÿ”Œ `ORJSONResponse` ๐ŸŽ“.
โžก๏ธ ๐Ÿ’ฌ ๐Ÿ‘† ๐Ÿ’š โšซ๏ธ ๐Ÿ“จ ๐Ÿ”‚ &amp; ๐Ÿ“ ๐ŸŽป, ๐Ÿ‘† ๐Ÿ’š โš™๏ธ Orjson ๐ŸŽ› `orjson.OPT_INDENT_2`.
๐Ÿ‘† ๐Ÿ’ช โœ `CustomORJSONResponse`. ๐Ÿ‘‘ ๐Ÿ‘œ ๐Ÿ‘† โœ”๏ธ โœ `Response.render(content)` ๐Ÿ‘ฉโ€๐Ÿ”ฌ ๐Ÿ‘ˆ ๐Ÿ“จ ๐ŸŽš `bytes`:
```Python hl_lines="9-14 17"
{!../../../docs_src/custom_response/tutorial009c.py!}
```
๐Ÿ”œ โ†ฉ๏ธ ๐Ÿ›ฌ:
```json
{"message": "Hello World"}
```
...๐Ÿ‘‰ ๐Ÿ“จ ๐Ÿ”œ ๐Ÿ“จ:
```json
{
"message": "Hello World"
}
```
โ†—๏ธ, ๐Ÿ‘† ๐Ÿ”œ ๐ŸŽฒ ๐Ÿ”Ž ๐ŸŒ… ๐Ÿ‘ ๐ŸŒŒ โœŠ ๐Ÿ“ˆ ๐Ÿ‘‰ ๐ŸŒ˜ โ• ๐ŸŽป. ๐Ÿ‘ถ
## ๐Ÿ”ข ๐Ÿ“จ ๐ŸŽ“
๐Ÿ•โ” ๐Ÿ— **FastAPI** ๐ŸŽ“ ๐Ÿ‘ โš–๏ธ `APIRouter` ๐Ÿ‘† ๐Ÿ’ช โœ” โ” ๐Ÿ“จ ๐ŸŽ“ โš™๏ธ ๐Ÿ”ข.
๐Ÿ”ข ๐Ÿ‘ˆ ๐Ÿ”ฌ ๐Ÿ‘‰ `default_response_class`.
๐Ÿ–ผ ๐Ÿ”›, **FastAPI** ๐Ÿ”œ โš™๏ธ `ORJSONResponse` ๐Ÿ”ข, ๐ŸŒ *โžก ๐Ÿ› ๏ธ*, โ†ฉ๏ธ `JSONResponse`.
```Python hl_lines="2 4"
{!../../../docs_src/custom_response/tutorial010.py!}
```
!!! tip
๐Ÿ‘† ๐Ÿ’ช ๐Ÿ” `response_class` *โžก ๐Ÿ› ๏ธ* โญ.
## ๐ŸŒ– ๐Ÿงพ
๐Ÿ‘† ๐Ÿ’ช ๐Ÿ“ฃ ๐Ÿ“ป ๐Ÿ†Ž &amp; ๐Ÿ“š ๐ŸŽ โ„น ๐Ÿ—„ โš™๏ธ `responses`: [๐ŸŒ– ๐Ÿ“จ ๐Ÿ—„](additional-responses.md){.internal-link target=_blank}.

98
docs/em/docs/advanced/dataclasses.md

@ -0,0 +1,98 @@
# โš™๏ธ ๐ŸŽป
FastAPI ๐Ÿ— ๐Ÿ”› ๐Ÿ” **Pydantic**, &amp; ๐Ÿ‘ค โœ”๏ธ ๐ŸŒ ๐Ÿ‘† โ” โš™๏ธ Pydantic ๐Ÿท ๐Ÿ“ฃ ๐Ÿ“จ &amp; ๐Ÿ“จ.
โœ‹๏ธ FastAPI ๐Ÿ•โ€๐Ÿฆบ โš™๏ธ <a href="https://docs.python.org/3/library/dataclasses.html" class="external-link" target="_blank">`dataclasses`</a> ๐ŸŽ ๐ŸŒŒ:
```Python hl_lines="1 7-12 19-20"
{!../../../docs_src/dataclasses/tutorial001.py!}
```
๐Ÿ‘‰ ๐Ÿ•โ€๐Ÿฆบ ๐Ÿ‘ **Pydantic**, โšซ๏ธ โœ”๏ธ <a href="https://pydantic-docs.helpmanual.io/usage/dataclasses/#use-of-stdlib-dataclasses-with-basemodel" class="external-link" target="_blank">๐Ÿ”— ๐Ÿ•โ€๐Ÿฆบ `dataclasses`</a>.
, โฎ๏ธ ๐Ÿ“Ÿ ๐Ÿ”› ๐Ÿ‘ˆ ๐Ÿšซ โš™๏ธ Pydantic ๐ŸŽฏ, FastAPI โš™๏ธ Pydantic ๐Ÿ—œ ๐Ÿ“š ๐Ÿฉ ๐ŸŽป Pydantic ๐Ÿ‘ ๐Ÿ› ๐ŸŽป.
&amp; โ†—๏ธ, โšซ๏ธ ๐Ÿ•โ€๐Ÿฆบ ๐ŸŽ:
* ๐Ÿ’ฝ ๐Ÿ”ฌ
* ๐Ÿ’ฝ ๐Ÿ› ๏ธ
* ๐Ÿ’ฝ ๐Ÿงพ, โ™’๏ธ.
๐Ÿ‘‰ ๐Ÿ‘ท ๐ŸŽ ๐ŸŒŒ โฎ๏ธ Pydantic ๐Ÿท. &amp; โšซ๏ธ ๐Ÿค™ ๐Ÿ† ๐ŸŽ ๐ŸŒŒ ๐Ÿ”˜, โš™๏ธ Pydantic.
!!! info
โœ”๏ธ ๐Ÿคฏ ๐Ÿ‘ˆ ๐ŸŽป ๐Ÿ’ช ๐Ÿšซ ๐ŸŒ Pydantic ๐Ÿท ๐Ÿ’ช.
, ๐Ÿ‘† 5๏ธโƒฃ๐Ÿ“† ๐Ÿ’ช โš™๏ธ Pydantic ๐Ÿท.
โœ‹๏ธ ๐Ÿšฅ ๐Ÿ‘† โœ”๏ธ ๐Ÿ“š ๐ŸŽป ๐Ÿคฅ ๐Ÿคญ, ๐Ÿ‘‰ ๐Ÿ‘Œ ๐ŸŽฑ โš™๏ธ ๐Ÿ‘ซ ๐Ÿ‹๏ธ ๐Ÿ•ธ ๐Ÿ› ๏ธ โš™๏ธ FastAPI. ๐Ÿ‘ถ
## ๐ŸŽป `response_model`
๐Ÿ‘† ๐Ÿ’ช โš™๏ธ `dataclasses` `response_model` ๐Ÿ”ข:
```Python hl_lines="1 7-13 19"
{!../../../docs_src/dataclasses/tutorial002.py!}
```
๐ŸŽป ๐Ÿ”œ ๐Ÿ” ๐Ÿ—œ Pydantic ๐ŸŽป.
๐Ÿ‘‰ ๐ŸŒŒ, ๐Ÿšฎ ๐Ÿ”— ๐Ÿ”œ ๐ŸŽฆ ๐Ÿ†™ ๐Ÿ› ๏ธ ๐Ÿฉบ ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ”ข:
<img src="/img/tutorial/dataclasses/image01.png">
## ๐ŸŽป ๐Ÿ” ๐Ÿ“Š ๐Ÿ“Š
๐Ÿ‘† ๐Ÿ’ช ๐ŸŒ€ `dataclasses` โฎ๏ธ ๐ŸŽ ๐Ÿ†Ž โœ โš’ ๐Ÿฆ ๐Ÿ“Š ๐Ÿ“Š.
๐Ÿ’ผ, ๐Ÿ‘† ๐Ÿ’ช โœ”๏ธ โš™๏ธ Pydantic โฌ `dataclasses`. ๐Ÿ–ผ, ๐Ÿšฅ ๐Ÿ‘† โœ”๏ธ โŒ โฎ๏ธ ๐Ÿ” ๐Ÿ— ๐Ÿ› ๏ธ ๐Ÿงพ.
๐Ÿ‘ˆ ๐Ÿ’ผ, ๐Ÿ‘† ๐Ÿ’ช ๐ŸŽฏ ๐Ÿ’ฑ ๐Ÿฉ `dataclasses` โฎ๏ธ `pydantic.dataclasses`, โ” ๐Ÿ’ง-โ™ป:
```{ .python .annotate hl_lines="1 5 8-11 14-17 23-25 28" }
{!../../../docs_src/dataclasses/tutorial003.py!}
```
1๏ธโƒฃ. ๐Ÿ‘ฅ ๐Ÿ—„ `field` โšช๏ธโžก๏ธ ๐Ÿฉ `dataclasses`.
2๏ธโƒฃ. `pydantic.dataclasses` ๐Ÿ’ง-โ™ป `dataclasses`.
3๏ธโƒฃ. `Author` ๐ŸŽป ๐Ÿ”Œ ๐Ÿ“‡ `Item` ๐ŸŽป.
4๏ธโƒฃ. `Author` ๐ŸŽป โš™๏ธ `response_model` ๐Ÿ”ข.
5๏ธโƒฃ. ๐Ÿ‘† ๐Ÿ’ช โš™๏ธ ๐ŸŽ ๐Ÿฉ ๐Ÿ†Ž โœ โฎ๏ธ ๐ŸŽป ๐Ÿ“จ ๐Ÿ’ช.
๐Ÿ‘‰ ๐Ÿ’ผ, โšซ๏ธ ๐Ÿ“‡ `Item` ๐ŸŽป.
6๏ธโƒฃ. ๐Ÿ“ฅ ๐Ÿ‘ฅ ๐Ÿ›ฌ ๐Ÿ“– ๐Ÿ‘ˆ ๐Ÿ”Œ `items` โ” ๐Ÿ“‡ ๐ŸŽป.
FastAPI ๐ŸŽฏ <abbr title="converting the data to a format that can be transmitted">โœ</abbr> ๐Ÿ’ฝ ๐ŸŽป.
7๏ธโƒฃ. ๐Ÿ“ฅ `response_model` โš™๏ธ ๐Ÿ†Ž โœ ๐Ÿ“‡ `Author` ๐ŸŽป.
๐Ÿ”„, ๐Ÿ‘† ๐Ÿ’ช ๐ŸŒ€ `dataclasses` โฎ๏ธ ๐Ÿฉ ๐Ÿ†Ž โœ.
8๏ธโƒฃ. ๐Ÿ‘€ ๐Ÿ‘ˆ ๐Ÿ‘‰ *โžก ๐Ÿ› ๏ธ ๐Ÿ”ข* โš™๏ธ ๐Ÿฅ” `def` โ†ฉ๏ธ `async def`.
๐Ÿ•ง, FastAPI ๐Ÿ‘† ๐Ÿ’ช ๐ŸŒ€ `def` &amp; `async def` ๐Ÿ’ช.
๐Ÿšฅ ๐Ÿ‘† ๐Ÿ’ช โ†—๏ธ ๐Ÿ”ƒ ๐Ÿ•โ” โš™๏ธ โ”, โœ… ๐Ÿ‘… ๐Ÿ“„ _"๐Ÿƒ โ“" _ ๐Ÿฉบ ๐Ÿ”ƒ <a href="https://fastapi.tiangolo.com/async/#in-a-hurry" target="_blank" class="internal-link">`async` &amp; `await`</a>.
9๏ธโƒฃ. ๐Ÿ‘‰ *โžก ๐Ÿ› ๏ธ ๐Ÿ”ข* ๐Ÿšซ ๐Ÿ›ฌ ๐ŸŽป (๐Ÿ‘ โšซ๏ธ ๐Ÿ’ช), โœ‹๏ธ ๐Ÿ“‡ ๐Ÿ“– โฎ๏ธ ๐Ÿ”— ๐Ÿ’ฝ.
FastAPI ๐Ÿ”œ โš™๏ธ `response_model` ๐Ÿ”ข (๐Ÿ‘ˆ ๐Ÿ”Œ ๐ŸŽป) ๐Ÿ—œ ๐Ÿ“จ.
๐Ÿ‘† ๐Ÿ’ช ๐ŸŒ€ `dataclasses` โฎ๏ธ ๐ŸŽ ๐Ÿ†Ž โœ ๐Ÿ“š ๐ŸŽ ๐ŸŒ€ ๐Ÿ“จ ๐Ÿ— ๐Ÿ“Š ๐Ÿ“Š.
โœ…-๐Ÿ“Ÿ โœ ๐Ÿ’โ€โ™‚ ๐Ÿ”› ๐Ÿ‘€ ๐ŸŒ… ๐ŸŽฏ โ„น.
## ๐Ÿ’ก ๐ŸŒ…
๐Ÿ‘† ๐Ÿ’ช ๐ŸŒ€ `dataclasses` โฎ๏ธ ๐ŸŽ Pydantic ๐Ÿท, ๐Ÿ˜– โšช๏ธโžก๏ธ ๐Ÿ‘ซ, ๐Ÿ”Œ ๐Ÿ‘ซ ๐Ÿ‘† ๐Ÿ‘ ๐Ÿท, โ™’๏ธ.
๐Ÿ’ก ๐ŸŒ…, โœ… <a href="https://pydantic-docs.helpmanual.io/usage/dataclasses/" class="external-link" target="_blank">Pydantic ๐Ÿฉบ ๐Ÿ”ƒ ๐ŸŽป</a>.
## โฌ
๐Ÿ‘‰ ๐Ÿ’ช โ†ฉ๏ธ FastAPI โฌ `0.67.0`. ๐Ÿ‘ถ

160
docs/em/docs/advanced/events.md

@ -0,0 +1,160 @@
# ๐Ÿ”† ๐ŸŽ‰
๐Ÿ‘† ๐Ÿ’ช ๐Ÿ”ฌ โš› (๐Ÿ“Ÿ) ๐Ÿ‘ˆ ๐Ÿ”œ ๐Ÿ› ๏ธ โญ ๐Ÿˆธ **โ–ถ๏ธ ๐Ÿ†™**. ๐Ÿ‘‰ โ›“ ๐Ÿ‘ˆ ๐Ÿ‘‰ ๐Ÿ“Ÿ ๐Ÿ”œ ๐Ÿ› ๏ธ **๐Ÿ•**, **โญ** ๐Ÿˆธ **โ–ถ๏ธ ๐Ÿ“จ ๐Ÿ“จ**.
๐ŸŽ ๐ŸŒŒ, ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ”ฌ โš› (๐Ÿ“Ÿ) ๐Ÿ‘ˆ ๐Ÿ”œ ๐Ÿ› ๏ธ ๐Ÿ•โ” ๐Ÿˆธ **๐Ÿคซ ๐Ÿ”ฝ**. ๐Ÿ‘‰ ๐Ÿ’ผ, ๐Ÿ‘‰ ๐Ÿ“Ÿ ๐Ÿ”œ ๐Ÿ› ๏ธ **๐Ÿ•**, **โฎ๏ธ** โœ”๏ธ ๐Ÿต ๐ŸŽฒ **๐Ÿ“š ๐Ÿ“จ**.
โ†ฉ๏ธ ๐Ÿ‘‰ ๐Ÿ“Ÿ ๐Ÿ› ๏ธ โญ ๐Ÿˆธ **โ–ถ๏ธ** โœŠ ๐Ÿ“จ, &amp; โ–ถ๏ธ๏ธ โฎ๏ธ โšซ๏ธ **๐Ÿ** ๐Ÿšš ๐Ÿ“จ, โšซ๏ธ ๐Ÿ“” ๐ŸŽ‚ ๐Ÿˆธ **๐Ÿ”†** (๐Ÿ”ค "๐Ÿ”†" ๐Ÿ”œ โš  ๐Ÿฅˆ ๐Ÿ‘ถ).
๐Ÿ‘‰ ๐Ÿ’ช ๐Ÿ“ถ โš  โš’ ๐Ÿ†™ **โ„น** ๐Ÿ‘ˆ ๐Ÿ‘† ๐Ÿ’ช โš™๏ธ ๐ŸŽ‚ ๐Ÿ“ฑ, &amp; ๐Ÿ‘ˆ **๐Ÿ’ฐ** ๐Ÿ‘ช ๐Ÿ“จ, &amp;/โš–๏ธ ๐Ÿ‘ˆ ๐Ÿ‘† ๐Ÿ’ช **๐Ÿงน ๐Ÿ†™** โฎ๏ธ. ๐Ÿ–ผ, ๐Ÿ’ฝ ๐Ÿ”— ๐ŸŽฑ, โš–๏ธ ๐Ÿšš ๐Ÿ”— ๐ŸŽฐ ๐Ÿซ ๐Ÿท.
## โš™๏ธ ๐Ÿ’ผ
โžก๏ธ โ–ถ๏ธ โฎ๏ธ ๐Ÿ–ผ **โš™๏ธ ๐Ÿ’ผ** &amp; โคด๏ธ ๐Ÿ‘€ โ” โŽ โšซ๏ธ โฎ๏ธ ๐Ÿ‘‰.
โžก๏ธ ๐ŸŒˆ ๐Ÿ‘ˆ ๐Ÿ‘† โœ”๏ธ **๐ŸŽฐ ๐Ÿซ ๐Ÿท** ๐Ÿ‘ˆ ๐Ÿ‘† ๐Ÿ’š โš™๏ธ ๐Ÿต ๐Ÿ“จ. ๐Ÿ‘ถ
๐ŸŽ ๐Ÿท ๐Ÿ”— ๐Ÿ‘ช ๐Ÿ“จ,, โšซ๏ธ ๐Ÿšซ 1๏ธโƒฃ ๐Ÿท ๐Ÿ“ ๐Ÿ“จ, โš–๏ธ 1๏ธโƒฃ ๐Ÿ“ ๐Ÿ‘ฉโ€๐Ÿ’ป โš–๏ธ ๐Ÿ•ณ ๐ŸŽ.
โžก๏ธ ๐ŸŒˆ ๐Ÿ‘ˆ ๐Ÿšš ๐Ÿท ๐Ÿ’ช **โœŠ ๐Ÿ•ฐ**, โ†ฉ๏ธ โšซ๏ธ โœ”๏ธ โœ ๐Ÿ“š **๐Ÿ’ฝ โšช๏ธโžก๏ธ ๐Ÿ’พ**. ๐Ÿ‘† ๐Ÿšซ ๐Ÿ’š โšซ๏ธ ๐Ÿ”  ๐Ÿ“จ.
๐Ÿ‘† ๐Ÿ’ช ๐Ÿ“ โšซ๏ธ ๐Ÿ” ๐ŸŽš ๐Ÿ•น/๐Ÿ“, โœ‹๏ธ ๐Ÿ‘ˆ ๐Ÿ”œ โ›“ ๐Ÿ‘ˆ โšซ๏ธ ๐Ÿ”œ **๐Ÿ“ ๐Ÿท** ๐Ÿšฅ ๐Ÿ‘† ๐Ÿƒโ€โ™‚ ๐Ÿ™… ๐Ÿง ๐Ÿ’ฏ, โคด๏ธ ๐Ÿ‘ˆ ๐Ÿ’ฏ ๐Ÿ”œ **๐ŸŒ** โ†ฉ๏ธ โšซ๏ธ ๐Ÿ”œ โœ”๏ธ โŒ› ๐Ÿท ๐Ÿ“ โญ ๐Ÿ’†โ€โ™‚ ๐Ÿ’ช ๐Ÿƒ ๐Ÿ”ฌ ๐Ÿ• ๐Ÿ“Ÿ.
๐Ÿ‘ˆ โšซ๏ธโ” ๐Ÿ‘ฅ ๐Ÿ”œ โŽ, โžก๏ธ ๐Ÿ“ ๐Ÿท โญ ๐Ÿ“จ ๐Ÿต, โœ‹๏ธ ๐Ÿ•ด โ–ถ๏ธ๏ธ โญ ๐Ÿˆธ โ–ถ๏ธ ๐Ÿ“จ ๐Ÿ“จ, ๐Ÿšซ โช ๐Ÿ“Ÿ โž– ๐Ÿ“.
## ๐Ÿ”†
๐Ÿ‘† ๐Ÿ’ช ๐Ÿ”ฌ ๐Ÿ‘‰ *๐Ÿ•ด* &amp; *๐Ÿคซ* โš› โš™๏ธ `lifespan` ๐Ÿ”ข `FastAPI` ๐Ÿ“ฑ, &amp; "๐Ÿ”‘ ๐Ÿ‘จโ€๐Ÿ’ผ" (๐Ÿ‘ค ๐Ÿ”œ ๐ŸŽฆ ๐Ÿ‘† โšซ๏ธโ” ๐Ÿ‘ˆ ๐Ÿฅˆ).
โžก๏ธ โ–ถ๏ธ โฎ๏ธ ๐Ÿ–ผ &amp; โคด๏ธ ๐Ÿ‘€ โšซ๏ธ โ„น.
๐Ÿ‘ฅ โœ ๐Ÿ” ๐Ÿ”ข `lifespan()` โฎ๏ธ `yield` ๐Ÿ’– ๐Ÿ‘‰:
```Python hl_lines="16 19"
{!../../../docs_src/events/tutorial003.py!}
```
๐Ÿ“ฅ ๐Ÿ‘ฅ โš– ๐Ÿ˜ฅ *๐Ÿ•ด* ๐Ÿ› ๏ธ ๐Ÿšš ๐Ÿท ๐Ÿšฎ (โŒ) ๐Ÿท ๐Ÿ”ข ๐Ÿ“– โฎ๏ธ ๐ŸŽฐ ๐Ÿซ ๐Ÿท โญ `yield`. ๐Ÿ‘‰ ๐Ÿ“Ÿ ๐Ÿ”œ ๐Ÿ› ๏ธ **โญ** ๐Ÿˆธ **โ–ถ๏ธ โœŠ ๐Ÿ“จ**, โฎ๏ธ *๐Ÿ•ด*.
&amp; โคด๏ธ, โ–ถ๏ธ๏ธ โฎ๏ธ `yield`, ๐Ÿ‘ฅ ๐Ÿšš ๐Ÿท. ๐Ÿ‘‰ ๐Ÿ“Ÿ ๐Ÿ”œ ๐Ÿ› ๏ธ **โฎ๏ธ** ๐Ÿˆธ **๐Ÿ ๐Ÿšš ๐Ÿ“จ**, โ–ถ๏ธ๏ธ โญ *๐Ÿคซ*. ๐Ÿ‘‰ ๐Ÿ’ช, ๐Ÿ–ผ, ๐Ÿš€ โ„น ๐Ÿ’– ๐Ÿ’พ โš–๏ธ ๐Ÿ’ป.
!!! tip
`shutdown` ๐Ÿ”œ ๐Ÿ”จ ๐Ÿ•โ” ๐Ÿ‘† **โ›”๏ธ** ๐Ÿˆธ.
๐ŸŽฒ ๐Ÿ‘† ๐Ÿ’ช โ–ถ๏ธ ๐Ÿ†• โฌ, โš–๏ธ ๐Ÿ‘† ๐Ÿคš ๐ŸŽก ๐Ÿƒ โšซ๏ธ. ๐Ÿคท
### ๐Ÿ”† ๐Ÿ”ข
๐Ÿฅ‡ ๐Ÿ‘œ ๐Ÿ‘€, ๐Ÿ‘ˆ ๐Ÿ‘ฅ โš– ๐Ÿ” ๐Ÿ”ข โฎ๏ธ `yield`. ๐Ÿ‘‰ ๐Ÿ“ถ ๐ŸŽ ๐Ÿ”— โฎ๏ธ `yield`.
```Python hl_lines="14-19"
{!../../../docs_src/events/tutorial003.py!}
```
๐Ÿฅ‡ ๐Ÿ• ๐Ÿ”ข, โญ `yield`, ๐Ÿ”œ ๐Ÿ› ๏ธ **โญ** ๐Ÿˆธ โ–ถ๏ธ.
&amp; ๐Ÿ• โฎ๏ธ `yield` ๐Ÿ”œ ๐Ÿ› ๏ธ **โฎ๏ธ** ๐Ÿˆธ โœ”๏ธ ๐Ÿ.
### ๐Ÿ” ๐Ÿ”‘ ๐Ÿ‘จโ€๐Ÿ’ผ
๐Ÿšฅ ๐Ÿ‘† โœ…, ๐Ÿ”ข ๐ŸŽ€ โฎ๏ธ `@asynccontextmanager`.
๐Ÿ‘ˆ ๐Ÿ—œ ๐Ÿ”ข ๐Ÿ”˜ ๐Ÿ•ณ ๐Ÿค™ "**๐Ÿ” ๐Ÿ”‘ ๐Ÿ‘จโ€๐Ÿ’ผ**".
```Python hl_lines="1 13"
{!../../../docs_src/events/tutorial003.py!}
```
**๐Ÿ”‘ ๐Ÿ‘จโ€๐Ÿ’ผ** ๐Ÿ ๐Ÿ•ณ ๐Ÿ‘ˆ ๐Ÿ‘† ๐Ÿ’ช โš™๏ธ `with` ๐Ÿ“„, ๐Ÿ–ผ, `open()` ๐Ÿ’ช โš™๏ธ ๐Ÿ”‘ ๐Ÿ‘จโ€๐Ÿ’ผ:
```Python
with open("file.txt") as file:
file.read()
```
โฎ๏ธ โฌ ๐Ÿ, ๐Ÿ“ค **๐Ÿ” ๐Ÿ”‘ ๐Ÿ‘จโ€๐Ÿ’ผ**. ๐Ÿ‘† ๐Ÿ”œ โš™๏ธ โšซ๏ธ โฎ๏ธ `async with`:
```Python
async with lifespan(app):
await do_stuff()
```
๐Ÿ•โ” ๐Ÿ‘† โœ ๐Ÿ”‘ ๐Ÿ‘จโ€๐Ÿ’ผ โš–๏ธ ๐Ÿ” ๐Ÿ”‘ ๐Ÿ‘จโ€๐Ÿ’ผ ๐Ÿ’– ๐Ÿ”›, โšซ๏ธโ” โšซ๏ธ ๐Ÿ”จ ๐Ÿ‘ˆ, โญ ๐Ÿ›ฌ `with` ๐Ÿซ, โšซ๏ธ ๐Ÿ”œ ๐Ÿ› ๏ธ ๐Ÿ“Ÿ โญ `yield`, &amp; โฎ๏ธ โŽ `with` ๐Ÿซ, โšซ๏ธ ๐Ÿ”œ ๐Ÿ› ๏ธ ๐Ÿ“Ÿ โฎ๏ธ `yield`.
๐Ÿ‘† ๐Ÿ“Ÿ ๐Ÿ–ผ ๐Ÿ”›, ๐Ÿ‘ฅ ๐Ÿšซ โš™๏ธ โšซ๏ธ ๐Ÿ”—, โœ‹๏ธ ๐Ÿ‘ฅ ๐Ÿšถโ€โ™€๏ธ โšซ๏ธ FastAPI โšซ๏ธ โš™๏ธ โšซ๏ธ.
`lifespan` ๐Ÿ”ข `FastAPI` ๐Ÿ“ฑ โœŠ **๐Ÿ” ๐Ÿ”‘ ๐Ÿ‘จโ€๐Ÿ’ผ**, ๐Ÿ‘ฅ ๐Ÿ’ช ๐Ÿšถโ€โ™€๏ธ ๐Ÿ‘† ๐Ÿ†• `lifespan` ๐Ÿ” ๐Ÿ”‘ ๐Ÿ‘จโ€๐Ÿ’ผ โšซ๏ธ.
```Python hl_lines="22"
{!../../../docs_src/events/tutorial003.py!}
```
## ๐ŸŽ› ๐ŸŽ‰ (๐Ÿ˜ข)
!!! warning
๐Ÿ‘ ๐ŸŒŒ ๐Ÿต *๐Ÿ•ด* &amp; *๐Ÿคซ* โš™๏ธ `lifespan` ๐Ÿ”ข `FastAPI` ๐Ÿ“ฑ ๐Ÿ”ฌ ๐Ÿ”›.
๐Ÿ‘† ๐Ÿ’ช ๐ŸŽฒ ๐Ÿšถ ๐Ÿ‘‰ ๐Ÿ•.
๐Ÿ“ค ๐ŸŽ› ๐ŸŒŒ ๐Ÿ”ฌ ๐Ÿ‘‰ โš› ๐Ÿ› ๏ธ โฎ๏ธ *๐Ÿ•ด* &amp; โฎ๏ธ *๐Ÿคซ*.
๐Ÿ‘† ๐Ÿ’ช ๐Ÿ”ฌ ๐ŸŽ‰ ๐Ÿ•โ€๐Ÿฆบ (๐Ÿ”ข) ๐Ÿ‘ˆ ๐Ÿ’ช ๐Ÿ› ๏ธ โญ ๐Ÿˆธ โ–ถ๏ธ ๐Ÿ†™, โš–๏ธ ๐Ÿ•โ” ๐Ÿˆธ ๐Ÿคซ ๐Ÿ”ฝ.
๐Ÿ‘ซ ๐Ÿ”ข ๐Ÿ’ช ๐Ÿ“ฃ โฎ๏ธ `async def` โš–๏ธ ๐Ÿ˜ `def`.
### `startup` ๐ŸŽ‰
๐Ÿšฎ ๐Ÿ”ข ๐Ÿ‘ˆ ๐Ÿ”œ ๐Ÿƒ โญ ๐Ÿˆธ โ–ถ๏ธ, ๐Ÿ“ฃ โšซ๏ธ โฎ๏ธ ๐ŸŽ‰ `"startup"`:
```Python hl_lines="8"
{!../../../docs_src/events/tutorial001.py!}
```
๐Ÿ‘‰ ๐Ÿ’ผ, `startup` ๐ŸŽ‰ ๐Ÿ•โ€๐Ÿฆบ ๐Ÿ”ข ๐Ÿ”œ ๐Ÿ”ข ๐Ÿฌ "๐Ÿ’ฝ" ( `dict`) โฎ๏ธ ๐Ÿ’ฒ.
๐Ÿ‘† ๐Ÿ’ช ๐Ÿšฎ ๐ŸŒ… ๐ŸŒ˜ 1๏ธโƒฃ ๐ŸŽ‰ ๐Ÿ•โ€๐Ÿฆบ ๐Ÿ”ข.
&amp; ๐Ÿ‘† ๐Ÿˆธ ๐Ÿ† ๐Ÿšซ โ–ถ๏ธ ๐Ÿ“จ ๐Ÿ“จ โญ ๐ŸŒ `startup` ๐ŸŽ‰ ๐Ÿ•โ€๐Ÿฆบ โœ”๏ธ ๐Ÿ.
### `shutdown` ๐ŸŽ‰
๐Ÿšฎ ๐Ÿ”ข ๐Ÿ‘ˆ ๐Ÿ”œ ๐Ÿƒ ๐Ÿ•โ” ๐Ÿˆธ ๐Ÿคซ ๐Ÿ”ฝ, ๐Ÿ“ฃ โšซ๏ธ โฎ๏ธ ๐ŸŽ‰ `"shutdown"`:
```Python hl_lines="6"
{!../../../docs_src/events/tutorial002.py!}
```
๐Ÿ“ฅ, `shutdown` ๐ŸŽ‰ ๐Ÿ•โ€๐Ÿฆบ ๐Ÿ”ข ๐Ÿ”œ โœ โœ โธ `"Application shutdown"` ๐Ÿ“ `log.txt`.
!!! info
`open()` ๐Ÿ”ข, `mode="a"` โ›“ "๐ŸŽป",, โธ ๐Ÿ”œ ๐Ÿšฎ โฎ๏ธ โšซ๏ธโ” ๐Ÿ”› ๐Ÿ‘ˆ ๐Ÿ“, ๐Ÿต ๐Ÿ“ โฎ๏ธ ๐ŸŽš.
!!! tip
๐Ÿ‘€ ๐Ÿ‘ˆ ๐Ÿ‘‰ ๐Ÿ’ผ ๐Ÿ‘ฅ โš™๏ธ ๐Ÿฉ ๐Ÿ `open()` ๐Ÿ”ข ๐Ÿ‘ˆ ๐Ÿ”— โฎ๏ธ ๐Ÿ“.
, โšซ๏ธ ๐Ÿ”Œ ๐Ÿ‘ค/๐Ÿ…พ (๐Ÿ”ข/๐Ÿ”ข), ๐Ÿ‘ˆ ๐Ÿšš "โŒ›" ๐Ÿ‘œ โœ ๐Ÿ’พ.
โœ‹๏ธ `open()` ๐Ÿšซ โš™๏ธ `async` &amp; `await`.
, ๐Ÿ‘ฅ ๐Ÿ“ฃ ๐ŸŽ‰ ๐Ÿ•โ€๐Ÿฆบ ๐Ÿ”ข โฎ๏ธ ๐Ÿฉ `def` โ†ฉ๏ธ `async def`.
!!! info
๐Ÿ‘† ๐Ÿ’ช โœ ๐ŸŒ… ๐Ÿ”ƒ ๐Ÿ‘ซ ๐ŸŽ‰ ๐Ÿ•โ€๐Ÿฆบ <a href="https://www.starlette.io/events/" class="external-link" target="_blank">๐Ÿ’ƒ ๐ŸŽ‰' ๐Ÿฉบ</a>.
### `startup` &amp; `shutdown` ๐Ÿ‘ฏโ€โ™‚๏ธ
๐Ÿ“ค โ†• ๐Ÿคž ๐Ÿ‘ˆ โš› ๐Ÿ‘† *๐Ÿ•ด* &amp; *๐Ÿคซ* ๐Ÿ”—, ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ’š โ–ถ๏ธ ๐Ÿ•ณ &amp; โคด๏ธ ๐Ÿ โšซ๏ธ, ๐Ÿ“Ž โ„น &amp; โคด๏ธ ๐Ÿš€ โšซ๏ธ, โ™’๏ธ.
๐Ÿ”จ ๐Ÿ‘ˆ ๐Ÿ‘ฝ ๐Ÿ”ข ๐Ÿ‘ˆ ๐Ÿšซ ๐Ÿ’ฐ โš› โš–๏ธ ๐Ÿ”ข ๐Ÿ‘ฏโ€โ™‚๏ธ ๐ŸŒ… โš  ๐Ÿ‘† ๐Ÿ”œ ๐Ÿ’ช ๐Ÿช ๐Ÿ’ฒ ๐ŸŒ ๐Ÿ”ข โš–๏ธ ๐ŸŽ ๐ŸŽฑ.
โ†ฉ๏ธ ๐Ÿ‘ˆ, โšซ๏ธ ๐Ÿ”œ ๐Ÿ‘ โ†ฉ๏ธ โš™๏ธ `lifespan` ๐Ÿ”ฌ ๐Ÿ”›.
## ๐Ÿ“ก โ„น
๐Ÿ“ก โ„น ๐Ÿ˜Ÿ ๐Ÿค“. ๐Ÿ‘ถ
๐Ÿ”˜, ๐Ÿ”ซ ๐Ÿ“ก ๐Ÿ”ง, ๐Ÿ‘‰ ๐Ÿ• <a href="https://asgi.readthedocs.io/en/latest/specs/lifespan.html" class="external-link" target="_blank">๐Ÿ”† ๐Ÿ› ๏ธ</a>, &amp; โšซ๏ธ ๐Ÿ”ฌ ๐ŸŽ‰ ๐Ÿค™ `startup` &amp; `shutdown`.
## ๐ŸŽง ๐Ÿˆธ
๐Ÿ‘ถ โœ”๏ธ ๐Ÿคฏ ๐Ÿ‘ˆ ๐Ÿ‘ซ ๐Ÿ”† ๐ŸŽ‰ (๐Ÿ•ด &amp; ๐Ÿคซ) ๐Ÿ”œ ๐Ÿ•ด ๐Ÿ› ๏ธ ๐Ÿ‘‘ ๐Ÿˆธ, ๐Ÿšซ [๐ŸŽง ๐Ÿˆธ - ๐Ÿ—ป](./sub-applications.md){.internal-link target=_blank}.

314
docs/em/docs/advanced/extending-openapi.md

@ -0,0 +1,314 @@
# โ†” ๐Ÿ—„
!!! warning
๐Ÿ‘‰ ๐Ÿ‘ ๐Ÿง โš’. ๐Ÿ‘† ๐ŸŽฒ ๐Ÿ’ช ๐Ÿšถ โšซ๏ธ.
๐Ÿšฅ ๐Ÿ‘† ๐Ÿ“„ ๐Ÿ”ฐ - ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿฆฎ, ๐Ÿ‘† ๐Ÿ’ช ๐ŸŽฒ ๐Ÿšถ ๐Ÿ‘‰ ๐Ÿ“„.
๐Ÿšฅ ๐Ÿ‘† โช ๐Ÿ’ญ ๐Ÿ‘ˆ ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ”€ ๐Ÿ— ๐Ÿ—„ ๐Ÿ”—, ๐Ÿ˜ฃ ๐Ÿ‘‚.
๐Ÿ“ค ๐Ÿ’ผ ๐ŸŒโ” ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ’ช ๐Ÿ”€ ๐Ÿ— ๐Ÿ—„ ๐Ÿ”—.
๐Ÿ‘‰ ๐Ÿ“„ ๐Ÿ‘† ๐Ÿ”œ ๐Ÿ‘€ โ”.
## ๐Ÿ˜ ๐Ÿ› ๏ธ
๐Ÿ˜ (๐Ÿ”ข) ๐Ÿ› ๏ธ, โฉ.
`FastAPI` ๐Ÿˆธ (๐Ÿ‘) โœ”๏ธ `.openapi()` ๐Ÿ‘ฉโ€๐Ÿ”ฌ ๐Ÿ‘ˆ ๐Ÿ“ˆ ๐Ÿ“จ ๐Ÿ—„ ๐Ÿ”—.
๐Ÿ• ๐Ÿˆธ ๐ŸŽš ๐Ÿ—, *โžก ๐Ÿ› ๏ธ* `/openapi.json` (โš–๏ธ โšซ๏ธโ” ๐Ÿ‘† โš’ ๐Ÿ‘† `openapi_url`) ยฎ.
โšซ๏ธ ๐Ÿ“จ ๐ŸŽป ๐Ÿ“จ โฎ๏ธ ๐Ÿ ๐Ÿˆธ `.openapi()` ๐Ÿ‘ฉโ€๐Ÿ”ฌ.
๐Ÿ”ข, โšซ๏ธโ” ๐Ÿ‘ฉโ€๐Ÿ”ฌ `.openapi()` ๐Ÿ”จ โœ… ๐Ÿ  `.openapi_schema` ๐Ÿ‘€ ๐Ÿšฅ โšซ๏ธ โœ”๏ธ ๐ŸŽš &amp; ๐Ÿ“จ ๐Ÿ‘ซ.
๐Ÿšฅ โšซ๏ธ ๐Ÿšซ, โšซ๏ธ ๐Ÿ— ๐Ÿ‘ซ โš™๏ธ ๐Ÿš™ ๐Ÿ”ข `fastapi.openapi.utils.get_openapi`.
&amp; ๐Ÿ‘ˆ ๐Ÿ”ข `get_openapi()` ๐Ÿ“จ ๐Ÿ”ข:
* `title`: ๐Ÿ—„ ๐Ÿ“›, ๐ŸŽฆ ๐Ÿฉบ.
* `version`: โฌ ๐Ÿ‘† ๐Ÿ› ๏ธ, โœ… `2.5.0`.
* `openapi_version`: โฌ ๐Ÿ—„ ๐Ÿ”ง โš™๏ธ. ๐Ÿ”ข, โช: `3.0.2`.
* `description`: ๐Ÿ“› ๐Ÿ‘† ๐Ÿ› ๏ธ.
* `routes`: ๐Ÿ“‡ ๐Ÿ›ฃ, ๐Ÿ‘ซ ๐Ÿ”  ยฎ *โžก ๐Ÿ› ๏ธ*. ๐Ÿ‘ซ โœŠ โšช๏ธโžก๏ธ `app.routes`.
## ๐Ÿ”‘ ๐Ÿ”ข
โš™๏ธ โ„น ๐Ÿ”›, ๐Ÿ‘† ๐Ÿ’ช โš™๏ธ ๐ŸŽ ๐Ÿš™ ๐Ÿ”ข ๐Ÿ— ๐Ÿ—„ ๐Ÿ”— &amp; ๐Ÿ” ๐Ÿ”  ๐Ÿ• ๐Ÿ‘ˆ ๐Ÿ‘† ๐Ÿ’ช.
๐Ÿ–ผ, โžก๏ธ ๐Ÿšฎ <a href="https://github.com/Rebilly/ReDoc/blob/master/docs/redoc-vendor-extensions.md#x-logo" class="external-link" target="_blank">๐Ÿ“„ ๐Ÿ—„ โ†” ๐Ÿ”Œ ๐Ÿ›ƒ ๐Ÿ”ฑ</a>.
### ๐Ÿ˜ **FastAPI**
๐Ÿฅ‡, โœ ๐ŸŒ ๐Ÿ‘† **FastAPI** ๐Ÿˆธ ๐Ÿ›Ž:
```Python hl_lines="1 4 7-9"
{!../../../docs_src/extending_openapi/tutorial001.py!}
```
### ๐Ÿ— ๐Ÿ—„ ๐Ÿ”—
โคด๏ธ, โš™๏ธ ๐ŸŽ ๐Ÿš™ ๐Ÿ”ข ๐Ÿ— ๐Ÿ—„ ๐Ÿ”—, ๐Ÿ”˜ `custom_openapi()` ๐Ÿ”ข:
```Python hl_lines="2 15-20"
{!../../../docs_src/extending_openapi/tutorial001.py!}
```
### ๐Ÿ”€ ๐Ÿ—„ ๐Ÿ”—
๐Ÿ”œ ๐Ÿ‘† ๐Ÿ’ช ๐Ÿšฎ ๐Ÿ“„ โ†”, โŽ ๐Ÿ›ƒ `x-logo` `info` "๐ŸŽš" ๐Ÿ—„ ๐Ÿ”—:
```Python hl_lines="21-23"
{!../../../docs_src/extending_openapi/tutorial001.py!}
```
### ๐Ÿ’พ ๐Ÿ—„ ๐Ÿ”—
๐Ÿ‘† ๐Ÿ’ช โš™๏ธ ๐Ÿ  `.openapi_schema` "๐Ÿ’พ", ๐Ÿช ๐Ÿ‘† ๐Ÿ— ๐Ÿ”—.
๐Ÿ‘ˆ ๐ŸŒŒ, ๐Ÿ‘† ๐Ÿˆธ ๐Ÿ† ๐Ÿšซ โœ”๏ธ ๐Ÿ— ๐Ÿ”— ๐Ÿ”  ๐Ÿ•ฐ ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ“‚ ๐Ÿ‘† ๐Ÿ› ๏ธ ๐Ÿฉบ.
โšซ๏ธ ๐Ÿ”œ ๐Ÿ— ๐Ÿ•ด ๐Ÿ•, &amp; โคด๏ธ ๐ŸŽ ๐Ÿ’พ ๐Ÿ”— ๐Ÿ”œ โš™๏ธ โญ ๐Ÿ“จ.
```Python hl_lines="13-14 24-25"
{!../../../docs_src/extending_openapi/tutorial001.py!}
```
### ๐Ÿ” ๐Ÿ‘ฉโ€๐Ÿ”ฌ
๐Ÿ”œ ๐Ÿ‘† ๐Ÿ’ช โŽ `.openapi()` ๐Ÿ‘ฉโ€๐Ÿ”ฌ โฎ๏ธ ๐Ÿ‘† ๐Ÿ†• ๐Ÿ”ข.
```Python hl_lines="28"
{!../../../docs_src/extending_openapi/tutorial001.py!}
```
### โœ… โšซ๏ธ
๐Ÿ• ๐Ÿ‘† ๐Ÿšถ <a href="http://127.0.0.1:8000/redoc" class="external-link" target="_blank">http://127.0.0.1:8000/redoc</a> ๐Ÿ‘† ๐Ÿ”œ ๐Ÿ‘€ ๐Ÿ‘ˆ ๐Ÿ‘† โš™๏ธ ๐Ÿ‘† ๐Ÿ›ƒ ๐Ÿ”ฑ (๐Ÿ‘‰ ๐Ÿ–ผ, **FastAPI**'โ“‚ ๐Ÿ”ฑ):
<img src="/img/tutorial/extending-openapi/image01.png">
## ๐Ÿ‘ค-๐Ÿ•ธ ๐Ÿ•ธ &amp; ๐ŸŽš ๐Ÿฉบ
๐Ÿ› ๏ธ ๐Ÿฉบ โš™๏ธ **๐Ÿฆ ๐ŸŽš** &amp; **๐Ÿ“„**, &amp; ๐Ÿ”  ๐Ÿ‘ˆ ๐Ÿ’ช ๐Ÿ•ธ &amp; ๐ŸŽš ๐Ÿ“.
๐Ÿ”ข, ๐Ÿ‘ˆ ๐Ÿ“ ๐Ÿฆ โšช๏ธโžก๏ธ <abbr title="Content Delivery Network: A service, normally composed of several servers, that provides static files, like JavaScript and CSS. It's commonly used to serve those files from the server closer to the client, improving performance.">๐Ÿ’ฒ</abbr>.
โœ‹๏ธ โšซ๏ธ ๐Ÿ’ช ๐Ÿ›ƒ โšซ๏ธ, ๐Ÿ‘† ๐Ÿ’ช โš’ ๐ŸŽฏ ๐Ÿ’ฒ, โš–๏ธ ๐Ÿฆ ๐Ÿ“ ๐Ÿ‘†.
๐Ÿ‘ˆ โš , ๐Ÿ–ผ, ๐Ÿšฅ ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ‘† ๐Ÿ“ฑ ๐Ÿšง ๐Ÿ‘ท โช ๐Ÿ“ฑ, ๐Ÿต ๐Ÿ“‚ ๐Ÿ•ธ ๐Ÿ”, โš–๏ธ ๐Ÿ‡ง๐Ÿ‡ฟ ๐Ÿ•ธ.
๐Ÿ“ฅ ๐Ÿ‘† ๐Ÿ”œ ๐Ÿ‘€ โ” ๐Ÿฆ ๐Ÿ‘ˆ ๐Ÿ“ ๐Ÿ‘†, ๐ŸŽ FastAPI ๐Ÿ“ฑ, &amp; ๐Ÿ”— ๐Ÿฉบ โš™๏ธ ๐Ÿ‘ซ.
### ๐Ÿ— ๐Ÿ“ ๐Ÿ“Š
โžก๏ธ ๐Ÿ’ฌ ๐Ÿ‘† ๐Ÿ— ๐Ÿ“ ๐Ÿ“Š ๐Ÿ‘€ ๐Ÿ’– ๐Ÿ‘‰:
```
.
โ”œโ”€โ”€ app
โ”‚ โ”œโ”€โ”€ __init__.py
โ”‚ โ”œโ”€โ”€ main.py
```
๐Ÿ”œ โœ ๐Ÿ“ ๐Ÿช ๐Ÿ“š ๐ŸŽป ๐Ÿ“.
๐Ÿ‘† ๐Ÿ†• ๐Ÿ“ ๐Ÿ“Š ๐Ÿ’ช ๐Ÿ‘€ ๐Ÿ’– ๐Ÿ‘‰:
```
.
โ”œโ”€โ”€ app
โ”‚ย ย  โ”œโ”€โ”€ __init__.py
โ”‚ย ย  โ”œโ”€โ”€ main.py
โ””โ”€โ”€ static/
```
### โฌ ๐Ÿ“
โฌ ๐ŸŽป ๐Ÿ“ ๐Ÿ’ช ๐Ÿฉบ &amp; ๐Ÿšฎ ๐Ÿ‘ซ ๐Ÿ”› ๐Ÿ‘ˆ `static/` ๐Ÿ“.
๐Ÿ‘† ๐Ÿ’ช ๐ŸŽฒ โ–ถ๏ธ๏ธ-๐Ÿ–Š ๐Ÿ”  ๐Ÿ”— &amp; ๐Ÿ–Š ๐ŸŽ› ๐ŸŽ `Save link as...`.
**๐Ÿฆ ๐ŸŽš** โš™๏ธ ๐Ÿ“:
* <a href="https://cdn.jsdelivr.net/npm/swagger-ui-dist@4/swagger-ui-bundle.js" class="external-link" target="_blank">`swagger-ui-bundle.js`</a>
* <a href="https://cdn.jsdelivr.net/npm/swagger-ui-dist@4/swagger-ui.css" class="external-link" target="_blank">`swagger-ui.css`</a>
&amp; **๐Ÿ“„** โš™๏ธ ๐Ÿ“:
* <a href="https://cdn.jsdelivr.net/npm/redoc@next/bundles/redoc.standalone.js" class="external-link" target="_blank">`redoc.standalone.js`</a>
โฎ๏ธ ๐Ÿ‘ˆ, ๐Ÿ‘† ๐Ÿ“ ๐Ÿ“Š ๐Ÿ’ช ๐Ÿ‘€ ๐Ÿ’–:
```
.
โ”œโ”€โ”€ app
โ”‚ย ย  โ”œโ”€โ”€ __init__.py
โ”‚ย ย  โ”œโ”€โ”€ main.py
โ””โ”€โ”€ static
โ”œโ”€โ”€ redoc.standalone.js
โ”œโ”€โ”€ swagger-ui-bundle.js
โ””โ”€โ”€ swagger-ui.css
```
### ๐Ÿฆ ๐ŸŽป ๐Ÿ“
* ๐Ÿ—„ `StaticFiles`.
* "๐Ÿ—ป" `StaticFiles()` ๐Ÿ‘ ๐ŸŽฏ โžก.
```Python hl_lines="7 11"
{!../../../docs_src/extending_openapi/tutorial002.py!}
```
### ๐Ÿ’ฏ ๐ŸŽป ๐Ÿ“
โ–ถ๏ธ ๐Ÿ‘† ๐Ÿˆธ &amp; ๐Ÿšถ <a href="http://127.0.0.1:8000/static/redoc.standalone.js" class="external-link" target="_blank">http://127.0.0.1:8000/static/redoc.standalone.js</a>.
๐Ÿ‘† ๐Ÿ”œ ๐Ÿ‘€ ๐Ÿ“ถ ๐Ÿ“ ๐Ÿ•ธ ๐Ÿ“ **๐Ÿ“„**.
โšซ๏ธ ๐Ÿ’ช โ–ถ๏ธ โฎ๏ธ ๐Ÿ•ณ ๐Ÿ’–:
```JavaScript
/*!
* ReDoc - OpenAPI/Swagger-generated API Reference Documentation
* -------------------------------------------------------------
* Version: "2.0.0-rc.18"
* Repo: https://github.com/Redocly/redoc
*/
!function(e,t){"object"==typeof exports&&"object"==typeof m
...
```
๐Ÿ‘ˆ โœ” ๐Ÿ‘ˆ ๐Ÿ‘† ๐Ÿ’†โ€โ™‚ ๐Ÿ’ช ๐Ÿฆ ๐ŸŽป ๐Ÿ“ โšช๏ธโžก๏ธ ๐Ÿ‘† ๐Ÿ“ฑ, &amp; ๐Ÿ‘ˆ ๐Ÿ‘† ๐Ÿฅ‰ ๐ŸŽป ๐Ÿ“ ๐Ÿฉบ โ˜‘ ๐Ÿฅ‰.
๐Ÿ”œ ๐Ÿ‘ฅ ๐Ÿ’ช ๐Ÿ”— ๐Ÿ“ฑ โš™๏ธ ๐Ÿ“š ๐ŸŽป ๐Ÿ“ ๐Ÿฉบ.
### โŽ ๐Ÿง ๐Ÿฉบ
๐Ÿฅ‡ ๐Ÿ” โŽ ๐Ÿง ๐Ÿฉบ, ๐Ÿ“š โš™๏ธ ๐Ÿ’ฒ ๐Ÿ”ข.
โŽ ๐Ÿ‘ซ, โš’ ๐Ÿ‘ซ ๐Ÿ“› `None` ๐Ÿ•โ” ๐Ÿ— ๐Ÿ‘† `FastAPI` ๐Ÿ“ฑ:
```Python hl_lines="9"
{!../../../docs_src/extending_openapi/tutorial002.py!}
```
### ๐Ÿ”Œ ๐Ÿ›ƒ ๐Ÿฉบ
๐Ÿ”œ ๐Ÿ‘† ๐Ÿ’ช โœ *โžก ๐Ÿ› ๏ธ* ๐Ÿ›ƒ ๐Ÿฉบ.
๐Ÿ‘† ๐Ÿ’ช ๐Ÿค-โš™๏ธ FastAPI ๐Ÿ”— ๐Ÿ”ข โœ ๐Ÿ•ธ ๐Ÿ“ƒ ๐Ÿฉบ, &amp; ๐Ÿšถโ€โ™€๏ธ ๐Ÿ‘ซ ๐Ÿ’ช โŒ:
* `openapi_url`: ๐Ÿ“› ๐ŸŒโ” ๐Ÿ•ธ ๐Ÿ“ƒ ๐Ÿฉบ ๐Ÿ’ช ๐Ÿคš ๐Ÿ—„ ๐Ÿ”— ๐Ÿ‘† ๐Ÿ› ๏ธ. ๐Ÿ‘† ๐Ÿ’ช โš™๏ธ ๐Ÿ“ฅ ๐Ÿ”ข `app.openapi_url`.
* `title`: ๐Ÿ“› ๐Ÿ‘† ๐Ÿ› ๏ธ.
* `oauth2_redirect_url`: ๐Ÿ‘† ๐Ÿ’ช โš™๏ธ `app.swagger_ui_oauth2_redirect_url` ๐Ÿ“ฅ โš™๏ธ ๐Ÿ”ข.
* `swagger_js_url`: ๐Ÿ“› ๐ŸŒโ” ๐Ÿ•ธ ๐Ÿ‘† ๐Ÿฆ ๐ŸŽš ๐Ÿฉบ ๐Ÿ’ช ๐Ÿคš **๐Ÿ•ธ** ๐Ÿ“. ๐Ÿ‘‰ 1๏ธโƒฃ ๐Ÿ‘ˆ ๐Ÿ‘† ๐Ÿ‘ ๐Ÿ“ฑ ๐Ÿ”œ ๐Ÿฆ.
* `swagger_css_url`: ๐Ÿ“› ๐ŸŒโ” ๐Ÿ•ธ ๐Ÿ‘† ๐Ÿฆ ๐ŸŽš ๐Ÿฉบ ๐Ÿ’ช ๐Ÿคš **๐ŸŽš** ๐Ÿ“. ๐Ÿ‘‰ 1๏ธโƒฃ ๐Ÿ‘ˆ ๐Ÿ‘† ๐Ÿ‘ ๐Ÿ“ฑ ๐Ÿ”œ ๐Ÿฆ.
&amp; โžก ๐Ÿ“„...
```Python hl_lines="2-6 14-22 25-27 30-36"
{!../../../docs_src/extending_openapi/tutorial002.py!}
```
!!! tip
*โžก ๐Ÿ› ๏ธ* `swagger_ui_redirect` ๐Ÿ‘ฉโ€๐ŸŽ“ ๐Ÿ•โ” ๐Ÿ‘† โš™๏ธ Oauth2๏ธโƒฃ.
๐Ÿšฅ ๐Ÿ‘† ๐Ÿ› ๏ธ ๐Ÿ‘† ๐Ÿ› ๏ธ โฎ๏ธ Oauth2๏ธโƒฃ ๐Ÿ•โ€๐Ÿฆบ, ๐Ÿ‘† ๐Ÿ”œ ๐Ÿ’ช ๐Ÿ”“ &amp; ๐Ÿ‘Ÿ ๐Ÿ”™ ๐Ÿ› ๏ธ ๐Ÿฉบ โฎ๏ธ ๐Ÿ“Ž ๐ŸŽ“. &amp; ๐Ÿ”— โฎ๏ธ โšซ๏ธ โš™๏ธ ๐ŸŽฐ Oauth2๏ธโƒฃ ๐Ÿค.
๐Ÿฆ ๐ŸŽš ๐Ÿ”œ ๐Ÿต โšซ๏ธ โ›… ๐ŸŽ‘ ๐Ÿ‘†, โœ‹๏ธ โšซ๏ธ ๐Ÿ’ช ๐Ÿ‘‰ "โŽ" ๐Ÿ‘ฉโ€๐ŸŽ“.
### โœ *โžก ๐Ÿ› ๏ธ* ๐Ÿ’ฏ โšซ๏ธ
๐Ÿ”œ, ๐Ÿ’ช ๐Ÿ’ฏ ๐Ÿ‘ˆ ๐ŸŒ ๐Ÿ‘ท, โœ *โžก ๐Ÿ› ๏ธ*:
```Python hl_lines="39-41"
{!../../../docs_src/extending_openapi/tutorial002.py!}
```
### ๐Ÿ’ฏ โšซ๏ธ
๐Ÿ”œ, ๐Ÿ‘† ๐Ÿ”œ ๐Ÿ’ช ๐Ÿ”Œ ๐Ÿ‘† ๐Ÿ“ป, ๐Ÿšถ ๐Ÿ‘† ๐Ÿฉบ <a href="http://127.0.0.1:8000/docs" class="external-link" target="_blank">http://127.0.0.1:8000/docs</a>, &amp; ๐Ÿ”ƒ ๐Ÿ“ƒ.
&amp; ๐Ÿต ๐Ÿ•ธ, ๐Ÿ‘† ๐Ÿ”œ ๐Ÿ’ช ๐Ÿ‘€ ๐Ÿฉบ ๐Ÿ‘† ๐Ÿ› ๏ธ &amp; ๐Ÿ”— โฎ๏ธ โšซ๏ธ.
## ๐Ÿ› ๏ธ ๐Ÿฆ ๐ŸŽš
๐Ÿ‘† ๐Ÿ’ช ๐Ÿ”— โž• <a href="https://swagger.io/docs/open-source-tools/swagger-ui/usage/configuration" class="external-link" target="_blank">๐Ÿฆ ๐ŸŽš ๐Ÿ”ข</a>.
๐Ÿ”— ๐Ÿ‘ซ, ๐Ÿšถโ€โ™€๏ธ `swagger_ui_parameters` โŒ ๐Ÿ•โ” ๐Ÿ— `FastAPI()` ๐Ÿ“ฑ ๐ŸŽš โš–๏ธ `get_swagger_ui_html()` ๐Ÿ”ข.
`swagger_ui_parameters` ๐Ÿ“จ ๐Ÿ“– โฎ๏ธ ๐Ÿ“ณ ๐Ÿšถโ€โ™€๏ธ ๐Ÿฆ ๐ŸŽš ๐Ÿ”—.
FastAPI ๐Ÿ—œ ๐Ÿ“ณ **๐ŸŽป** โš’ ๐Ÿ‘ซ ๐Ÿ”— โฎ๏ธ ๐Ÿ•ธ, ๐Ÿ‘ˆ โšซ๏ธโ” ๐Ÿฆ ๐ŸŽš ๐Ÿ’ช.
### โŽ โ• ๐ŸŽฆ
๐Ÿ–ผ, ๐Ÿ‘† ๐Ÿ’ช โŽ โ• ๐ŸŽฆ ๐Ÿฆ ๐ŸŽš.
๐Ÿต ๐Ÿ”€ โš’, โ• ๐ŸŽฆ ๐Ÿ› ๏ธ ๐Ÿ”ข:
<img src="/img/tutorial/extending-openapi/image02.png">
โœ‹๏ธ ๐Ÿ‘† ๐Ÿ’ช โŽ โšซ๏ธ โš’ `syntaxHighlight` `False`:
```Python hl_lines="3"
{!../../../docs_src/extending_openapi/tutorial003.py!}
```
...&amp; โคด๏ธ ๐Ÿฆ ๐ŸŽš ๐Ÿ† ๐Ÿšซ ๐ŸŽฆ โ• ๐ŸŽฆ ๐Ÿšซ๐Ÿ”œ:
<img src="/img/tutorial/extending-openapi/image03.png">
### ๐Ÿ”€ ๐ŸŽข
๐ŸŽ ๐ŸŒŒ ๐Ÿ‘† ๐Ÿ’ช โš’ โ• ๐ŸŽฆ ๐ŸŽข โฎ๏ธ ๐Ÿ”‘ `"syntaxHighlight.theme"` (๐Ÿ‘€ ๐Ÿ‘ˆ โšซ๏ธ โœ”๏ธ โฃ ๐Ÿ–•):
```Python hl_lines="3"
{!../../../docs_src/extending_openapi/tutorial004.py!}
```
๐Ÿ‘ˆ ๐Ÿ“ณ ๐Ÿ”œ ๐Ÿ”€ โ• ๐ŸŽฆ ๐ŸŽจ ๐ŸŽข:
<img src="/img/tutorial/extending-openapi/image04.png">
### ๐Ÿ”€ ๐Ÿ”ข ๐Ÿฆ ๐ŸŽš ๐Ÿ”ข
FastAPI ๐Ÿ”Œ ๐Ÿ”ข ๐Ÿ“ณ ๐Ÿ”ข โ˜‘ ๐ŸŒ… โš™๏ธ ๐Ÿ’ผ.
โšซ๏ธ ๐Ÿ”Œ ๐Ÿ‘ซ ๐Ÿ”ข ๐Ÿ“ณ:
```Python
{!../../../fastapi/openapi/docs.py[ln:7-13]!}
```
๐Ÿ‘† ๐Ÿ’ช ๐Ÿ” ๐Ÿ™† ๐Ÿ‘ซ โš’ ๐ŸŽ ๐Ÿ’ฒ โŒ `swagger_ui_parameters`.
๐Ÿ–ผ, โŽ `deepLinking` ๐Ÿ‘† ๐Ÿ’ช ๐Ÿšถโ€โ™€๏ธ ๐Ÿ‘‰ โš’ `swagger_ui_parameters`:
```Python hl_lines="3"
{!../../../docs_src/extending_openapi/tutorial005.py!}
```
### ๐ŸŽ ๐Ÿฆ ๐ŸŽš ๐Ÿ”ข
๐Ÿ‘€ ๐ŸŒ ๐ŸŽ ๐Ÿ’ช ๐Ÿ“ณ ๐Ÿ‘† ๐Ÿ’ช โš™๏ธ, โœ ๐Ÿ›‚ <a href="https://swagger.io/docs/open-source-tools/swagger-ui/usage/configuration" class="external-link" target="_blank">๐Ÿฉบ ๐Ÿฆ ๐ŸŽš ๐Ÿ”ข</a>.
### ๐Ÿ•ธ-๐Ÿ•ด โš’
๐Ÿฆ ๐ŸŽš โœ” ๐ŸŽ ๐Ÿ“ณ **๐Ÿ•ธ-๐Ÿ•ด** ๐ŸŽš (๐Ÿ–ผ, ๐Ÿ•ธ ๐Ÿ”ข).
FastAPI ๐Ÿ”Œ ๐Ÿ‘ซ ๐Ÿ•ธ-๐Ÿ•ด `presets` โš’:
```JavaScript
presets: [
SwaggerUIBundle.presets.apis,
SwaggerUIBundle.SwaggerUIStandalonePreset
]
```
๐Ÿ‘ซ **๐Ÿ•ธ** ๐ŸŽš, ๐Ÿšซ ๐ŸŽป, ๐Ÿ‘† ๐Ÿ’ช ๐Ÿšซ ๐Ÿšถโ€โ™€๏ธ ๐Ÿ‘ซ โšช๏ธโžก๏ธ ๐Ÿ ๐Ÿ“Ÿ ๐Ÿ”—.
๐Ÿšฅ ๐Ÿ‘† ๐Ÿ’ช โš™๏ธ ๐Ÿ•ธ-๐Ÿ•ด ๐Ÿ“ณ ๐Ÿ’– ๐Ÿ“š, ๐Ÿ‘† ๐Ÿ’ช โš™๏ธ 1๏ธโƒฃ ๐Ÿ‘ฉโ€๐Ÿ”ฌ ๐Ÿ”›. ๐Ÿ” ๐ŸŒ ๐Ÿฆ ๐ŸŽš *โžก ๐Ÿ› ๏ธ* &amp; โŽ โœ ๐Ÿ™† ๐Ÿ•ธ ๐Ÿ‘† ๐Ÿ’ช.

267
docs/em/docs/advanced/generate-clients.md

@ -0,0 +1,267 @@
# ๐Ÿ— ๐Ÿ‘ฉโ€๐Ÿ’ป
**FastAPI** โš“๏ธ ๐Ÿ”› ๐Ÿ—„ ๐Ÿ”ง, ๐Ÿ‘† ๐Ÿคš ๐Ÿง ๐Ÿ”— โฎ๏ธ ๐Ÿ“š ๐Ÿงฐ, ๐Ÿ”Œ ๐Ÿง ๐Ÿ› ๏ธ ๐Ÿฉบ (๐Ÿšš ๐Ÿฆ ๐ŸŽš).
1๏ธโƒฃ ๐ŸŽฏ ๐Ÿ“ˆ ๐Ÿ‘ˆ ๐Ÿšซ ๐ŸŽฏ โญ ๐Ÿ‘ˆ ๐Ÿ‘† ๐Ÿ’ช **๐Ÿ— ๐Ÿ‘ฉโ€๐Ÿ’ป** (๐Ÿ•ฃ ๐Ÿค™ <abbr title="Software Development Kits">**๐Ÿ“ฑ**</abbr> ) ๐Ÿ‘† ๐Ÿ› ๏ธ, ๐Ÿ“š ๐ŸŽ **๐Ÿ› ๏ธ ๐Ÿ‡ช๐Ÿ‡ธ**.
## ๐Ÿ—„ ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿš‚
๐Ÿ“ค ๐Ÿ“š ๐Ÿงฐ ๐Ÿ— ๐Ÿ‘ฉโ€๐Ÿ’ป โšช๏ธโžก๏ธ **๐Ÿ—„**.
โš  ๐Ÿงฐ <a href="https://openapi-generator.tech/" class="external-link" target="_blank">๐Ÿ—„ ๐Ÿš‚</a>.
๐Ÿšฅ ๐Ÿ‘† ๐Ÿ— **๐Ÿ•ธ**, ๐Ÿ“ถ ๐Ÿ˜Œ ๐ŸŽ› <a href="https://github.com/ferdikoomen/openapi-typescript-codegen" class="external-link" target="_blank">๐Ÿ—„-๐Ÿ“•-๐Ÿ‡ฆ๐Ÿ‡ช</a>.
## ๐Ÿ— ๐Ÿ“• ๐Ÿ•ธ ๐Ÿ‘ฉโ€๐Ÿ’ป
โžก๏ธ โ–ถ๏ธ โฎ๏ธ ๐Ÿ™… FastAPI ๐Ÿˆธ:
=== "๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="9-11 14-15 18 19 23"
{!> ../../../docs_src/generate_clients/tutorial001.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.9๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="7-9 12-13 16-17 21"
{!> ../../../docs_src/generate_clients/tutorial001_py39.py!}
```
๐Ÿ‘€ ๐Ÿ‘ˆ *โžก ๐Ÿ› ๏ธ* ๐Ÿ”ฌ ๐Ÿท ๐Ÿ‘ซ โš™๏ธ ๐Ÿ“จ ๐Ÿš€ &amp; ๐Ÿ“จ ๐Ÿš€, โš™๏ธ ๐Ÿท `Item` &amp; `ResponseMessage`.
### ๐Ÿ› ๏ธ ๐Ÿฉบ
๐Ÿšฅ ๐Ÿ‘† ๐Ÿšถ ๐Ÿ› ๏ธ ๐Ÿฉบ, ๐Ÿ‘† ๐Ÿ”œ ๐Ÿ‘€ ๐Ÿ‘ˆ โšซ๏ธ โœ”๏ธ **๐Ÿ”—** ๐Ÿ“Š ๐Ÿ“จ ๐Ÿ“จ &amp; ๐Ÿ“จ ๐Ÿ“จ:
<img src="/img/tutorial/generate-clients/image01.png">
๐Ÿ‘† ๐Ÿ’ช ๐Ÿ‘€ ๐Ÿ‘ˆ ๐Ÿ”— โ†ฉ๏ธ ๐Ÿ‘ซ ๐Ÿ“ฃ โฎ๏ธ ๐Ÿท ๐Ÿ“ฑ.
๐Ÿ‘ˆ โ„น ๐Ÿ’ช ๐Ÿ“ฑ **๐Ÿ—„ ๐Ÿ”—**, &amp; โคด๏ธ ๐ŸŽฆ ๐Ÿ› ๏ธ ๐Ÿฉบ (๐Ÿฆ ๐ŸŽš).
&amp; ๐Ÿ‘ˆ ๐ŸŽ โ„น โšช๏ธโžก๏ธ ๐Ÿท ๐Ÿ‘ˆ ๐Ÿ”Œ ๐Ÿ—„ โšซ๏ธโ” ๐Ÿ’ช โš™๏ธ **๐Ÿ— ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ“Ÿ**.
### ๐Ÿ— ๐Ÿ“• ๐Ÿ‘ฉโ€๐Ÿ’ป
๐Ÿ”œ ๐Ÿ‘ˆ ๐Ÿ‘ฅ โœ”๏ธ ๐Ÿ“ฑ โฎ๏ธ ๐Ÿท, ๐Ÿ‘ฅ ๐Ÿ’ช ๐Ÿ— ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ“Ÿ ๐Ÿ•ธ.
#### โŽ `openapi-typescript-codegen`
๐Ÿ‘† ๐Ÿ’ช โŽ `openapi-typescript-codegen` ๐Ÿ‘† ๐Ÿ•ธ ๐Ÿ“Ÿ โฎ๏ธ:
<div class="termy">
```console
$ npm install openapi-typescript-codegen --save-dev
---> 100%
```
</div>
#### ๐Ÿ— ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ“Ÿ
๐Ÿ— ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ“Ÿ ๐Ÿ‘† ๐Ÿ’ช โš™๏ธ ๐Ÿ“‹ โธ ๐Ÿˆธ `openapi` ๐Ÿ‘ˆ ๐Ÿ”œ ๐Ÿ”œ โŽ.
โ†ฉ๏ธ โšซ๏ธ โŽ ๐Ÿ‡ง๐Ÿ‡ฟ ๐Ÿ—, ๐Ÿ‘† ๐ŸŽฒ ๐Ÿšซ๐Ÿ”œ ๐Ÿ’ช ๐Ÿค™ ๐Ÿ‘ˆ ๐Ÿ“‹ ๐Ÿ”—, โœ‹๏ธ ๐Ÿ‘† ๐Ÿ”œ ๐Ÿšฎ โšซ๏ธ ๐Ÿ”› ๐Ÿ‘† `package.json` ๐Ÿ“.
โšซ๏ธ ๐Ÿ’ช ๐Ÿ‘€ ๐Ÿ’– ๐Ÿ‘‰:
```JSON hl_lines="7"
{
"name": "frontend-app",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"generate-client": "openapi --input http://localhost:8000/openapi.json --output ./src/client --client axios"
},
"author": "",
"license": "",
"devDependencies": {
"openapi-typescript-codegen": "^0.20.1",
"typescript": "^4.6.2"
}
}
```
โฎ๏ธ โœ”๏ธ ๐Ÿ‘ˆ โ˜• `generate-client` โœ ๐Ÿ“ค, ๐Ÿ‘† ๐Ÿ’ช ๐Ÿƒ โšซ๏ธ โฎ๏ธ:
<div class="termy">
```console
$ npm run generate-client
[email protected] generate-client /home/user/code/frontend-app
> openapi --input http://localhost:8000/openapi.json --output ./src/client --client axios
```
</div>
๐Ÿ‘ˆ ๐Ÿ“‹ ๐Ÿ”œ ๐Ÿ— ๐Ÿ“Ÿ `./src/client` &amp; ๐Ÿ”œ โš™๏ธ `axios` (๐Ÿ•ธ ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ” ๐Ÿ—ƒ) ๐Ÿ”˜.
### ๐Ÿ”„ ๐Ÿ‘… ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ“Ÿ
๐Ÿ”œ ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ—„ &amp; โš™๏ธ ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ“Ÿ, โšซ๏ธ ๐Ÿ’ช ๐Ÿ‘€ ๐Ÿ’– ๐Ÿ‘‰, ๐Ÿ‘€ ๐Ÿ‘ˆ ๐Ÿ‘† ๐Ÿคš โœ ๐Ÿ‘ฉโ€๐Ÿ”ฌ:
<img src="/img/tutorial/generate-clients/image02.png">
๐Ÿ‘† ๐Ÿ”œ ๐Ÿคš โœ ๐Ÿš€ ๐Ÿ“จ:
<img src="/img/tutorial/generate-clients/image03.png">
!!! tip
๐Ÿ‘€ โœ `name` &amp; `price`, ๐Ÿ‘ˆ ๐Ÿ”ฌ FastAPI ๐Ÿˆธ, `Item` ๐Ÿท.
๐Ÿ‘† ๐Ÿ”œ โœ”๏ธ โธ โŒ ๐Ÿ“Š ๐Ÿ‘ˆ ๐Ÿ‘† ๐Ÿ“จ:
<img src="/img/tutorial/generate-clients/image04.png">
๐Ÿ“จ ๐ŸŽš ๐Ÿ”œ โœ”๏ธ โœ:
<img src="/img/tutorial/generate-clients/image05.png">
## FastAPI ๐Ÿ“ฑ โฎ๏ธ ๐Ÿ”–
๐Ÿ“š ๐Ÿ’ผ ๐Ÿ‘† FastAPI ๐Ÿ“ฑ ๐Ÿ”œ ๐Ÿฆ, &amp; ๐Ÿ‘† ๐Ÿ”œ ๐ŸŽฒ โš™๏ธ ๐Ÿ”– ๐ŸŽ ๐ŸŽ ๐Ÿ‘ช *โžก ๐Ÿ› ๏ธ*.
๐Ÿ–ผ, ๐Ÿ‘† ๐Ÿ’ช โœ”๏ธ ๐Ÿ“„ **๐Ÿฌ** &amp; โž•1๏ธโƒฃ ๐Ÿ“„ **๐Ÿ‘ฉโ€๐Ÿ’ป**, &amp; ๐Ÿ‘ซ ๐Ÿ’ช ๐Ÿ‘ฝ ๐Ÿ”–:
=== "๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="23 28 36"
{!> ../../../docs_src/generate_clients/tutorial002.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.9๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="21 26 34"
{!> ../../../docs_src/generate_clients/tutorial002_py39.py!}
```
### ๐Ÿ— ๐Ÿ“• ๐Ÿ‘ฉโ€๐Ÿ’ป โฎ๏ธ ๐Ÿ”–
๐Ÿšฅ ๐Ÿ‘† ๐Ÿ— ๐Ÿ‘ฉโ€๐Ÿ’ป FastAPI ๐Ÿ“ฑ โš™๏ธ ๐Ÿ”–, โšซ๏ธ ๐Ÿ”œ ๐Ÿ›Ž ๐ŸŽ ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ“Ÿ โš“๏ธ ๐Ÿ”› ๐Ÿ”–.
๐Ÿ‘‰ ๐ŸŒŒ ๐Ÿ‘† ๐Ÿ”œ ๐Ÿ’ช โœ”๏ธ ๐Ÿ‘œ โœ” &amp; ๐Ÿ‘ช โ˜‘ ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ“Ÿ:
<img src="/img/tutorial/generate-clients/image06.png">
๐Ÿ‘‰ ๐Ÿ’ผ ๐Ÿ‘† โœ”๏ธ:
* `ItemsService`
* `UsersService`
### ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ‘ฉโ€๐Ÿ”ฌ ๐Ÿ“›
โ–ถ๏ธ๏ธ ๐Ÿ”œ ๐Ÿ— ๐Ÿ‘ฉโ€๐Ÿ”ฌ ๐Ÿ“› ๐Ÿ’– `createItemItemsPost` ๐Ÿšซ ๐Ÿ‘€ ๐Ÿ“ถ ๐Ÿงน:
```TypeScript
ItemsService.createItemItemsPost({name: "Plumbus", price: 5})
```
...๐Ÿ‘ˆ โ†ฉ๏ธ ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿš‚ โš™๏ธ ๐Ÿ—„ ๐Ÿ”— **๐Ÿ› ๏ธ ๐Ÿ†”** ๐Ÿ”  *โžก ๐Ÿ› ๏ธ*.
๐Ÿ—„ ๐Ÿšš ๐Ÿ‘ˆ ๐Ÿ”  ๐Ÿ› ๏ธ ๐Ÿ†” ๐Ÿ˜ ๐Ÿคญ ๐ŸŒ *โžก ๐Ÿ› ๏ธ*, FastAPI โš™๏ธ **๐Ÿ”ข ๐Ÿ“›**, **โžก**, &amp; **๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ” ๐Ÿ‘ฉโ€๐Ÿ”ฌ/๐Ÿ› ๏ธ** ๐Ÿ— ๐Ÿ‘ˆ ๐Ÿ› ๏ธ ๐Ÿ†”, โ†ฉ๏ธ ๐Ÿ‘ˆ ๐ŸŒŒ โšซ๏ธ ๐Ÿ’ช โš’ ๐Ÿ’ญ ๐Ÿ‘ˆ ๐Ÿ› ๏ธ ๐Ÿ†” ๐Ÿ˜.
โœ‹๏ธ ๐Ÿ‘ค ๐Ÿ”œ ๐ŸŽฆ ๐Ÿ‘† โ” ๐Ÿ“‰ ๐Ÿ‘ˆ โญ. ๐Ÿ‘ถ
## ๐Ÿ›ƒ ๐Ÿ› ๏ธ ๐Ÿ†” &amp; ๐Ÿ‘ ๐Ÿ‘ฉโ€๐Ÿ”ฌ ๐Ÿ“›
๐Ÿ‘† ๐Ÿ’ช **๐Ÿ”€** ๐ŸŒŒ ๐Ÿ‘ซ ๐Ÿ› ๏ธ ๐Ÿ†” **๐Ÿ—** โš’ ๐Ÿ‘ซ ๐Ÿ™… &amp; โœ”๏ธ **๐Ÿ™… ๐Ÿ‘ฉโ€๐Ÿ”ฌ ๐Ÿ“›** ๐Ÿ‘ฉโ€๐Ÿ’ป.
๐Ÿ‘‰ ๐Ÿ’ผ ๐Ÿ‘† ๐Ÿ”œ โœ”๏ธ ๐Ÿšš ๐Ÿ‘ˆ ๐Ÿ”  ๐Ÿ› ๏ธ ๐Ÿ†” **๐Ÿ˜** ๐ŸŽ ๐ŸŒŒ.
๐Ÿ–ผ, ๐Ÿ‘† ๐Ÿ’ช โš’ ๐Ÿ’ญ ๐Ÿ‘ˆ ๐Ÿ”  *โžก ๐Ÿ› ๏ธ* โœ”๏ธ ๐Ÿ”–, &amp; โคด๏ธ ๐Ÿ— ๐Ÿ› ๏ธ ๐Ÿ†” โš“๏ธ ๐Ÿ”› **๐Ÿ”–** &amp; *โžก ๐Ÿ› ๏ธ* **๐Ÿ“›** (๐Ÿ”ข ๐Ÿ“›).
### ๐Ÿ›ƒ ๐Ÿ— ๐Ÿ˜ ๐Ÿ†” ๐Ÿ”ข
FastAPI โš™๏ธ **๐Ÿ˜ ๐Ÿ†”** ๐Ÿ”  *โžก ๐Ÿ› ๏ธ*, โšซ๏ธ โš™๏ธ **๐Ÿ› ๏ธ ๐Ÿ†”** &amp; ๐Ÿ“› ๐Ÿ™† ๐Ÿ’ช ๐Ÿ›ƒ ๐Ÿท, ๐Ÿ“จ โš–๏ธ ๐Ÿ“จ.
๐Ÿ‘† ๐Ÿ’ช ๐Ÿ›ƒ ๐Ÿ‘ˆ ๐Ÿ”ข. โšซ๏ธ โœŠ `APIRoute` &amp; ๐Ÿ”ข ๐ŸŽป.
๐Ÿ–ผ, ๐Ÿ“ฅ โšซ๏ธ โš™๏ธ ๐Ÿฅ‡ ๐Ÿ”– (๐Ÿ‘† ๐Ÿ”œ ๐ŸŽฒ โœ”๏ธ ๐Ÿ•ด 1๏ธโƒฃ ๐Ÿ”–) &amp; *โžก ๐Ÿ› ๏ธ* ๐Ÿ“› (๐Ÿ”ข ๐Ÿ“›).
๐Ÿ‘† ๐Ÿ’ช โคด๏ธ ๐Ÿšถโ€โ™€๏ธ ๐Ÿ‘ˆ ๐Ÿ›ƒ ๐Ÿ”ข **FastAPI** `generate_unique_id_function` ๐Ÿ”ข:
=== "๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="8-9 12"
{!> ../../../docs_src/generate_clients/tutorial003.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.9๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="6-7 10"
{!> ../../../docs_src/generate_clients/tutorial003_py39.py!}
```
### ๐Ÿ— ๐Ÿ“• ๐Ÿ‘ฉโ€๐Ÿ’ป โฎ๏ธ ๐Ÿ›ƒ ๐Ÿ› ๏ธ ๐Ÿ†”
๐Ÿ”œ ๐Ÿšฅ ๐Ÿ‘† ๐Ÿ— ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ”„, ๐Ÿ‘† ๐Ÿ”œ ๐Ÿ‘€ ๐Ÿ‘ˆ โšซ๏ธ โœ”๏ธ ๐Ÿ“‰ ๐Ÿ‘ฉโ€๐Ÿ”ฌ ๐Ÿ“›:
<img src="/img/tutorial/generate-clients/image07.png">
๐Ÿ‘† ๐Ÿ‘€, ๐Ÿ‘ฉโ€๐Ÿ”ฌ ๐Ÿ“› ๐Ÿ”œ โœ”๏ธ ๐Ÿ”– &amp; โคด๏ธ ๐Ÿ”ข ๐Ÿ“›, ๐Ÿ”œ ๐Ÿ‘ซ ๐Ÿšซ ๐Ÿ”Œ โ„น โšช๏ธโžก๏ธ ๐Ÿ“› โžก &amp; ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ” ๐Ÿ› ๏ธ.
### ๐Ÿ—œ ๐Ÿ—„ ๐Ÿ”ง ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿš‚
๐Ÿ— ๐Ÿ“Ÿ โœ”๏ธ **โŽ โ„น**.
๐Ÿ‘ฅ โช ๐Ÿ’ญ ๐Ÿ‘ˆ ๐Ÿ‘‰ ๐Ÿ‘ฉโ€๐Ÿ”ฌ ๐Ÿ”— **๐Ÿฌ** โ†ฉ๏ธ ๐Ÿ‘ˆ ๐Ÿ”ค `ItemsService` (โœŠ โšช๏ธโžก๏ธ ๐Ÿ”–), โœ‹๏ธ ๐Ÿ‘ฅ โœ”๏ธ ๐Ÿ“› ๐Ÿ”ก ๐Ÿ‘ฉโ€๐Ÿ”ฌ ๐Ÿ“› ๐Ÿ’โ€โ™‚๏ธ. ๐Ÿ‘ถ
๐Ÿ‘ฅ ๐Ÿ”œ ๐ŸŽฒ ๐Ÿ’š ๐Ÿšง โšซ๏ธ ๐Ÿ—„ ๐Ÿข, ๐Ÿ‘ˆ ๐Ÿ”œ ๐Ÿšš ๐Ÿ‘ˆ ๐Ÿ› ๏ธ ๐Ÿ†” **๐Ÿ˜**.
โœ‹๏ธ ๐Ÿ— ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ‘ฅ ๐Ÿ’ช **๐Ÿ”€** ๐Ÿ—„ ๐Ÿ› ๏ธ ๐Ÿ†” โ–ถ๏ธ๏ธ โญ ๐Ÿญ ๐Ÿ‘ฉโ€๐Ÿ’ป, โš’ ๐Ÿ‘ˆ ๐Ÿ‘ฉโ€๐Ÿ”ฌ ๐Ÿ“› ๐Ÿ‘Œ &amp; **๐Ÿงน**.
๐Ÿ‘ฅ ๐Ÿ’ช โฌ ๐Ÿ—„ ๐ŸŽป ๐Ÿ“ `openapi.json` &amp; โคด๏ธ ๐Ÿ‘ฅ ๐Ÿ’ช **โŽ ๐Ÿ‘ˆ ๐Ÿ”ก ๐Ÿ”–** โฎ๏ธ โœ ๐Ÿ’– ๐Ÿ‘‰:
```Python
{!../../../docs_src/generate_clients/tutorial004.py!}
```
โฎ๏ธ ๐Ÿ‘ˆ, ๐Ÿ› ๏ธ ๐Ÿ†” ๐Ÿ”œ ๐Ÿ“ โšช๏ธโžก๏ธ ๐Ÿ‘œ ๐Ÿ’– `items-get_items` `get_items`, ๐Ÿ‘ˆ ๐ŸŒŒ ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿš‚ ๐Ÿ’ช ๐Ÿ— ๐Ÿ™… ๐Ÿ‘ฉโ€๐Ÿ”ฌ ๐Ÿ“›.
### ๐Ÿ— ๐Ÿ“• ๐Ÿ‘ฉโ€๐Ÿ’ป โฎ๏ธ ๐Ÿ—œ ๐Ÿ—„
๐Ÿ”œ ๐Ÿ”š ๐Ÿ ๐Ÿ“ `openapi.json`, ๐Ÿ‘† ๐Ÿ”œ ๐Ÿ”€ `package.json` โš™๏ธ ๐Ÿ‘ˆ ๐Ÿ‡ง๐Ÿ‡ฟ ๐Ÿ“, ๐Ÿ–ผ:
```JSON hl_lines="7"
{
"name": "frontend-app",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"generate-client": "openapi --input ./openapi.json --output ./src/client --client axios"
},
"author": "",
"license": "",
"devDependencies": {
"openapi-typescript-codegen": "^0.20.1",
"typescript": "^4.6.2"
}
}
```
โฎ๏ธ ๐Ÿญ ๐Ÿ†• ๐Ÿ‘ฉโ€๐Ÿ’ป, ๐Ÿ‘† ๐Ÿ”œ ๐Ÿ”œ โœ”๏ธ **๐Ÿงน ๐Ÿ‘ฉโ€๐Ÿ”ฌ ๐Ÿ“›**, โฎ๏ธ ๐ŸŒ **โœ**, **โธ โŒ**, โ™’๏ธ:
<img src="/img/tutorial/generate-clients/image08.png">
## ๐Ÿ’ฐ
๐Ÿ•โ” โš™๏ธ ๐Ÿ” ๐Ÿ— ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ‘† ๐Ÿ”œ **โœ** :
* ๐Ÿ‘ฉโ€๐Ÿ”ฌ.
* ๐Ÿ“จ ๐Ÿš€ ๐Ÿ’ช, ๐Ÿ”ข ๐Ÿ”ข, โ™’๏ธ.
* ๐Ÿ“จ ๐Ÿš€.
๐Ÿ‘† ๐Ÿ”œ โœ”๏ธ **โธ โŒ** ๐ŸŒ.
&amp; ๐Ÿ•โ” ๐Ÿ‘† โ„น ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ“Ÿ, &amp; **โ™ป** ๐Ÿ•ธ, โšซ๏ธ ๐Ÿ”œ โœ”๏ธ ๐Ÿ™† ๐Ÿ†• *โžก ๐Ÿ› ๏ธ* ๐Ÿ’ช ๐Ÿ‘ฉโ€๐Ÿ”ฌ, ๐Ÿ— ๐Ÿ• โŽ, &amp; ๐Ÿ™† ๐ŸŽ ๐Ÿ”€ ๐Ÿ”œ ๐ŸŽจ ๐Ÿ”› ๐Ÿ— ๐Ÿ“Ÿ. ๐Ÿ‘ถ
๐Ÿ‘‰ โ›“ ๐Ÿ‘ˆ ๐Ÿšฅ ๐Ÿ•ณ ๐Ÿ”€ โšซ๏ธ ๐Ÿ”œ **๐ŸŽจ** ๐Ÿ”› ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ“Ÿ ๐Ÿ”. &amp; ๐Ÿšฅ ๐Ÿ‘† **๐Ÿ—** ๐Ÿ‘ฉโ€๐Ÿ’ป โšซ๏ธ ๐Ÿ”œ โŒ ๐Ÿ‘… ๐Ÿšฅ ๐Ÿ‘† โœ”๏ธ ๐Ÿ™† **๐Ÿ”–** ๐Ÿ“Š โš™๏ธ.
, ๐Ÿ‘† ๐Ÿ”œ **๐Ÿ” ๐Ÿ“š โŒ** ๐Ÿ“ถ โช ๐Ÿ› ๏ธ ๐Ÿ›ต โ†ฉ๏ธ โœ”๏ธ โŒ› โŒ ๐ŸŽฆ ๐Ÿ†™ ๐Ÿ‘† ๐Ÿ ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿญ &amp; โคด๏ธ ๐Ÿ”„ โ„น ๐ŸŒโ” โš . ๐Ÿ‘ถ

56
docs/em/docs/advanced/graphql.md

@ -0,0 +1,56 @@
# ๐Ÿ•น
**FastAPI** โš“๏ธ ๐Ÿ”› **๐Ÿ”ซ** ๐Ÿฉ, โšซ๏ธ ๐Ÿ“ถ โฉ ๐Ÿ› ๏ธ ๐Ÿ™† **๐Ÿ•น** ๐Ÿ—ƒ ๐Ÿ”— โฎ๏ธ ๐Ÿ”ซ.
๐Ÿ‘† ๐Ÿ’ช ๐ŸŒ€ ๐Ÿ˜ FastAPI *โžก ๐Ÿ› ๏ธ* โฎ๏ธ ๐Ÿ•น ๐Ÿ”› ๐ŸŽ ๐Ÿˆธ.
!!! tip
**๐Ÿ•น** โŽ ๐Ÿ“ถ ๐ŸŽฏ โš™๏ธ ๐Ÿ’ผ.
โšซ๏ธ โœ”๏ธ **๐Ÿ“ˆ** &amp; **โš ** ๐Ÿ•โ” ๐Ÿ”ฌ โš  **๐Ÿ•ธ ๐Ÿ”—**.
โš’ ๐Ÿ’ญ ๐Ÿ‘† ๐Ÿ”ฌ ๐Ÿšฅ **๐Ÿ’ฐ** ๐Ÿ‘† โš™๏ธ ๐Ÿ’ผ โš– **๐Ÿ‘**. ๐Ÿ‘ถ
## ๐Ÿ•น ๐Ÿ—ƒ
๐Ÿ“ฅ **๐Ÿ•น** ๐Ÿ—ƒ ๐Ÿ‘ˆ โœ”๏ธ **๐Ÿ”ซ** ๐Ÿ•โ€๐Ÿฆบ. ๐Ÿ‘† ๐Ÿ’ช โš™๏ธ ๐Ÿ‘ซ โฎ๏ธ **FastAPI**:
* <a href="https://strawberry.rocks/" class="external-link" target="_blank">๐Ÿ“</a> ๐Ÿ‘ถ
* โฎ๏ธ <a href="https://strawberry.rocks/docs/integrations/fastapi" class="external-link" target="_blank">๐Ÿฉบ FastAPI</a>
* <a href="https://ariadnegraphql.org/" class="external-link" target="_blank">๐Ÿ‘ธ</a>
* โฎ๏ธ <a href="https://ariadnegraphql.org/docs/starlette-integration" class="external-link" target="_blank">๐Ÿฉบ ๐Ÿ’ƒ</a> (๐Ÿ‘ˆ โœ” FastAPI)
* <a href="https://tartiflette.io/" class="external-link" target="_blank">๐ŸŸ</a>
* โฎ๏ธ <a href="https://tartiflette.github.io/tartiflette-asgi/" class="external-link" target="_blank">๐ŸŸ ๐Ÿ”ซ</a> ๐Ÿšš ๐Ÿ”ซ ๐Ÿ› ๏ธ
* <a href="https://graphene-python.org/" class="external-link" target="_blank">โš—</a>
* โฎ๏ธ <a href="https://github.com/ciscorn/starlette-graphene3" class="external-link" target="_blank">๐Ÿ’ƒ-Graphene3๏ธโƒฃ</a>
## ๐Ÿ•น โฎ๏ธ ๐Ÿ“
๐Ÿšฅ ๐Ÿ‘† ๐Ÿ’ช โš–๏ธ ๐Ÿ’š ๐Ÿ‘ท โฎ๏ธ **๐Ÿ•น**, <a href="https://strawberry.rocks/" class="external-link" target="_blank">**๐Ÿ“**</a> **๐Ÿ‘** ๐Ÿ—ƒ โšซ๏ธ โœ”๏ธ ๐Ÿ”ง ๐Ÿ” **FastAPI** ๐Ÿ”ง, โšซ๏ธ ๐ŸŒ โš“๏ธ ๐Ÿ”› **๐Ÿ†Ž โœ**.
โš“๏ธ ๐Ÿ”› ๐Ÿ‘† โš™๏ธ ๐Ÿ’ผ, ๐Ÿ‘† 5๏ธโƒฃ๐Ÿ“† ๐Ÿ’– โš™๏ธ ๐ŸŽ ๐Ÿ—ƒ, โœ‹๏ธ ๐Ÿšฅ ๐Ÿ‘† ๐Ÿ’ญ ๐Ÿ‘ค, ๐Ÿ‘ค ๐Ÿ”œ ๐ŸŽฒ ๐Ÿค” ๐Ÿ‘† ๐Ÿ”„ **๐Ÿ“**.
๐Ÿ“ฅ ๐Ÿคช ๐ŸŽฎ โ” ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ› ๏ธ ๐Ÿ“ โฎ๏ธ FastAPI:
```Python hl_lines="3 22 25-26"
{!../../../docs_src/graphql/tutorial001.py!}
```
๐Ÿ‘† ๐Ÿ’ช ๐Ÿ’ก ๐ŸŒ… ๐Ÿ”ƒ ๐Ÿ“ <a href="https://strawberry.rocks/" class="external-link" target="_blank">๐Ÿ“ ๐Ÿงพ</a>.
&amp; ๐Ÿฉบ ๐Ÿ”ƒ <a href="https://strawberry.rocks/docs/integrations/fastapi" class="external-link" target="_blank">๐Ÿ“ โฎ๏ธ FastAPI</a>.
## ๐Ÿ— `GraphQLApp` โšช๏ธโžก๏ธ ๐Ÿ’ƒ
โฎ๏ธ โฌ ๐Ÿ’ƒ ๐Ÿ”Œ `GraphQLApp` ๐ŸŽ“ ๐Ÿ› ๏ธ โฎ๏ธ <a href="https://graphene-python.org/" class="external-link" target="_blank">โš—</a>.
โšซ๏ธ ๐Ÿ˜ข โšช๏ธโžก๏ธ ๐Ÿ’ƒ, โœ‹๏ธ ๐Ÿšฅ ๐Ÿ‘† โœ”๏ธ ๐Ÿ“Ÿ ๐Ÿ‘ˆ โš™๏ธ โšซ๏ธ, ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ’ช **โ†”** <a href="https://github.com/ciscorn/starlette-graphene3" class="external-link" target="_blank">๐Ÿ’ƒ-Graphene3๏ธโƒฃ</a>, ๐Ÿ‘ˆ ๐Ÿ“” ๐ŸŽ โš™๏ธ ๐Ÿ’ผ &amp; โœ”๏ธ **๐ŸŒ– ๐ŸŒ“ ๐Ÿ”ข**.
!!! tip
๐Ÿšฅ ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ•น, ๐Ÿ‘ค ๐Ÿ”œ ๐Ÿ‘ ๐Ÿ‘† โœ… ๐Ÿ‘… <a href="https://strawberry.rocks/" class="external-link" target="_blank">๐Ÿ“</a>, โšซ๏ธ โš“๏ธ ๐Ÿ”› ๐Ÿ†Ž โœ โ†ฉ๏ธ ๐Ÿ›ƒ ๐ŸŽ“ &amp; ๐Ÿ†Ž.
## ๐Ÿ’ก ๐ŸŒ…
๐Ÿ‘† ๐Ÿ’ช ๐Ÿ’ก ๐ŸŒ… ๐Ÿ”ƒ **๐Ÿ•น** <a href="https://graphql.org/" class="external-link" target="_blank">๐Ÿ›‚ ๐Ÿ•น ๐Ÿงพ</a>.
๐Ÿ‘† ๐Ÿ’ช โœ ๐ŸŒ… ๐Ÿ”ƒ ๐Ÿ”  ๐Ÿ‘ˆ ๐Ÿ—ƒ ๐Ÿ”ฌ ๐Ÿ”› ๐Ÿ‘ซ ๐Ÿ”—.

24
docs/em/docs/advanced/index.md

@ -0,0 +1,24 @@
# ๐Ÿง ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿฆฎ - ๐ŸŽถ
## ๐ŸŒ– โš’
๐Ÿ‘‘ [๐Ÿ”ฐ - ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿฆฎ](../tutorial/){.internal-link target=_blank} ๐Ÿ”œ ๐Ÿฅƒ ๐Ÿค ๐Ÿ‘† ๐ŸŽซ ๐Ÿ”˜ ๐ŸŒ ๐Ÿ‘‘ โš’ **FastAPI**.
โญ ๐Ÿ“„ ๐Ÿ‘† ๐Ÿ”œ ๐Ÿ‘€ ๐ŸŽ ๐ŸŽ›, ๐Ÿ“ณ, &amp; ๐ŸŒ– โš’.
!!! tip
โญ ๐Ÿ“„ **๐Ÿšซ ๐ŸŽฏ "๐Ÿง"**.
&amp; โšซ๏ธ ๐Ÿ’ช ๐Ÿ‘ˆ ๐Ÿ‘† โš™๏ธ ๐Ÿ’ผ, โš— 1๏ธโƒฃ ๐Ÿ‘ซ.
## โœ ๐Ÿ”ฐ ๐Ÿฅ‡
๐Ÿ‘† ๐Ÿ’ช โš™๏ธ ๐Ÿ† โš’ **FastAPI** โฎ๏ธ ๐Ÿ’ก โšช๏ธโžก๏ธ ๐Ÿ‘‘ [๐Ÿ”ฐ - ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿฆฎ](../tutorial/){.internal-link target=_blank}.
&amp; โญ ๐Ÿ“„ ๐Ÿค” ๐Ÿ‘† โช โœ โšซ๏ธ, &amp; ๐Ÿค” ๐Ÿ‘ˆ ๐Ÿ‘† ๐Ÿ’ญ ๐Ÿ‘ˆ ๐Ÿ‘‘ ๐Ÿ’ญ.
## ๐ŸŽ.๐Ÿ…พ โ†—๏ธ
๐Ÿšฅ ๐Ÿ‘† ๐Ÿ”œ ๐Ÿ’– โœŠ ๐Ÿง-๐Ÿ”ฐ โ†—๏ธ ๐Ÿ”— ๐Ÿ‘‰ ๐Ÿ“„ ๐Ÿฉบ, ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ’š โœ…: <a href="https://testdriven.io/courses/tdd-fastapi/" class="external-link" target="_blank">๐Ÿ’ฏ-๐Ÿ’พ ๐Ÿ› ๏ธ โฎ๏ธ FastAPI &amp; โ˜</a> **๐ŸŽ.๐Ÿ…พ**.
๐Ÿ‘ซ โณ ๐Ÿฉธ 1๏ธโƒฃ0๏ธโƒฃ ๐Ÿ’ฏ ๐ŸŒ ๐Ÿ’ฐ ๐Ÿ› ๏ธ **FastAPI**. ๐Ÿ‘ถ ๐Ÿ‘ถ

99
docs/em/docs/advanced/middleware.md

@ -0,0 +1,99 @@
# ๐Ÿง ๐Ÿ› ๏ธ
๐Ÿ‘‘ ๐Ÿ”ฐ ๐Ÿ‘† โœ โ” ๐Ÿšฎ [๐Ÿ›ƒ ๐Ÿ› ๏ธ](../tutorial/middleware.md){.internal-link target=_blank} ๐Ÿ‘† ๐Ÿˆธ.
&amp; โคด๏ธ ๐Ÿ‘† โœ โ” ๐Ÿต [โšœ โฎ๏ธ `CORSMiddleware`](../tutorial/cors.md){.internal-link target=_blank}.
๐Ÿ‘‰ ๐Ÿ“„ ๐Ÿ‘ฅ ๐Ÿ”œ ๐Ÿ‘€ โ” โš™๏ธ ๐ŸŽ ๐Ÿ› ๏ธ.
## โŽ ๐Ÿ”ซ ๐Ÿ› ๏ธ
**FastAPI** โš“๏ธ ๐Ÿ”› ๐Ÿ’ƒ &amp; ๐Ÿ› ๏ธ <abbr title="Asynchronous Server Gateway Interface">๐Ÿ”ซ</abbr> ๐Ÿ”ง, ๐Ÿ‘† ๐Ÿ’ช โš™๏ธ ๐Ÿ™† ๐Ÿ”ซ ๐Ÿ› ๏ธ.
๐Ÿ› ๏ธ ๐Ÿšซ โœ”๏ธ โš’ FastAPI โš–๏ธ ๐Ÿ’ƒ ๐Ÿ‘ท, ๐Ÿ“ โšซ๏ธ โฉ ๐Ÿ”ซ ๐Ÿ”Œ.
๐Ÿข, ๐Ÿ”ซ ๐Ÿ› ๏ธ ๐ŸŽ“ ๐Ÿ‘ˆ โŒ› ๐Ÿ“จ ๐Ÿ”ซ ๐Ÿ“ฑ ๐Ÿฅ‡ โŒ.
, ๐Ÿงพ ๐Ÿฅ‰-๐Ÿฅณ ๐Ÿ”ซ ๐Ÿ› ๏ธ ๐Ÿ‘ซ ๐Ÿ”œ ๐ŸŽฒ ๐Ÿ’ฌ ๐Ÿ‘† ๐Ÿ•ณ ๐Ÿ’–:
```Python
from unicorn import UnicornMiddleware
app = SomeASGIApp()
new_app = UnicornMiddleware(app, some_config="rainbow")
```
โœ‹๏ธ FastAPI (๐Ÿค™ ๐Ÿ’ƒ) ๐Ÿšš ๐Ÿ™… ๐ŸŒŒ โšซ๏ธ ๐Ÿ‘ˆ โš’ ๐Ÿ’ญ ๐Ÿ‘ˆ ๐Ÿ”— ๐Ÿ› ๏ธ ๐Ÿต ๐Ÿ’ฝ โŒ &amp; ๐Ÿ›ƒ โš  ๐Ÿ•โ€๐Ÿฆบ ๐Ÿ‘ท โ˜‘.
๐Ÿ‘ˆ, ๐Ÿ‘† โš™๏ธ `app.add_middleware()` (๐Ÿ–ผ โšœ).
```Python
from fastapi import FastAPI
from unicorn import UnicornMiddleware
app = FastAPI()
app.add_middleware(UnicornMiddleware, some_config="rainbow")
```
`app.add_middleware()` ๐Ÿ“จ ๐Ÿ› ๏ธ ๐ŸŽ“ ๐Ÿฅ‡ โŒ &amp; ๐Ÿ™† ๐ŸŒ– โŒ ๐Ÿšถโ€โ™€๏ธ ๐Ÿ› ๏ธ.
## ๐Ÿ› ๏ธ ๐Ÿ› ๏ธ
**FastAPI** ๐Ÿ”Œ ๐Ÿ“š ๐Ÿ› ๏ธ โš  โš™๏ธ ๐Ÿ’ผ, ๐Ÿ‘ฅ ๐Ÿ”œ ๐Ÿ‘€ โญ โ” โš™๏ธ ๐Ÿ‘ซ.
!!! note "๐Ÿ“ก โ„น"
โญ ๐Ÿ–ผ, ๐Ÿ‘† ๐Ÿ’ช โš™๏ธ `from starlette.middleware.something import SomethingMiddleware`.
**FastAPI** ๐Ÿšš ๐Ÿ“š ๐Ÿ› ๏ธ `fastapi.middleware` ๐Ÿช ๐Ÿ‘†, ๐Ÿ‘ฉโ€๐Ÿ’ป. โœ‹๏ธ ๐ŸŒ… ๐Ÿ’ช ๐Ÿ› ๏ธ ๐Ÿ‘Ÿ ๐Ÿ”— โšช๏ธโžก๏ธ ๐Ÿ’ƒ.
## `HTTPSRedirectMiddleware`
๐Ÿ› ๏ธ ๐Ÿ‘ˆ ๐ŸŒ ๐Ÿ“จ ๐Ÿ“จ ๐Ÿ”œ ๐Ÿ‘ฏโ€โ™‚๏ธ `https` โš–๏ธ `wss`.
๐Ÿ™† ๐Ÿ“จ ๐Ÿ“จ `http` โš–๏ธ `ws` ๐Ÿ”œ โŽ ๐Ÿ” โš– โ†ฉ๏ธ.
```Python hl_lines="2 6"
{!../../../docs_src/advanced_middleware/tutorial001.py!}
```
## `TrustedHostMiddleware`
๐Ÿ› ๏ธ ๐Ÿ‘ˆ ๐ŸŒ ๐Ÿ“จ ๐Ÿ“จ โœ”๏ธ โ˜‘ โš’ `Host` ๐ŸŽš, โœ” ๐Ÿ’‚โ€โ™‚ ๐Ÿ›ก ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ” ๐Ÿฆ  ๐ŸŽš ๐Ÿ‘Š.
```Python hl_lines="2 6-8"
{!../../../docs_src/advanced_middleware/tutorial002.py!}
```
๐Ÿ“„ โŒ ๐Ÿ•โ€๐Ÿฆบ:
* `allowed_hosts` - ๐Ÿ“‡ ๐Ÿ†” ๐Ÿ“› ๐Ÿ‘ˆ ๐Ÿ”œ โœ” ๐Ÿ“›. ๐Ÿƒ ๐Ÿ†” โœ… `*.example.com` ๐Ÿ•โ€๐Ÿฆบ ๐ŸŽ€ ๐Ÿ“. โœ” ๐Ÿ™† ๐Ÿ“› ๐Ÿ‘ฏโ€โ™‚๏ธ โš™๏ธ `allowed_hosts=["*"]` โš–๏ธ ๐Ÿšซ ๐Ÿ› ๏ธ.
๐Ÿšฅ ๐Ÿ“จ ๐Ÿ“จ ๐Ÿ”จ ๐Ÿšซ โœ” โ˜‘ โคด๏ธ `400` ๐Ÿ“จ ๐Ÿ”œ ๐Ÿ“จ.
## `GZipMiddleware`
๐Ÿต ๐Ÿ—œ ๐Ÿ“จ ๐Ÿ™† ๐Ÿ“จ ๐Ÿ‘ˆ ๐Ÿ”Œ `"gzip"` `Accept-Encoding` ๐ŸŽš.
๐Ÿ› ๏ธ ๐Ÿ”œ ๐Ÿต ๐Ÿ‘ฏโ€โ™‚๏ธ ๐Ÿฉ &amp; ๐ŸŽฅ ๐Ÿ“จ.
```Python hl_lines="2 6"
{!../../../docs_src/advanced_middleware/tutorial003.py!}
```
๐Ÿ“„ โŒ ๐Ÿ•โ€๐Ÿฆบ:
* `minimum_size` - ๐Ÿšซ ๐Ÿ—œ ๐Ÿ“จ ๐Ÿ‘ˆ ๐Ÿคช ๐ŸŒ˜ ๐Ÿ‘‰ ๐Ÿ’ฏ ๐Ÿ“ ๐Ÿ”ข. ๐Ÿ”ข `500`.
## ๐ŸŽ ๐Ÿ› ๏ธ
๐Ÿ“ค ๐Ÿ“š ๐ŸŽ ๐Ÿ”ซ ๐Ÿ› ๏ธ.
๐Ÿ–ผ:
* <a href="https://docs.sentry.io/platforms/python/asgi/" class="external-link" target="_blank">๐Ÿ”ซ</a>
* <a href="https://github.com/encode/uvicorn/blob/master/uvicorn/middleware/proxy_headers.py" class="external-link" target="_blank">Uvicorn `ProxyHeadersMiddleware`</a>
* <a href="https://github.com/florimondmanca/msgpack-asgi" class="external-link" target="_blank">๐Ÿ‡ธ๐Ÿ‡ฒ</a>
๐Ÿ‘€ ๐ŸŽ ๐Ÿ’ช ๐Ÿ› ๏ธ โœ… <a href="https://www.starlette.io/middleware/" class="external-link" target="_blank">๐Ÿ’ƒ ๐Ÿ› ๏ธ ๐Ÿฉบ</a> &amp; <a href="https://github.com/florimondmanca/awesome-asgi" class="external-link" target="_blank">๐Ÿ”ซ ๐Ÿ‘Œ ๐Ÿ“‡</a>.

156
docs/em/docs/advanced/nosql-databases.md

@ -0,0 +1,156 @@
# โ˜ (๐Ÿ“Ž / ๐Ÿฆ ๐Ÿ’ฝ) ๐Ÿ’ฝ
**FastAPI** ๐Ÿ’ช ๐Ÿ› ๏ธ โฎ๏ธ ๐Ÿ™† <abbr title="Distributed database (Big Data), also 'Not Only SQL'">โ˜</abbr>.
๐Ÿ“ฅ ๐Ÿ‘ฅ ๐Ÿ”œ ๐Ÿ‘€ ๐Ÿ–ผ โš™๏ธ **<a href="https://www.couchbase.com/" class="external-link" target="_blank">๐Ÿ—„</a>**, <abbr title="Document here refers to a JSON object (a dict), with keys and values, and those values can also be other JSON objects, arrays (lists), numbers, strings, booleans, etc.">๐Ÿ“„</abbr> ๐Ÿงข โ˜ ๐Ÿ’ฝ.
๐Ÿ‘† ๐Ÿ’ช ๐Ÿ› ๏ธ โšซ๏ธ ๐Ÿ™† ๐ŸŽ โ˜ ๐Ÿ’ฝ ๐Ÿ’–:
* **โœณ**
* **๐Ÿ‘ธ**
* **โœณ**
* **๐Ÿ‡ธ๐Ÿ‡ฒ**
* **โœณ**, โ™’๏ธ.
!!! tip
๐Ÿ“ค ๐Ÿ›‚ ๐Ÿ— ๐Ÿš‚ โฎ๏ธ **FastAPI** &amp; **๐Ÿ—„**, ๐ŸŒ โš“๏ธ ๐Ÿ”› **โ˜**, ๐Ÿ”Œ ๐Ÿ•ธ &amp; ๐ŸŒ– ๐Ÿงฐ: <a href="https://github.com/tiangolo/full-stack-fastapi-couchbase" class="external-link" target="_blank">https://github.com/tiangolo/full-stack-fastapi-couchbase</a>
## ๐Ÿ—„ ๐Ÿ—„ ๐Ÿฆฒ
๐Ÿ”œ, ๐Ÿšซ ๐Ÿ’ธ ๐Ÿ™‹ ๐ŸŽ‚, ๐Ÿ•ด ๐Ÿ—„:
```Python hl_lines="3-5"
{!../../../docs_src/nosql_databases/tutorial001.py!}
```
## ๐Ÿ”ฌ ๐Ÿ“‰ โš™๏ธ "๐Ÿ“„ ๐Ÿ†Ž"
๐Ÿ‘ฅ ๐Ÿ”œ โš™๏ธ โšซ๏ธ โช ๐Ÿ”ง ๐Ÿ‘ `type` ๐Ÿ‘† ๐Ÿ“„.
๐Ÿ‘‰ ๐Ÿšซ โœ” ๐Ÿ—„, โœ‹๏ธ ๐Ÿ‘ ๐Ÿ’ก ๐Ÿ‘ˆ ๐Ÿ”œ โ„น ๐Ÿ‘† โฎ๏ธ.
```Python hl_lines="9"
{!../../../docs_src/nosql_databases/tutorial001.py!}
```
## ๐Ÿšฎ ๐Ÿ”ข ๐Ÿคš `Bucket`
**๐Ÿ—„**, ๐Ÿฅก โš’ ๐Ÿ“„, ๐Ÿ‘ˆ ๐Ÿ’ช ๐ŸŽ ๐Ÿ†Ž.
๐Ÿ‘ซ ๐Ÿ›Ž ๐ŸŒ ๐Ÿ”— ๐ŸŽ ๐Ÿˆธ.
๐Ÿ”‘ ๐Ÿ”— ๐Ÿ’ฝ ๐ŸŒ ๐Ÿ”œ "๐Ÿ’ฝ" (๐ŸŽฏ ๐Ÿ’ฝ, ๐Ÿšซ ๐Ÿ’ฝ ๐Ÿ’ฝ).
๐Ÿ”‘ **โœณ** ๐Ÿ”œ "๐Ÿ—ƒ".
๐Ÿ“Ÿ, `Bucket` ๐ŸŽจ ๐Ÿ‘‘ ๐Ÿ‡จ๐Ÿ‡ป ๐Ÿ“ป โฎ๏ธ ๐Ÿ’ฝ.
๐Ÿ‘‰ ๐Ÿš™ ๐Ÿ”ข ๐Ÿ”œ:
* ๐Ÿ”— **๐Ÿ—„** ๐ŸŒ‘ (๐Ÿ‘ˆ ๐Ÿ’ช ๐Ÿ‘ ๐ŸŽฐ).
* โš’ ๐Ÿ”ข โฒ.
* ๐Ÿ”“ ๐ŸŒ‘.
* ๐Ÿคš `Bucket` ๐Ÿ‘.
* โš’ ๐Ÿ”ข โฒ.
* ๐Ÿ“จ โšซ๏ธ.
```Python hl_lines="12-21"
{!../../../docs_src/nosql_databases/tutorial001.py!}
```
## โœ Pydantic ๐Ÿท
**๐Ÿ—„** "๐Ÿ“„" ๐Ÿค™ "๐ŸŽป ๐ŸŽš", ๐Ÿ‘ฅ ๐Ÿ’ช ๐Ÿท ๐Ÿ‘ซ โฎ๏ธ Pydantic.
### `User` ๐Ÿท
๐Ÿฅ‡, โžก๏ธ โœ `User` ๐Ÿท:
```Python hl_lines="24-28"
{!../../../docs_src/nosql_databases/tutorial001.py!}
```
๐Ÿ‘ฅ ๐Ÿ”œ โš™๏ธ ๐Ÿ‘‰ ๐Ÿท ๐Ÿ‘† *โžก ๐Ÿ› ๏ธ ๐Ÿ”ข*,, ๐Ÿ‘ฅ ๐Ÿšซ ๐Ÿ”Œ โšซ๏ธ `hashed_password`.
### `UserInDB` ๐Ÿท
๐Ÿ”œ, โžก๏ธ โœ `UserInDB` ๐Ÿท.
๐Ÿ‘‰ ๐Ÿ”œ โœ”๏ธ ๐Ÿ’ฝ ๐Ÿ‘ˆ ๐Ÿค™ ๐Ÿช ๐Ÿ’ฝ.
๐Ÿ‘ฅ ๐Ÿšซ โœ โšซ๏ธ ๐Ÿฟ Pydantic `BaseModel` โœ‹๏ธ ๐Ÿฟ ๐Ÿ‘† ๐Ÿ‘ `User`, โ†ฉ๏ธ โšซ๏ธ ๐Ÿ”œ โœ”๏ธ ๐ŸŒ ๐Ÿ”ข `User` โž• ๐Ÿ‘ฉโ€โคโ€๐Ÿ‘จ ๐ŸŒ…:
```Python hl_lines="31-33"
{!../../../docs_src/nosql_databases/tutorial001.py!}
```
!!! note
๐Ÿ‘€ ๐Ÿ‘ˆ ๐Ÿ‘ฅ โœ”๏ธ `hashed_password` &amp; `type` ๐Ÿ‘ ๐Ÿ‘ˆ ๐Ÿ”œ ๐Ÿช ๐Ÿ’ฝ.
โœ‹๏ธ โšซ๏ธ ๐Ÿšซ ๐Ÿ• ๐Ÿข `User` ๐Ÿท (1๏ธโƒฃ ๐Ÿ‘ฅ ๐Ÿ”œ ๐Ÿ“จ *โžก ๐Ÿ› ๏ธ*).
## ๐Ÿคš ๐Ÿ‘ฉโ€๐Ÿ’ป
๐Ÿ”œ โœ ๐Ÿ”ข ๐Ÿ‘ˆ ๐Ÿ”œ:
* โœŠ ๐Ÿ†”.
* ๐Ÿ— ๐Ÿ“„ ๐Ÿ†” โšช๏ธโžก๏ธ โšซ๏ธ.
* ๐Ÿคš ๐Ÿ“„ โฎ๏ธ ๐Ÿ‘ˆ ๐Ÿ†”.
* ๐Ÿšฎ ๐ŸŽš ๐Ÿ“„ `UserInDB` ๐Ÿท.
๐Ÿ— ๐Ÿ”ข ๐Ÿ‘ˆ ๐Ÿ•ด ๐Ÿ’ก ๐Ÿคš ๐Ÿ‘† ๐Ÿ‘ฉโ€๐Ÿ’ป โšช๏ธโžก๏ธ `username` (โš–๏ธ ๐Ÿ™† ๐ŸŽ ๐Ÿ”ข) ๐Ÿ”ฌ ๐Ÿ‘† *โžก ๐Ÿ› ๏ธ ๐Ÿ”ข*, ๐Ÿ‘† ๐Ÿ’ช ๐ŸŒ– ๐Ÿ’ช ๐Ÿค-โš™๏ธ โšซ๏ธ ๐Ÿ’— ๐Ÿ• &amp; ๐Ÿšฎ <abbr title="Automated test, written in code, that checks if another piece of code is working correctly.">โš’ ๐Ÿ’ฏ</abbr> โšซ๏ธ:
```Python hl_lines="36-42"
{!../../../docs_src/nosql_databases/tutorial001.py!}
```
### โ“‚-๐ŸŽป
๐Ÿšฅ ๐Ÿ‘† ๐Ÿšซ ๐Ÿ˜ฐ โฎ๏ธ `f"userprofile::{username}"`, โšซ๏ธ ๐Ÿ "<a href="https://docs.python.org/3/glossary.html#term-f-string" class="external-link" target="_blank">โ“‚-๐ŸŽป</a>".
๐Ÿ™† ๐Ÿ”ข ๐Ÿ‘ˆ ๐Ÿšฎ ๐Ÿ”˜ `{}` โ“‚-๐ŸŽป ๐Ÿ”œ โ†” / ๐Ÿ’‰ ๐ŸŽป.
### `dict` ๐Ÿ—
๐Ÿšฅ ๐Ÿ‘† ๐Ÿšซ ๐Ÿ˜ฐ โฎ๏ธ `UserInDB(**result.value)`, <a href="https://docs.python.org/3/glossary.html#term-argument" class="external-link" target="_blank">โšซ๏ธ โš™๏ธ `dict` "๐Ÿ—"</a>.
โšซ๏ธ ๐Ÿ”œ โœŠ `dict` `result.value`, &amp; โœŠ ๐Ÿ”  ๐Ÿšฎ ๐Ÿ”‘ &amp; ๐Ÿ’ฒ &amp; ๐Ÿšถโ€โ™€๏ธ ๐Ÿ‘ซ ๐Ÿ”‘-๐Ÿ’ฒ `UserInDB` ๐Ÿ‡จ๐Ÿ‡ป โŒ.
, ๐Ÿšฅ `dict` ๐Ÿ”Œ:
```Python
{
"username": "johndoe",
"hashed_password": "some_hash",
}
```
โšซ๏ธ ๐Ÿ”œ ๐Ÿšถโ€โ™€๏ธ `UserInDB` :
```Python
UserInDB(username="johndoe", hashed_password="some_hash")
```
## โœ ๐Ÿ‘† **FastAPI** ๐Ÿ“Ÿ
### โœ `FastAPI` ๐Ÿ“ฑ
```Python hl_lines="46"
{!../../../docs_src/nosql_databases/tutorial001.py!}
```
### โœ *โžก ๐Ÿ› ๏ธ ๐Ÿ”ข*
๐Ÿ‘† ๐Ÿ“Ÿ ๐Ÿค™ ๐Ÿ—„ &amp; ๐Ÿ‘ฅ ๐Ÿšซ โš™๏ธ <a href="https://docs.couchbase.com/python-sdk/2.5/async-programming.html#asyncio-python-3-5" class="external-link" target="_blank">๐Ÿฅผ ๐Ÿ <code>await</code> ๐Ÿ•โ€๐Ÿฆบ</a>, ๐Ÿ‘ฅ ๐Ÿ”œ ๐Ÿ“ฃ ๐Ÿ‘† ๐Ÿ”ข โฎ๏ธ ๐Ÿ˜ `def` โ†ฉ๏ธ `async def`.
, ๐Ÿ—„ ๐Ÿ‘ ๐Ÿšซ โš™๏ธ ๐Ÿ‘ `Bucket` ๐ŸŽš ๐Ÿ’— "<abbr title="A sequence of code being executed by the program, while at the same time, or at intervals, there can be others being executed too.">๐Ÿงต</abbr>โ“‚",, ๐Ÿ‘ฅ ๐Ÿ’ช ๐Ÿคš ๐Ÿฅก ๐Ÿ”— &amp; ๐Ÿšถโ€โ™€๏ธ โšซ๏ธ ๐Ÿ‘† ๐Ÿš™ ๐Ÿ”ข:
```Python hl_lines="49-53"
{!../../../docs_src/nosql_databases/tutorial001.py!}
```
## ๐ŸŒƒ
๐Ÿ‘† ๐Ÿ’ช ๐Ÿ› ๏ธ ๐Ÿ™† ๐Ÿฅ‰ ๐Ÿฅณ โ˜ ๐Ÿ’ฝ, โš™๏ธ ๐Ÿ‘ซ ๐Ÿฉ ๐Ÿ“ฆ.
๐ŸŽ โœ” ๐Ÿ™† ๐ŸŽ ๐Ÿ”ข ๐Ÿงฐ, โš™๏ธ โš–๏ธ ๐Ÿ› ๏ธ.

179
docs/em/docs/advanced/openapi-callbacks.md

@ -0,0 +1,179 @@
# ๐Ÿ—„ โฒ
๐Ÿ‘† ๐Ÿ’ช โœ ๐Ÿ› ๏ธ โฎ๏ธ *โžก ๐Ÿ› ๏ธ* ๐Ÿ‘ˆ ๐Ÿ’ช โฒ ๐Ÿ“จ *๐Ÿ”ข ๐Ÿ› ๏ธ* โœ ๐Ÿ‘ฑ ๐Ÿ™† (๐ŸŽฒ ๐ŸŽ ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ‘ˆ ๐Ÿ”œ *โš™๏ธ* ๐Ÿ‘† ๐Ÿ› ๏ธ).
๐Ÿ› ๏ธ ๐Ÿ‘ˆ ๐Ÿ”จ ๐Ÿ•โ” ๐Ÿ‘† ๐Ÿ› ๏ธ ๐Ÿ“ฑ ๐Ÿค™ *๐Ÿ”ข ๐Ÿ› ๏ธ* ๐Ÿ“› "โฒ". โ†ฉ๏ธ ๐Ÿ–ฅ ๐Ÿ‘ˆ ๐Ÿ”ข ๐Ÿ‘ฉโ€๐Ÿ’ป โœ ๐Ÿ“จ ๐Ÿ“จ ๐Ÿ‘† ๐Ÿ› ๏ธ &amp; โคด๏ธ ๐Ÿ‘† ๐Ÿ› ๏ธ *๐Ÿค™ ๐Ÿ”™*, ๐Ÿ“จ ๐Ÿ“จ *๐Ÿ”ข ๐Ÿ› ๏ธ* (๐Ÿ‘ˆ ๐ŸŽฒ โœ ๐ŸŽ ๐Ÿ‘ฉโ€๐Ÿ’ป).
๐Ÿ‘‰ ๐Ÿ’ผ, ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ’š ๐Ÿ“„ โ” ๐Ÿ‘ˆ ๐Ÿ”ข ๐Ÿ› ๏ธ *๐Ÿ”œ* ๐Ÿ‘€ ๐Ÿ’–. โšซ๏ธโ” *โžก ๐Ÿ› ๏ธ* โšซ๏ธ ๐Ÿ”œ โœ”๏ธ, โšซ๏ธโ” ๐Ÿ’ช โšซ๏ธ ๐Ÿ”œ โŒ›, โšซ๏ธโ” ๐Ÿ“จ โšซ๏ธ ๐Ÿ”œ ๐Ÿ“จ, โ™’๏ธ.
## ๐Ÿ“ฑ โฎ๏ธ โฒ
โžก๏ธ ๐Ÿ‘€ ๐ŸŒ ๐Ÿ‘‰ โฎ๏ธ ๐Ÿ–ผ.
๐ŸŒˆ ๐Ÿ‘† ๐Ÿ› ๏ธ ๐Ÿ“ฑ ๐Ÿ‘ˆ โœ” ๐Ÿ— ๐Ÿงพ.
๐Ÿ‘‰ ๐Ÿงพ ๐Ÿ”œ โœ”๏ธ `id`, `title` (๐Ÿ“ฆ), `customer`, &amp; `total`.
๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ‘† ๐Ÿ› ๏ธ (๐Ÿ”ข ๐Ÿ‘ฉโ€๐Ÿ’ป) ๐Ÿ”œ โœ ๐Ÿงพ ๐Ÿ‘† ๐Ÿ› ๏ธ โฎ๏ธ ๐Ÿค ๐Ÿ“จ.
โคด๏ธ ๐Ÿ‘† ๐Ÿ› ๏ธ ๐Ÿ”œ (โžก๏ธ ๐ŸŒˆ):
* ๐Ÿ“จ ๐Ÿงพ ๐Ÿ•ด ๐Ÿ”ข ๐Ÿ‘ฉโ€๐Ÿ’ป.
* ๐Ÿ“ˆ ๐Ÿ’ธ.
* ๐Ÿ“จ ๐Ÿ“จ ๐Ÿ”™ ๐Ÿ› ๏ธ ๐Ÿ‘ฉโ€๐Ÿ’ป (๐Ÿ”ข ๐Ÿ‘ฉโ€๐Ÿ’ป).
* ๐Ÿ‘‰ ๐Ÿ”œ ๐Ÿ”จ ๐Ÿ“จ ๐Ÿค ๐Ÿ“จ (โšช๏ธโžก๏ธ *๐Ÿ‘† ๐Ÿ› ๏ธ*) *๐Ÿ”ข ๐Ÿ› ๏ธ* ๐Ÿšš ๐Ÿ‘ˆ ๐Ÿ”ข ๐Ÿ‘ฉโ€๐Ÿ’ป (๐Ÿ‘‰ "โฒ").
## ๐Ÿ˜ **FastAPI** ๐Ÿ“ฑ
โžก๏ธ ๐Ÿฅ‡ ๐Ÿ‘€ โ” ๐Ÿ˜ ๐Ÿ› ๏ธ ๐Ÿ“ฑ ๐Ÿ”œ ๐Ÿ‘€ ๐Ÿ’– โญ โŽ โฒ.
โšซ๏ธ ๐Ÿ”œ โœ”๏ธ *โžก ๐Ÿ› ๏ธ* ๐Ÿ‘ˆ ๐Ÿ”œ ๐Ÿ“จ `Invoice` ๐Ÿ’ช, &amp; ๐Ÿ”ข ๐Ÿ”ข `callback_url` ๐Ÿ‘ˆ ๐Ÿ”œ ๐Ÿ”Œ ๐Ÿ“› โฒ.
๐Ÿ‘‰ ๐Ÿ• ๐Ÿ“ถ ๐Ÿ˜, ๐ŸŒ… ๐Ÿ“Ÿ ๐ŸŽฒ โช ๐Ÿ˜ฐ ๐Ÿ‘†:
```Python hl_lines="9-13 36-53"
{!../../../docs_src/openapi_callbacks/tutorial001.py!}
```
!!! tip
`callback_url` ๐Ÿ”ข ๐Ÿ”ข โš™๏ธ Pydantic <a href="https://pydantic-docs.helpmanual.io/usage/types/#urls" class="external-link" target="_blank">๐Ÿ“›</a> ๐Ÿ†Ž.
๐Ÿ•ด ๐Ÿ†• ๐Ÿ‘œ `callbacks=messages_callback_router.routes` โŒ *โžก ๐Ÿ› ๏ธ ๐Ÿ‘จโ€๐ŸŽจ*. ๐Ÿ‘ฅ ๐Ÿ”œ ๐Ÿ‘€ โšซ๏ธโ” ๐Ÿ‘ˆ โญ.
## ๐Ÿ”ฌ โฒ
โ˜‘ โฒ ๐Ÿ“Ÿ ๐Ÿ”œ ๐Ÿช€ ๐Ÿ™‡ ๐Ÿ”› ๐Ÿ‘† ๐Ÿ‘ ๐Ÿ› ๏ธ ๐Ÿ“ฑ.
&amp; โšซ๏ธ ๐Ÿ”œ ๐ŸŽฒ ๐Ÿช€ ๐Ÿ“š โšช๏ธโžก๏ธ 1๏ธโƒฃ ๐Ÿ“ฑ โญ.
โšซ๏ธ ๐Ÿ’ช 1๏ธโƒฃ โš–๏ธ 2๏ธโƒฃ โธ ๐Ÿ“Ÿ, ๐Ÿ’–:
```Python
callback_url = "https://example.com/api/v1/invoices/events/"
httpx.post(callback_url, json={"description": "Invoice paid", "paid": True})
```
โœ‹๏ธ ๐ŸŽฒ ๐Ÿ† โš  ๐Ÿ• โฒ โš’ ๐Ÿ’ญ ๐Ÿ‘ˆ ๐Ÿ‘† ๐Ÿ› ๏ธ ๐Ÿ‘ฉโ€๐Ÿ’ป (๐Ÿ”ข ๐Ÿ‘ฉโ€๐Ÿ’ป) ๐Ÿ› ๏ธ *๐Ÿ”ข ๐Ÿ› ๏ธ* โ˜‘, ๐Ÿ›„ ๐Ÿ’ฝ ๐Ÿ‘ˆ *๐Ÿ‘† ๐Ÿ› ๏ธ* ๐Ÿ”œ ๐Ÿ“จ ๐Ÿ“จ ๐Ÿ’ช โฒ, โ™’๏ธ.
, โšซ๏ธโ” ๐Ÿ‘ฅ ๐Ÿ”œ โญ ๐Ÿšฎ ๐Ÿ“Ÿ ๐Ÿ“„ โ” ๐Ÿ‘ˆ *๐Ÿ”ข ๐Ÿ› ๏ธ* ๐Ÿ”œ ๐Ÿ‘€ ๐Ÿ’– ๐Ÿ“จ โฒ โšช๏ธโžก๏ธ *๐Ÿ‘† ๐Ÿ› ๏ธ*.
๐Ÿ‘ˆ ๐Ÿงพ ๐Ÿ”œ ๐ŸŽฆ ๐Ÿ†™ ๐Ÿฆ ๐ŸŽš `/docs` ๐Ÿ‘† ๐Ÿ› ๏ธ, &amp; โšซ๏ธ ๐Ÿ”œ โžก๏ธ ๐Ÿ”ข ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ’ญ โ” ๐Ÿ— *๐Ÿ”ข ๐Ÿ› ๏ธ*.
๐Ÿ‘‰ ๐Ÿ–ผ ๐Ÿšซ ๐Ÿ› ๏ธ โฒ โšซ๏ธ (๐Ÿ‘ˆ ๐Ÿ’ช โธ ๐Ÿ“Ÿ), ๐Ÿ•ด ๐Ÿงพ ๐Ÿ•.
!!! tip
โ˜‘ โฒ ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ” ๐Ÿ“จ.
๐Ÿ•โ” ๐Ÿ› ๏ธ โฒ ๐Ÿ‘†, ๐Ÿ‘† ๐Ÿ’ช โš™๏ธ ๐Ÿ•ณ ๐Ÿ’– <a href="https://www.python-httpx.org" class="external-link" target="_blank">๐Ÿ‡ธ๐Ÿ‡ฒ</a> โš–๏ธ <a href="https://requests.readthedocs.io/" class="external-link" target="_blank">๐Ÿ“จ</a>.
## โœ โฒ ๐Ÿงพ ๐Ÿ“Ÿ
๐Ÿ‘‰ ๐Ÿ“Ÿ ๐Ÿ† ๐Ÿšซ ๐Ÿ› ๏ธ ๐Ÿ‘† ๐Ÿ“ฑ, ๐Ÿ‘ฅ ๐Ÿ•ด ๐Ÿ’ช โšซ๏ธ *๐Ÿ“„* โ” ๐Ÿ‘ˆ *๐Ÿ”ข ๐Ÿ› ๏ธ* ๐Ÿ”œ ๐Ÿ‘€ ๐Ÿ’–.
โœ‹๏ธ, ๐Ÿ‘† โช ๐Ÿ’ญ โ” ๐Ÿ’ช โœ ๐Ÿง ๐Ÿงพ ๐Ÿ› ๏ธ โฎ๏ธ **FastAPI**.
๐Ÿ‘ฅ ๐Ÿ”œ โš™๏ธ ๐Ÿ‘ˆ ๐ŸŽ ๐Ÿ’ก ๐Ÿ“„ โ” *๐Ÿ”ข ๐Ÿ› ๏ธ* ๐Ÿ”œ ๐Ÿ‘€ ๐Ÿ’–... ๐Ÿ— *โžก ๐Ÿ› ๏ธ(โ“‚)* ๐Ÿ‘ˆ ๐Ÿ”ข ๐Ÿ› ๏ธ ๐Ÿ”œ ๐Ÿ› ๏ธ (๐Ÿ• ๐Ÿ‘† ๐Ÿ› ๏ธ ๐Ÿ”œ ๐Ÿค™).
!!! tip
๐Ÿ•โ” โœ ๐Ÿ“Ÿ ๐Ÿ“„ โฒ, โšซ๏ธ ๐Ÿ’ช โš  ๐ŸŒˆ ๐Ÿ‘ˆ ๐Ÿ‘† ๐Ÿ‘ˆ *๐Ÿ”ข ๐Ÿ‘ฉโ€๐Ÿ’ป*. &amp; ๐Ÿ‘ˆ ๐Ÿ‘† โณ ๐Ÿ› ๏ธ *๐Ÿ”ข ๐Ÿ› ๏ธ*, ๐Ÿšซ *๐Ÿ‘† ๐Ÿ› ๏ธ*.
๐Ÿ• ๐Ÿ› ๏ธ ๐Ÿ‘‰ โ˜ ๐ŸŽ‘ ( *๐Ÿ”ข ๐Ÿ‘ฉโ€๐Ÿ’ป*) ๐Ÿ’ช โ„น ๐Ÿ‘† ๐Ÿ’ญ ๐Ÿ’– โšซ๏ธ ๐ŸŒ… โญ ๐ŸŒโ” ๐Ÿšฎ ๐Ÿ”ข, Pydantic ๐Ÿท ๐Ÿ’ช, ๐Ÿ“จ, โ™’๏ธ. ๐Ÿ‘ˆ *๐Ÿ”ข ๐Ÿ› ๏ธ*.
### โœ โฒ `APIRouter`
๐Ÿฅ‡ โœ ๐Ÿ†• `APIRouter` ๐Ÿ‘ˆ ๐Ÿ”œ ๐Ÿ”Œ 1๏ธโƒฃ โš–๏ธ ๐ŸŒ… โฒ.
```Python hl_lines="3 25"
{!../../../docs_src/openapi_callbacks/tutorial001.py!}
```
### โœ โฒ *โžก ๐Ÿ› ๏ธ*
โœ โฒ *โžก ๐Ÿ› ๏ธ* โš™๏ธ ๐ŸŽ `APIRouter` ๐Ÿ‘† โœ ๐Ÿ”›.
โšซ๏ธ ๐Ÿ”œ ๐Ÿ‘€ ๐Ÿ’– ๐Ÿ˜ FastAPI *โžก ๐Ÿ› ๏ธ*:
* โšซ๏ธ ๐Ÿ”œ ๐ŸŽฒ โœ”๏ธ ๐Ÿ“„ ๐Ÿ’ช โšซ๏ธ ๐Ÿ”œ ๐Ÿ“จ, โœ… `body: InvoiceEvent`.
* &amp; โšซ๏ธ ๐Ÿ’ช โœ”๏ธ ๐Ÿ“„ ๐Ÿ“จ โšซ๏ธ ๐Ÿ”œ ๐Ÿ“จ, โœ… `response_model=InvoiceEventReceived`.
```Python hl_lines="16-18 21-22 28-32"
{!../../../docs_src/openapi_callbacks/tutorial001.py!}
```
๐Ÿ“ค 2๏ธโƒฃ ๐Ÿ‘‘ ๐Ÿ”บ โšช๏ธโžก๏ธ ๐Ÿ˜ *โžก ๐Ÿ› ๏ธ*:
* โšซ๏ธ ๐Ÿšซ ๐Ÿ’ช โœ”๏ธ ๐Ÿ™† โ˜‘ ๐Ÿ“Ÿ, โ†ฉ๏ธ ๐Ÿ‘† ๐Ÿ“ฑ ๐Ÿ”œ ๐Ÿ™… ๐Ÿค™ ๐Ÿ‘‰ ๐Ÿ“Ÿ. โšซ๏ธ ๐Ÿ•ด โš™๏ธ ๐Ÿ“„ *๐Ÿ”ข ๐Ÿ› ๏ธ*. , ๐Ÿ”ข ๐Ÿ’ช โœ”๏ธ `pass`.
* *โžก* ๐Ÿ’ช ๐Ÿ”Œ <a href="https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#key-expression" class="external-link" target="_blank">๐Ÿ—„ 3๏ธโƒฃ ๐Ÿงฌ</a> (๐Ÿ‘€ ๐ŸŒ– ๐Ÿ”›) ๐ŸŒโ” โšซ๏ธ ๐Ÿ’ช โš™๏ธ ๐Ÿ”ข โฎ๏ธ ๐Ÿ”ข &amp; ๐Ÿ• โฎ๏ธ ๐Ÿ“จ ๐Ÿ“จ *๐Ÿ‘† ๐Ÿ› ๏ธ*.
### โฒ โžก ๐Ÿงฌ
โฒ *โžก* ๐Ÿ’ช โœ”๏ธ <a href="https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#key-expression" class="external-link" target="_blank">๐Ÿ—„ 3๏ธโƒฃ ๐Ÿงฌ</a> ๐Ÿ‘ˆ ๐Ÿ’ช ๐Ÿ”Œ ๐Ÿ• โฎ๏ธ ๐Ÿ“จ ๐Ÿ“จ *๐Ÿ‘† ๐Ÿ› ๏ธ*.
๐Ÿ‘‰ ๐Ÿ’ผ, โšซ๏ธ `str`:
```Python
"{$callback_url}/invoices/{$request.body.id}"
```
, ๐Ÿšฅ ๐Ÿ‘† ๐Ÿ› ๏ธ ๐Ÿ‘ฉโ€๐Ÿ’ป (๐Ÿ”ข ๐Ÿ‘ฉโ€๐Ÿ’ป) ๐Ÿ“จ ๐Ÿ“จ *๐Ÿ‘† ๐Ÿ› ๏ธ* :
```
https://yourapi.com/invoices/?callback_url=https://www.external.org/events
```
โฎ๏ธ ๐ŸŽป ๐Ÿ’ช:
```JSON
{
"id": "2expen51ve",
"customer": "Mr. Richie Rich",
"total": "9999"
}
```
โคด๏ธ *๐Ÿ‘† ๐Ÿ› ๏ธ* ๐Ÿ”œ ๐Ÿ› ๏ธ ๐Ÿงพ, &amp; โ˜ โช, ๐Ÿ“จ โฒ ๐Ÿ“จ `callback_url` ( *๐Ÿ”ข ๐Ÿ› ๏ธ*):
```
https://www.external.org/events/invoices/2expen51ve
```
โฎ๏ธ ๐ŸŽป ๐Ÿ’ช โš— ๐Ÿ•ณ ๐Ÿ’–:
```JSON
{
"description": "Payment celebration",
"paid": true
}
```
&amp; โšซ๏ธ ๐Ÿ”œ โŒ› ๐Ÿ“จ โšช๏ธโžก๏ธ ๐Ÿ‘ˆ *๐Ÿ”ข ๐Ÿ› ๏ธ* โฎ๏ธ ๐ŸŽป ๐Ÿ’ช ๐Ÿ’–:
```JSON
{
"ok": true
}
```
!!! tip
๐Ÿ‘€ โ” โฒ ๐Ÿ“› โš™๏ธ ๐Ÿ”Œ ๐Ÿ“› ๐Ÿ“จ ๐Ÿ”ข ๐Ÿ”ข `callback_url` (`https://www.external.org/events`) &amp; ๐Ÿงพ `id` โšช๏ธโžก๏ธ ๐Ÿ”˜ ๐ŸŽป ๐Ÿ’ช (`2expen51ve`).
### ๐Ÿšฎ โฒ ๐Ÿ“ป
๐Ÿ‘‰ โ˜ ๐Ÿ‘† โœ”๏ธ *โฒ โžก ๐Ÿ› ๏ธ(โ“‚)* ๐Ÿ’ช (1๏ธโƒฃ(โ“‚) ๐Ÿ‘ˆ *๐Ÿ”ข ๐Ÿ‘ฉโ€๐Ÿ’ป* ๐Ÿ”œ ๐Ÿ› ๏ธ *๐Ÿ”ข ๐Ÿ› ๏ธ*) โฒ ๐Ÿ“ป ๐Ÿ‘† โœ ๐Ÿ”›.
๐Ÿ”œ โš™๏ธ ๐Ÿ”ข `callbacks` *๐Ÿ‘† ๐Ÿ› ๏ธ โžก ๐Ÿ› ๏ธ ๐Ÿ‘จโ€๐ŸŽจ* ๐Ÿšถโ€โ™€๏ธ ๐Ÿ”ข `.routes` (๐Ÿ‘ˆ ๐Ÿค™ `list` ๐Ÿ›ฃ/*โžก ๐Ÿ› ๏ธ*) โšช๏ธโžก๏ธ ๐Ÿ‘ˆ โฒ ๐Ÿ“ป:
```Python hl_lines="35"
{!../../../docs_src/openapi_callbacks/tutorial001.py!}
```
!!! tip
๐Ÿ‘€ ๐Ÿ‘ˆ ๐Ÿ‘† ๐Ÿšซ ๐Ÿšถโ€โ™€๏ธ ๐Ÿ“ป โšซ๏ธ (`invoices_callback_router`) `callback=`, โœ‹๏ธ ๐Ÿ”ข `.routes`, `invoices_callback_router.routes`.
### โœ… ๐Ÿฉบ
๐Ÿ”œ ๐Ÿ‘† ๐Ÿ’ช โ–ถ๏ธ ๐Ÿ‘† ๐Ÿ“ฑ โฎ๏ธ Uvicorn &amp; ๐Ÿšถ <a href="http://127.0.0.1:8000/docs" class="external-link" target="_blank">http://127.0.0.1:8000/docs</a>.
๐Ÿ‘† ๐Ÿ”œ ๐Ÿ‘€ ๐Ÿ‘† ๐Ÿฉบ โœ… "โฒ" ๐Ÿ“„ ๐Ÿ‘† *โžก ๐Ÿ› ๏ธ* ๐Ÿ‘ˆ ๐ŸŽฆ โ” *๐Ÿ”ข ๐Ÿ› ๏ธ* ๐Ÿ”œ ๐Ÿ‘€ ๐Ÿ’–:
<img src="/img/tutorial/openapi-callbacks/image01.png">

170
docs/em/docs/advanced/path-operation-advanced-configuration.md

@ -0,0 +1,170 @@
# โžก ๐Ÿ› ๏ธ ๐Ÿง ๐Ÿ“ณ
## ๐Ÿ—„ {
!!! warning
๐Ÿšฅ ๐Ÿ‘† ๐Ÿšซ "๐Ÿ•ด" ๐Ÿ—„, ๐Ÿ‘† ๐ŸŽฒ ๐Ÿšซ ๐Ÿ’ช ๐Ÿ‘‰.
๐Ÿ‘† ๐Ÿ’ช โš’ ๐Ÿ—„ `operationId` โš™๏ธ ๐Ÿ‘† *โžก ๐Ÿ› ๏ธ* โฎ๏ธ ๐Ÿ”ข `operation_id`.
๐Ÿ‘† ๐Ÿ”œ โœ”๏ธ โš’ ๐Ÿ’ญ ๐Ÿ‘ˆ โšซ๏ธ ๐Ÿ˜ ๐Ÿ”  ๐Ÿ› ๏ธ.
```Python hl_lines="6"
{!../../../docs_src/path_operation_advanced_configuration/tutorial001.py!}
```
### โš™๏ธ *โžก ๐Ÿ› ๏ธ ๐Ÿ”ข* ๐Ÿ“› {
๐Ÿšฅ ๐Ÿ‘† ๐Ÿ’š โš™๏ธ ๐Ÿ‘† ๐Ÿ”—' ๐Ÿ”ข ๐Ÿ“› `operationId`โ“‚, ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ” ๐Ÿคญ ๐ŸŒ ๐Ÿ‘ซ &amp; ๐Ÿ” ๐Ÿ”  *โžก ๐Ÿ› ๏ธ* `operation_id` โš™๏ธ ๐Ÿ‘ซ `APIRoute.name`.
๐Ÿ‘† ๐Ÿ”œ โšซ๏ธ โฎ๏ธ โŽ ๐ŸŒ ๐Ÿ‘† *โžก ๐Ÿ› ๏ธ*.
```Python hl_lines="2 12-21 24"
{!../../../docs_src/path_operation_advanced_configuration/tutorial002.py!}
```
!!! tip
๐Ÿšฅ ๐Ÿ‘† โŽ ๐Ÿค™ `app.openapi()`, ๐Ÿ‘† ๐Ÿ”œ โ„น `operationId`โ“‚ โญ ๐Ÿ‘ˆ.
!!! warning
๐Ÿšฅ ๐Ÿ‘† ๐Ÿ‘‰, ๐Ÿ‘† โœ”๏ธ โš’ ๐Ÿ’ญ ๐Ÿ”  1๏ธโƒฃ ๐Ÿ‘† *โžก ๐Ÿ› ๏ธ ๐Ÿ”ข* โœ”๏ธ ๐Ÿ˜ ๐Ÿ“›.
๐Ÿšฅ ๐Ÿ‘ซ ๐ŸŽ ๐Ÿ•น (๐Ÿ ๐Ÿ“).
## ๐Ÿšซ โšช๏ธโžก๏ธ ๐Ÿ—„
๐Ÿšซ *โžก ๐Ÿ› ๏ธ* โšช๏ธโžก๏ธ ๐Ÿ— ๐Ÿ—„ ๐Ÿ”— (&amp; โžก๏ธ, โšช๏ธโžก๏ธ ๐Ÿง ๐Ÿงพ โš™๏ธ), โš™๏ธ ๐Ÿ”ข `include_in_schema` &amp; โš’ โšซ๏ธ `False`:
```Python hl_lines="6"
{!../../../docs_src/path_operation_advanced_configuration/tutorial003.py!}
```
## ๐Ÿง ๐Ÿ“› โšช๏ธโžก๏ธ #๏ธโƒฃ
๐Ÿ‘† ๐Ÿ’ช ๐Ÿ“‰ โธ โš™๏ธ โšช๏ธโžก๏ธ #๏ธโƒฃ *โžก ๐Ÿ› ๏ธ ๐Ÿ”ข* ๐Ÿ—„.
โŽ `\f` (๐Ÿ˜– "๐Ÿ“จ ๐Ÿผ" ๐Ÿฆน) ๐Ÿค• **FastAPI** ๐Ÿ” ๐Ÿ”ข โš™๏ธ ๐Ÿ—„ ๐Ÿ‘‰ โ˜.
โšซ๏ธ ๐Ÿ† ๐Ÿšซ ๐ŸŽฆ ๐Ÿ†™ ๐Ÿงพ, โœ‹๏ธ ๐ŸŽ ๐Ÿงฐ (โœ… ๐Ÿ‰) ๐Ÿ”œ ๐Ÿ’ช โš™๏ธ ๐ŸŽ‚.
```Python hl_lines="19-29"
{!../../../docs_src/path_operation_advanced_configuration/tutorial004.py!}
```
## ๐ŸŒ– ๐Ÿ“จ
๐Ÿ‘† ๐ŸŽฒ โœ”๏ธ ๐Ÿ‘€ โ” ๐Ÿ“ฃ `response_model` &amp; `status_code` *โžก ๐Ÿ› ๏ธ*.
๐Ÿ‘ˆ ๐Ÿ”ฌ ๐Ÿ—ƒ ๐Ÿ”ƒ ๐Ÿ‘‘ ๐Ÿ“จ *โžก ๐Ÿ› ๏ธ*.
๐Ÿ‘† ๐Ÿ’ช ๐Ÿ“ฃ ๐ŸŒ– ๐Ÿ“จ โฎ๏ธ ๐Ÿ‘ซ ๐Ÿท, ๐Ÿ‘” ๐Ÿ“Ÿ, โ™’๏ธ.
๐Ÿ“ค ๐ŸŽ‚ ๐Ÿ“ƒ ๐Ÿ“ฅ ๐Ÿงพ ๐Ÿ”ƒ โšซ๏ธ, ๐Ÿ‘† ๐Ÿ’ช โœ โšซ๏ธ [๐ŸŒ– ๐Ÿ“จ ๐Ÿ—„](./additional-responses.md){.internal-link target=_blank}.
## ๐Ÿ—„ โž•
๐Ÿ•โ” ๐Ÿ‘† ๐Ÿ“ฃ *โžก ๐Ÿ› ๏ธ* ๐Ÿ‘† ๐Ÿˆธ, **FastAPI** ๐Ÿ” ๐Ÿ— ๐Ÿ”— ๐Ÿ—ƒ ๐Ÿ”ƒ ๐Ÿ‘ˆ *โžก ๐Ÿ› ๏ธ* ๐Ÿ”Œ ๐Ÿ—„ ๐Ÿ”—.
!!! note "๐Ÿ“ก โ„น"
๐Ÿ—„ ๐Ÿ”ง โšซ๏ธ ๐Ÿค™ <a href="https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#operation-object" class="external-link" target="_blank">๐Ÿ› ๏ธ ๐ŸŽš</a>.
โšซ๏ธ โœ”๏ธ ๐ŸŒ โ„น ๐Ÿ”ƒ *โžก ๐Ÿ› ๏ธ* &amp; โš™๏ธ ๐Ÿ— ๐Ÿง ๐Ÿงพ.
โšซ๏ธ ๐Ÿ”Œ `tags`, `parameters`, `requestBody`, `responses`, โ™’๏ธ.
๐Ÿ‘‰ *โžก ๐Ÿ› ๏ธ*-๐ŸŽฏ ๐Ÿ—„ ๐Ÿ”— ๐Ÿ›Ž ๐Ÿ— ๐Ÿ” **FastAPI**, โœ‹๏ธ ๐Ÿ‘† ๐Ÿ’ช โ†” โšซ๏ธ.
!!! tip
๐Ÿ‘‰ ๐Ÿ”… ๐ŸŽš โ†” โ˜.
๐Ÿšฅ ๐Ÿ‘† ๐Ÿ•ด ๐Ÿ’ช ๐Ÿ“ฃ ๐ŸŒ– ๐Ÿ“จ, ๐ŸŒ… ๐Ÿช ๐ŸŒŒ โšซ๏ธ โฎ๏ธ [๐ŸŒ– ๐Ÿ“จ ๐Ÿ—„](./additional-responses.md){.internal-link target=_blank}.
๐Ÿ‘† ๐Ÿ’ช โ†” ๐Ÿ—„ ๐Ÿ”— *โžก ๐Ÿ› ๏ธ* โš™๏ธ ๐Ÿ”ข `openapi_extra`.
### ๐Ÿ—„ โ†”
๐Ÿ‘‰ `openapi_extra` ๐Ÿ’ช ๐Ÿ‘, ๐Ÿ–ผ, ๐Ÿ“ฃ [๐Ÿ—„ โ†”](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#specificationExtensions):
```Python hl_lines="6"
{!../../../docs_src/path_operation_advanced_configuration/tutorial005.py!}
```
๐Ÿšฅ ๐Ÿ‘† ๐Ÿ“‚ ๐Ÿง ๐Ÿ› ๏ธ ๐Ÿฉบ, ๐Ÿ‘† โ†” ๐Ÿ”œ ๐ŸŽฆ ๐Ÿ†™ ๐Ÿ” ๐ŸŽฏ *โžก ๐Ÿ› ๏ธ*.
<img src="/img/tutorial/path-operation-advanced-configuration/image01.png">
&amp; ๐Ÿšฅ ๐Ÿ‘† ๐Ÿ‘€ ๐Ÿ“‰ ๐Ÿ—„ ( `/openapi.json` ๐Ÿ‘† ๐Ÿ› ๏ธ), ๐Ÿ‘† ๐Ÿ”œ ๐Ÿ‘€ ๐Ÿ‘† โ†” ๐Ÿ• ๐ŸŽฏ *โžก ๐Ÿ› ๏ธ* ๐Ÿ’โ€โ™‚๏ธ:
```JSON hl_lines="22"
{
"openapi": "3.0.2",
"info": {
"title": "FastAPI",
"version": "0.1.0"
},
"paths": {
"/items/": {
"get": {
"summary": "Read Items",
"operationId": "read_items_items__get",
"responses": {
"200": {
"description": "Successful Response",
"content": {
"application/json": {
"schema": {}
}
}
}
},
"x-aperture-labs-portal": "blue"
}
}
}
}
```
### ๐Ÿ›ƒ ๐Ÿ—„ *โžก ๐Ÿ› ๏ธ* ๐Ÿ”—
๐Ÿ“– `openapi_extra` ๐Ÿ”œ ๐Ÿ™‡ ๐Ÿ”— โฎ๏ธ ๐Ÿ” ๐Ÿ— ๐Ÿ—„ ๐Ÿ”— *โžก ๐Ÿ› ๏ธ*.
, ๐Ÿ‘† ๐Ÿ’ช ๐Ÿšฎ ๐ŸŒ– ๐Ÿ’ฝ ๐Ÿ” ๐Ÿ— ๐Ÿ”—.
๐Ÿ–ผ, ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ’ญ โœ &amp; โœ” ๐Ÿ“จ โฎ๏ธ ๐Ÿ‘† ๐Ÿ‘ ๐Ÿ“Ÿ, ๐Ÿต โš™๏ธ ๐Ÿง โš’ FastAPI โฎ๏ธ Pydantic, โœ‹๏ธ ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ’š ๐Ÿ”ฌ ๐Ÿ“จ ๐Ÿ—„ ๐Ÿ”—.
๐Ÿ‘† ๐Ÿ’ช ๐Ÿ‘ˆ โฎ๏ธ `openapi_extra`:
```Python hl_lines="20-37 39-40"
{!../../../docs_src/path_operation_advanced_configuration/tutorial006.py!}
```
๐Ÿ‘‰ ๐Ÿ–ผ, ๐Ÿ‘ฅ ๐Ÿšซ ๐Ÿ“ฃ ๐Ÿ™† Pydantic ๐Ÿท. ๐Ÿ‘, ๐Ÿ“จ ๐Ÿ’ช ๐Ÿšซ <abbr title="converted from some plain format, like bytes, into Python objects">๐ŸŽป</abbr> ๐ŸŽป, โšซ๏ธ โœ ๐Ÿ”— `bytes`, &amp; ๐Ÿ”ข `magic_data_reader()` ๐Ÿ”œ ๐Ÿˆš ๐ŸŽป โšซ๏ธ ๐ŸŒŒ.
๐Ÿ‘, ๐Ÿ‘ฅ ๐Ÿ’ช ๐Ÿ“ฃ ๐Ÿ“ˆ ๐Ÿ”— ๐Ÿ“จ ๐Ÿ’ช.
### ๐Ÿ›ƒ ๐Ÿ—„ ๐ŸŽš ๐Ÿ†Ž
โš™๏ธ ๐Ÿ‘‰ ๐ŸŽ ๐ŸŽฑ, ๐Ÿ‘† ๐Ÿ’ช โš™๏ธ Pydantic ๐Ÿท ๐Ÿ”ฌ ๐ŸŽป ๐Ÿ”— ๐Ÿ‘ˆ โคด๏ธ ๐Ÿ”Œ ๐Ÿ›ƒ ๐Ÿ—„ ๐Ÿ”— ๐Ÿ“„ *โžก ๐Ÿ› ๏ธ*.
&amp; ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ‘‰ ๐Ÿšฅ ๐Ÿ’ฝ ๐Ÿ†Ž ๐Ÿ“จ ๐Ÿšซ ๐ŸŽป.
๐Ÿ–ผ, ๐Ÿ‘‰ ๐Ÿˆธ ๐Ÿ‘ฅ ๐Ÿšซ โš™๏ธ FastAPI ๐Ÿ› ๏ธ ๐Ÿ› ๏ธ โš— ๐ŸŽป ๐Ÿ”— โšช๏ธโžก๏ธ Pydantic ๐Ÿท ๐Ÿšซ ๐Ÿง ๐Ÿ”ฌ ๐ŸŽป. ๐Ÿ‘, ๐Ÿ‘ฅ ๐Ÿ“ฃ ๐Ÿ“จ ๐ŸŽš ๐Ÿ†Ž ๐Ÿ“, ๐Ÿšซ ๐ŸŽป:
```Python hl_lines="17-22 24"
{!../../../docs_src/path_operation_advanced_configuration/tutorial007.py!}
```
๐Ÿ‘, ๐Ÿ‘ ๐Ÿ‘ฅ ๐Ÿšซ โš™๏ธ ๐Ÿ”ข ๐Ÿ› ๏ธ ๐Ÿ› ๏ธ, ๐Ÿ‘ฅ โš™๏ธ Pydantic ๐Ÿท โŽ ๐Ÿ— ๐ŸŽป ๐Ÿ”— ๐Ÿ’ฝ ๐Ÿ‘ˆ ๐Ÿ‘ฅ ๐Ÿ’š ๐Ÿ“จ ๐Ÿ“.
โคด๏ธ ๐Ÿ‘ฅ โš™๏ธ ๐Ÿ“จ ๐Ÿ”—, &amp; โš— ๐Ÿ’ช `bytes`. ๐Ÿ‘‰ โ›“ ๐Ÿ‘ˆ FastAPI ๐Ÿ† ๐Ÿšซ ๐Ÿ”„ ๐ŸŽป ๐Ÿ“จ ๐Ÿš€ ๐ŸŽป.
&amp; โคด๏ธ ๐Ÿ‘† ๐Ÿ“Ÿ, ๐Ÿ‘ฅ ๐ŸŽป ๐Ÿ‘ˆ ๐Ÿ“ ๐ŸŽš ๐Ÿ”—, &amp; โคด๏ธ ๐Ÿ‘ฅ ๐Ÿ”„ โš™๏ธ ๐ŸŽ Pydantic ๐Ÿท โœ” ๐Ÿ“ ๐ŸŽš:
```Python hl_lines="26-33"
{!../../../docs_src/path_operation_advanced_configuration/tutorial007.py!}
```
!!! tip
๐Ÿ“ฅ ๐Ÿ‘ฅ ๐Ÿค-โš™๏ธ ๐ŸŽ Pydantic ๐Ÿท.
โœ‹๏ธ ๐ŸŽ ๐ŸŒŒ, ๐Ÿ‘ฅ ๐Ÿ’ช โœ”๏ธ โœ” โšซ๏ธ ๐ŸŽ ๐ŸŒŒ.

33
docs/em/docs/advanced/response-change-status-code.md

@ -0,0 +1,33 @@
# ๐Ÿ“จ - ๐Ÿ”€ ๐Ÿ‘” ๐Ÿ“Ÿ
๐Ÿ‘† ๐ŸŽฒ โœ โญ ๐Ÿ‘ˆ ๐Ÿ‘† ๐Ÿ’ช โš’ ๐Ÿ”ข [๐Ÿ“จ ๐Ÿ‘” ๐Ÿ“Ÿ](../tutorial/response-status-code.md){.internal-link target=_blank}.
โœ‹๏ธ ๐Ÿ’ผ ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ“จ ๐ŸŽ ๐Ÿ‘” ๐Ÿ“Ÿ ๐ŸŒ˜ ๐Ÿ”ข.
## โš™๏ธ ๐Ÿ’ผ
๐Ÿ–ผ, ๐ŸŒˆ ๐Ÿ‘ˆ ๐Ÿ‘† ๐Ÿ’š ๐Ÿ“จ ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ” ๐Ÿ‘” ๐Ÿ“Ÿ "๐Ÿ‘Œ" `200` ๐Ÿ”ข.
โœ‹๏ธ ๐Ÿšฅ ๐Ÿ’ฝ ๐Ÿšซ ๐Ÿ”€, ๐Ÿ‘† ๐Ÿ’š โœ โšซ๏ธ, &amp; ๐Ÿ“จ ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ” ๐Ÿ‘” ๐Ÿ“Ÿ "โœ" `201`.
โœ‹๏ธ ๐Ÿ‘† ๐Ÿ’š ๐Ÿ’ช โ›ฝ &amp; ๐Ÿ—œ ๐Ÿ’ฝ ๐Ÿ‘† ๐Ÿ“จ โฎ๏ธ `response_model`.
๐Ÿ“š ๐Ÿ’ผ, ๐Ÿ‘† ๐Ÿ’ช โš™๏ธ `Response` ๐Ÿ”ข.
## โš™๏ธ `Response` ๐Ÿ”ข
๐Ÿ‘† ๐Ÿ’ช ๐Ÿ“ฃ ๐Ÿ”ข ๐Ÿ†Ž `Response` ๐Ÿ‘† *โžก ๐Ÿ› ๏ธ ๐Ÿ”ข* (๐Ÿ‘† ๐Ÿ’ช ๐Ÿช &amp; ๐ŸŽš).
&amp; โคด๏ธ ๐Ÿ‘† ๐Ÿ’ช โš’ `status_code` ๐Ÿ‘ˆ *๐Ÿ”€* ๐Ÿ“จ ๐ŸŽš.
```Python hl_lines="1 9 12"
{!../../../docs_src/response_change_status_code/tutorial001.py!}
```
&amp; โคด๏ธ ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ“จ ๐Ÿ™† ๐ŸŽš ๐Ÿ‘† ๐Ÿ’ช, ๐Ÿ‘† ๐Ÿ›Ž ๐Ÿ”œ ( `dict`, ๐Ÿ’ฝ ๐Ÿท, โ™’๏ธ).
&amp; ๐Ÿšฅ ๐Ÿ‘† ๐Ÿ“ฃ `response_model`, โšซ๏ธ ๐Ÿ”œ โš™๏ธ โ›ฝ &amp; ๐Ÿ—œ ๐ŸŽš ๐Ÿ‘† ๐Ÿ“จ.
**FastAPI** ๐Ÿ”œ โš™๏ธ ๐Ÿ‘ˆ *๐Ÿ”€* ๐Ÿ“จ โš— ๐Ÿ‘” ๐Ÿ“Ÿ (๐Ÿช &amp; ๐ŸŽš), &amp; ๐Ÿ”œ ๐Ÿšฎ ๐Ÿ‘ซ ๐Ÿ ๐Ÿ“จ ๐Ÿ‘ˆ ๐Ÿ”Œ ๐Ÿ’ฒ ๐Ÿ‘† ๐Ÿ“จ, โ›ฝ ๐Ÿ™† `response_model`.
๐Ÿ‘† ๐Ÿ’ช ๐Ÿ“ฃ `Response` ๐Ÿ”ข ๐Ÿ”—, &amp; โš’ ๐Ÿ‘” ๐Ÿ“Ÿ ๐Ÿ‘ซ. โœ‹๏ธ โœ”๏ธ ๐Ÿคฏ ๐Ÿ‘ˆ ๐Ÿ 1๏ธโƒฃ โš’ ๐Ÿ”œ ๐Ÿ†.

49
docs/em/docs/advanced/response-cookies.md

@ -0,0 +1,49 @@
# ๐Ÿ“จ ๐Ÿช
## โš™๏ธ `Response` ๐Ÿ”ข
๐Ÿ‘† ๐Ÿ’ช ๐Ÿ“ฃ ๐Ÿ”ข ๐Ÿ†Ž `Response` ๐Ÿ‘† *โžก ๐Ÿ› ๏ธ ๐Ÿ”ข*.
&amp; โคด๏ธ ๐Ÿ‘† ๐Ÿ’ช โš’ ๐Ÿช ๐Ÿ‘ˆ *๐Ÿ”€* ๐Ÿ“จ ๐ŸŽš.
```Python hl_lines="1 8-9"
{!../../../docs_src/response_cookies/tutorial002.py!}
```
&amp; โคด๏ธ ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ“จ ๐Ÿ™† ๐ŸŽš ๐Ÿ‘† ๐Ÿ’ช, ๐Ÿ‘† ๐Ÿ›Ž ๐Ÿ”œ ( `dict`, ๐Ÿ’ฝ ๐Ÿท, โ™’๏ธ).
&amp; ๐Ÿšฅ ๐Ÿ‘† ๐Ÿ“ฃ `response_model`, โšซ๏ธ ๐Ÿ”œ โš™๏ธ โ›ฝ &amp; ๐Ÿ—œ ๐ŸŽš ๐Ÿ‘† ๐Ÿ“จ.
**FastAPI** ๐Ÿ”œ โš™๏ธ ๐Ÿ‘ˆ *๐Ÿ”€* ๐Ÿ“จ โš— ๐Ÿช (๐ŸŽš &amp; ๐Ÿ‘” ๐Ÿ“Ÿ), &amp; ๐Ÿ”œ ๐Ÿšฎ ๐Ÿ‘ซ ๐Ÿ ๐Ÿ“จ ๐Ÿ‘ˆ ๐Ÿ”Œ ๐Ÿ’ฒ ๐Ÿ‘† ๐Ÿ“จ, โ›ฝ ๐Ÿ™† `response_model`.
๐Ÿ‘† ๐Ÿ’ช ๐Ÿ“ฃ `Response` ๐Ÿ”ข ๐Ÿ”—, &amp; โš’ ๐Ÿช (&amp; ๐ŸŽš) ๐Ÿ‘ซ.
## ๐Ÿ“จ `Response` ๐Ÿ”—
๐Ÿ‘† ๐Ÿ’ช โœ ๐Ÿช ๐Ÿ•โ” ๐Ÿ›ฌ `Response` ๐Ÿ”— ๐Ÿ‘† ๐Ÿ“Ÿ.
๐Ÿ‘ˆ, ๐Ÿ‘† ๐Ÿ’ช โœ ๐Ÿ“จ ๐Ÿ”ฌ [๐Ÿ“จ ๐Ÿ“จ ๐Ÿ”—](response-directly.md){.internal-link target=_blank}.
โคด๏ธ โš’ ๐Ÿช โšซ๏ธ, &amp; โคด๏ธ ๐Ÿ“จ โšซ๏ธ:
```Python hl_lines="10-12"
{!../../../docs_src/response_cookies/tutorial001.py!}
```
!!! tip
โœ”๏ธ ๐Ÿคฏ ๐Ÿ‘ˆ ๐Ÿšฅ ๐Ÿ‘† ๐Ÿ“จ ๐Ÿ“จ ๐Ÿ”— โ†ฉ๏ธ โš™๏ธ `Response` ๐Ÿ”ข, FastAPI ๐Ÿ”œ ๐Ÿ“จ โšซ๏ธ ๐Ÿ”—.
, ๐Ÿ‘† ๐Ÿ”œ โœ”๏ธ โš’ ๐Ÿ’ญ ๐Ÿ‘† ๐Ÿ’ฝ โ˜‘ ๐Ÿ†Ž. ๐Ÿคถ โ“‚. โšซ๏ธ ๐Ÿ”— โฎ๏ธ ๐ŸŽป, ๐Ÿšฅ ๐Ÿ‘† ๐Ÿ›ฌ `JSONResponse`.
&amp; ๐Ÿ‘ˆ ๐Ÿ‘† ๐Ÿšซ ๐Ÿ“จ ๐Ÿ™† ๐Ÿ“Š ๐Ÿ‘ˆ ๐Ÿ”œ โœ”๏ธ โ›ฝ `response_model`.
### ๐ŸŒ… โ„น
!!! note "๐Ÿ“ก โ„น"
๐Ÿ‘† ๐Ÿ’ช โš™๏ธ `from starlette.responses import Response` โš–๏ธ `from starlette.responses import JSONResponse`.
**FastAPI** ๐Ÿšš ๐ŸŽ `starlette.responses` `fastapi.responses` ๐Ÿช ๐Ÿ‘†, ๐Ÿ‘ฉโ€๐Ÿ’ป. โœ‹๏ธ ๐ŸŒ… ๐Ÿ’ช ๐Ÿ“จ ๐Ÿ‘Ÿ ๐Ÿ”— โšช๏ธโžก๏ธ ๐Ÿ’ƒ.
&amp; `Response` ๐Ÿ’ช โš™๏ธ ๐Ÿ›Ž โš’ ๐ŸŽš &amp; ๐Ÿช, **FastAPI** ๐Ÿšš โšซ๏ธ `fastapi.Response`.
๐Ÿ‘€ ๐ŸŒ ๐Ÿ’ช ๐Ÿ”ข &amp; ๐ŸŽ›, โœ… <a href="https://www.starlette.io/responses/#set-cookie" class="external-link" target="_blank">๐Ÿงพ ๐Ÿ’ƒ</a>.

63
docs/em/docs/advanced/response-directly.md

@ -0,0 +1,63 @@
# ๐Ÿ“จ ๐Ÿ“จ ๐Ÿ”—
๐Ÿ•โ” ๐Ÿ‘† โœ **FastAPI** *โžก ๐Ÿ› ๏ธ* ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ›Ž ๐Ÿ“จ ๐Ÿ™† ๐Ÿ“Š โšช๏ธโžก๏ธ โšซ๏ธ: `dict`, `list`, Pydantic ๐Ÿท, ๐Ÿ’ฝ ๐Ÿท, โ™’๏ธ.
๐Ÿ”ข, **FastAPI** ๐Ÿ”œ ๐Ÿ” ๐Ÿ—œ ๐Ÿ‘ˆ ๐Ÿ“จ ๐Ÿ’ฒ ๐ŸŽป โš™๏ธ `jsonable_encoder` ๐Ÿ”ฌ [๐ŸŽป ๐Ÿ”— ๐Ÿ”ข](../tutorial/encoder.md){.internal-link target=_blank}.
โคด๏ธ, โ›… ๐ŸŽ‘, โšซ๏ธ ๐Ÿ”œ ๐Ÿšฎ ๐Ÿ‘ˆ ๐ŸŽป-๐Ÿ”— ๐Ÿ’ฝ (โœ… `dict`) ๐Ÿ”˜ `JSONResponse` ๐Ÿ‘ˆ ๐Ÿ”œ โš™๏ธ ๐Ÿ“จ ๐Ÿ“จ ๐Ÿ‘ฉโ€๐Ÿ’ป.
โœ‹๏ธ ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ“จ `JSONResponse` ๐Ÿ”— โšช๏ธโžก๏ธ ๐Ÿ‘† *โžก ๐Ÿ› ๏ธ*.
โšซ๏ธ ๐Ÿ’ช โš , ๐Ÿ–ผ, ๐Ÿ“จ ๐Ÿ›ƒ ๐ŸŽš โš–๏ธ ๐Ÿช.
## ๐Ÿ“จ `Response`
๐Ÿ‘, ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ“จ ๐Ÿ™† `Response` โš–๏ธ ๐Ÿ™† ๐ŸŽง-๐ŸŽ“ โšซ๏ธ.
!!! tip
`JSONResponse` โšซ๏ธ ๐ŸŽง-๐ŸŽ“ `Response`.
&amp; ๐Ÿ•โ” ๐Ÿ‘† ๐Ÿ“จ `Response`, **FastAPI** ๐Ÿ”œ ๐Ÿšถโ€โ™€๏ธ โšซ๏ธ ๐Ÿ”—.
โšซ๏ธ ๐Ÿ† ๐Ÿšซ ๐Ÿ™† ๐Ÿ’ฝ ๐Ÿ› ๏ธ โฎ๏ธ Pydantic ๐Ÿท, โšซ๏ธ ๐Ÿ† ๐Ÿšซ ๐Ÿ—œ ๐ŸŽš ๐Ÿ™† ๐Ÿ†Ž, โ™’๏ธ.
๐Ÿ‘‰ ๐Ÿค ๐Ÿ‘† ๐Ÿ“š ๐Ÿ’ช. ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ“จ ๐Ÿ™† ๐Ÿ“Š ๐Ÿ†Ž, ๐Ÿ” ๐Ÿ™† ๐Ÿ’ฝ ๐Ÿ“„ โš–๏ธ ๐Ÿ”ฌ, โ™’๏ธ.
## โš™๏ธ `jsonable_encoder` `Response`
โ†ฉ๏ธ **FastAPI** ๐Ÿšซ ๐Ÿ™† ๐Ÿ”€ `Response` ๐Ÿ‘† ๐Ÿ“จ, ๐Ÿ‘† โœ”๏ธ โš’ ๐Ÿ’ญ โšซ๏ธ ๐ŸŽš ๐Ÿ”œ โšซ๏ธ.
๐Ÿ–ผ, ๐Ÿ‘† ๐Ÿšซ๐Ÿ”œ ๐Ÿšฎ Pydantic ๐Ÿท `JSONResponse` ๐Ÿต ๐Ÿฅ‡ ๐Ÿญ โšซ๏ธ `dict` โฎ๏ธ ๐ŸŒ ๐Ÿ“Š ๐Ÿ†Ž (๐Ÿ’– `datetime`, `UUID`, โ™’๏ธ) ๐Ÿ—œ ๐ŸŽป-๐Ÿ”— ๐Ÿ†Ž.
๐Ÿ“š ๐Ÿ’ผ, ๐Ÿ‘† ๐Ÿ’ช โš™๏ธ `jsonable_encoder` ๐Ÿ—œ ๐Ÿ‘† ๐Ÿ“Š โญ ๐Ÿšถโ€โ™€๏ธ โšซ๏ธ ๐Ÿ“จ:
```Python hl_lines="6-7 21-22"
{!../../../docs_src/response_directly/tutorial001.py!}
```
!!! note "๐Ÿ“ก โ„น"
๐Ÿ‘† ๐Ÿ’ช โš™๏ธ `from starlette.responses import JSONResponse`.
**FastAPI** ๐Ÿšš ๐ŸŽ `starlette.responses` `fastapi.responses` ๐Ÿช ๐Ÿ‘†, ๐Ÿ‘ฉโ€๐Ÿ’ป. โœ‹๏ธ ๐ŸŒ… ๐Ÿ’ช ๐Ÿ“จ ๐Ÿ‘Ÿ ๐Ÿ”— โšช๏ธโžก๏ธ ๐Ÿ’ƒ.
## ๐Ÿ›ฌ ๐Ÿ›ƒ `Response`
๐Ÿ–ผ ๐Ÿ”› ๐ŸŽฆ ๐ŸŒ ๐Ÿ• ๐Ÿ‘† ๐Ÿ’ช, โœ‹๏ธ โšซ๏ธ ๐Ÿšซ ๐Ÿ“ถ โš , ๐Ÿ‘† ๐Ÿ’ช โœ”๏ธ ๐Ÿ“จ `item` ๐Ÿ”—, &amp; **FastAPI** ๐Ÿ”œ ๐Ÿšฎ โšซ๏ธ `JSONResponse` ๐Ÿ‘†, ๐Ÿญ โšซ๏ธ `dict`, โ™’๏ธ. ๐ŸŒ ๐Ÿ‘ˆ ๐Ÿ”ข.
๐Ÿ”œ, โžก๏ธ ๐Ÿ‘€ โ” ๐Ÿ‘† ๐Ÿ’ช โš™๏ธ ๐Ÿ‘ˆ ๐Ÿ“จ ๐Ÿ›ƒ ๐Ÿ“จ.
โžก๏ธ ๐Ÿ’ฌ ๐Ÿ‘ˆ ๐Ÿ‘† ๐Ÿ’š ๐Ÿ“จ <a href="https://en.wikipedia.org/wiki/XML" class="external-link" target="_blank">๐Ÿ“‚</a> ๐Ÿ“จ.
๐Ÿ‘† ๐Ÿ’ช ๐Ÿšฎ ๐Ÿ‘† ๐Ÿ“‚ ๐ŸŽš ๐ŸŽป, ๐Ÿšฎ โšซ๏ธ `Response`, &amp; ๐Ÿ“จ โšซ๏ธ:
```Python hl_lines="1 18"
{!../../../docs_src/response_directly/tutorial002.py!}
```
## ๐Ÿ—’
๐Ÿ•โ” ๐Ÿ‘† ๐Ÿ“จ `Response` ๐Ÿ”— ๐Ÿšฎ ๐Ÿ“Š ๐Ÿšซ โœ”, ๐Ÿ—œ (๐ŸŽป), ๐Ÿšซ ๐Ÿ“„ ๐Ÿ”.
โœ‹๏ธ ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ“„ โšซ๏ธ ๐Ÿ”ฌ [๐ŸŒ– ๐Ÿ“จ ๐Ÿ—„](additional-responses.md){.internal-link target=_blank}.
๐Ÿ‘† ๐Ÿ’ช ๐Ÿ‘€ โช ๐Ÿ“„ โ” โš™๏ธ/๐Ÿ“ฃ ๐Ÿ‘‰ ๐Ÿ›ƒ `Response`โ“‚ โช โœ”๏ธ ๐Ÿง ๐Ÿ’ฝ ๐Ÿ› ๏ธ, ๐Ÿงพ, โ™’๏ธ.

42
docs/em/docs/advanced/response-headers.md

@ -0,0 +1,42 @@
# ๐Ÿ“จ ๐ŸŽš
## โš™๏ธ `Response` ๐Ÿ”ข
๐Ÿ‘† ๐Ÿ’ช ๐Ÿ“ฃ ๐Ÿ”ข ๐Ÿ†Ž `Response` ๐Ÿ‘† *โžก ๐Ÿ› ๏ธ ๐Ÿ”ข* (๐Ÿ‘† ๐Ÿ’ช ๐Ÿช).
&amp; โคด๏ธ ๐Ÿ‘† ๐Ÿ’ช โš’ ๐ŸŽš ๐Ÿ‘ˆ *๐Ÿ”€* ๐Ÿ“จ ๐ŸŽš.
```Python hl_lines="1 7-8"
{!../../../docs_src/response_headers/tutorial002.py!}
```
&amp; โคด๏ธ ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ“จ ๐Ÿ™† ๐ŸŽš ๐Ÿ‘† ๐Ÿ’ช, ๐Ÿ‘† ๐Ÿ›Ž ๐Ÿ”œ ( `dict`, ๐Ÿ’ฝ ๐Ÿท, โ™’๏ธ).
&amp; ๐Ÿšฅ ๐Ÿ‘† ๐Ÿ“ฃ `response_model`, โšซ๏ธ ๐Ÿ”œ โš™๏ธ โ›ฝ &amp; ๐Ÿ—œ ๐ŸŽš ๐Ÿ‘† ๐Ÿ“จ.
**FastAPI** ๐Ÿ”œ โš™๏ธ ๐Ÿ‘ˆ *๐Ÿ”€* ๐Ÿ“จ โš— ๐ŸŽš (๐Ÿช &amp; ๐Ÿ‘” ๐Ÿ“Ÿ), &amp; ๐Ÿ”œ ๐Ÿšฎ ๐Ÿ‘ซ ๐Ÿ ๐Ÿ“จ ๐Ÿ‘ˆ ๐Ÿ”Œ ๐Ÿ’ฒ ๐Ÿ‘† ๐Ÿ“จ, โ›ฝ ๐Ÿ™† `response_model`.
๐Ÿ‘† ๐Ÿ’ช ๐Ÿ“ฃ `Response` ๐Ÿ”ข ๐Ÿ”—, &amp; โš’ ๐ŸŽš (&amp; ๐Ÿช) ๐Ÿ‘ซ.
## ๐Ÿ“จ `Response` ๐Ÿ”—
๐Ÿ‘† ๐Ÿ’ช ๐Ÿšฎ ๐ŸŽš ๐Ÿ•โ” ๐Ÿ‘† ๐Ÿ“จ `Response` ๐Ÿ”—.
โœ ๐Ÿ“จ ๐Ÿ”ฌ [๐Ÿ“จ ๐Ÿ“จ ๐Ÿ”—](response-directly.md){.internal-link target=_blank} &amp; ๐Ÿšถโ€โ™€๏ธ ๐ŸŽš ๐ŸŒ– ๐Ÿ”ข:
```Python hl_lines="10-12"
{!../../../docs_src/response_headers/tutorial001.py!}
```
!!! note "๐Ÿ“ก โ„น"
๐Ÿ‘† ๐Ÿ’ช โš™๏ธ `from starlette.responses import Response` โš–๏ธ `from starlette.responses import JSONResponse`.
**FastAPI** ๐Ÿšš ๐ŸŽ `starlette.responses` `fastapi.responses` ๐Ÿช ๐Ÿ‘†, ๐Ÿ‘ฉโ€๐Ÿ’ป. โœ‹๏ธ ๐ŸŒ… ๐Ÿ’ช ๐Ÿ“จ ๐Ÿ‘Ÿ ๐Ÿ”— โšช๏ธโžก๏ธ ๐Ÿ’ƒ.
&amp; `Response` ๐Ÿ’ช โš™๏ธ ๐Ÿ›Ž โš’ ๐ŸŽš &amp; ๐Ÿช, **FastAPI** ๐Ÿšš โšซ๏ธ `fastapi.Response`.
## ๐Ÿ›ƒ ๐ŸŽš
โœ”๏ธ ๐Ÿคฏ ๐Ÿ‘ˆ ๐Ÿ›ƒ ยฉ ๐ŸŽš ๐Ÿ’ช ๐Ÿšฎ <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers" class="external-link" target="_blank">โš™๏ธ 'โœ–-' ๐Ÿ”ก</a>.
โœ‹๏ธ ๐Ÿšฅ ๐Ÿ‘† โœ”๏ธ ๐Ÿ›ƒ ๐ŸŽš ๐Ÿ‘ˆ ๐Ÿ‘† ๐Ÿ’š ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ–ฅ ๐Ÿ’ช ๐Ÿ‘€, ๐Ÿ‘† ๐Ÿ’ช ๐Ÿšฎ ๐Ÿ‘ซ ๐Ÿ‘† โšœ ๐Ÿ“ณ (โœ ๐ŸŒ… [โšœ (โœ–๏ธ-๐Ÿ‡จ๐Ÿ‡ณ โ„น ๐Ÿค)](../tutorial/cors.md){.internal-link target=_blank}), โš™๏ธ ๐Ÿ”ข `expose_headers` ๐Ÿ“„ <a href="https://www.starlette.io/middleware/#corsmiddleware" class="external-link" target="_blank">๐Ÿ’ƒ โšœ ๐Ÿฉบ</a>.

113
docs/em/docs/advanced/security/http-basic-auth.md

@ -0,0 +1,113 @@
# ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ” ๐Ÿ”ฐ ๐Ÿ”
๐Ÿ™… ๐Ÿ’ผ, ๐Ÿ‘† ๐Ÿ’ช โš™๏ธ ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ” ๐Ÿ”ฐ ๐Ÿ”.
๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ” ๐Ÿ”ฐ ๐Ÿ”, ๐Ÿˆธ โŒ› ๐ŸŽš ๐Ÿ‘ˆ ๐Ÿ”Œ ๐Ÿ†” &amp; ๐Ÿ”.
๐Ÿšฅ โšซ๏ธ ๐Ÿšซ ๐Ÿ“จ โšซ๏ธ, โšซ๏ธ ๐Ÿ“จ ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ” 4๏ธโƒฃ0๏ธโƒฃ1๏ธโƒฃ "โ›”" โŒ.
&amp; ๐Ÿ“จ ๐ŸŽš `WWW-Authenticate` โฎ๏ธ ๐Ÿ’ฒ `Basic`, &amp; ๐Ÿ“ฆ `realm` ๐Ÿ”ข.
๐Ÿ‘ˆ ๐Ÿ’ฌ ๐Ÿ–ฅ ๐ŸŽฆ ๐Ÿ› ๏ธ ๐Ÿ“‹ ๐Ÿ†” &amp; ๐Ÿ”.
โคด๏ธ, ๐Ÿ•โ” ๐Ÿ‘† ๐Ÿ†Ž ๐Ÿ‘ˆ ๐Ÿ†” &amp; ๐Ÿ”, ๐Ÿ–ฅ ๐Ÿ“จ ๐Ÿ‘ซ ๐ŸŽš ๐Ÿ”.
## ๐Ÿ™… ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ” ๐Ÿ”ฐ ๐Ÿ”
* ๐Ÿ—„ `HTTPBasic` &amp; `HTTPBasicCredentials`.
* โœ "`security` โš–" โš™๏ธ `HTTPBasic`.
* โš™๏ธ ๐Ÿ‘ˆ `security` โฎ๏ธ ๐Ÿ”— ๐Ÿ‘† *โžก ๐Ÿ› ๏ธ*.
* โšซ๏ธ ๐Ÿ“จ ๐ŸŽš ๐Ÿ†Ž `HTTPBasicCredentials`:
* โšซ๏ธ ๐Ÿ”Œ `username` &amp; `password` ๐Ÿ“จ.
```Python hl_lines="2 6 10"
{!../../../docs_src/security/tutorial006.py!}
```
๐Ÿ•โ” ๐Ÿ‘† ๐Ÿ”„ ๐Ÿ“‚ ๐Ÿ“› ๐Ÿฅ‡ ๐Ÿ•ฐ (โš–๏ธ ๐Ÿ–Š "๐Ÿ› ๏ธ" ๐Ÿ”ผ ๐Ÿฉบ) ๐Ÿ–ฅ ๐Ÿ”œ ๐Ÿ’ญ ๐Ÿ‘† ๐Ÿ‘† ๐Ÿ†” &amp; ๐Ÿ”:
<img src="/img/tutorial/security/image12.png">
## โœ… ๐Ÿ†”
๐Ÿ“ฅ ๐ŸŒ… ๐Ÿ ๐Ÿ–ผ.
โš™๏ธ ๐Ÿ”— โœ… ๐Ÿšฅ ๐Ÿ†” &amp; ๐Ÿ” โ˜‘.
๐Ÿ‘‰, โš™๏ธ ๐Ÿ ๐Ÿฉ ๐Ÿ•น <a href="https://docs.python.org/3/library/secrets.html" class="external-link" target="_blank">`secrets`</a> โœ… ๐Ÿ†” &amp; ๐Ÿ”.
`secrets.compare_digest()` ๐Ÿ’ช โœŠ `bytes` โš–๏ธ `str` ๐Ÿ‘ˆ ๐Ÿ•ด ๐Ÿ”Œ ๐Ÿ”  ๐Ÿฆน (๐Ÿ• ๐Ÿ‡ช๐Ÿ‡ธ), ๐Ÿ‘‰ โ›“ โšซ๏ธ ๐Ÿšซ๐Ÿ”œ ๐Ÿ‘ท โฎ๏ธ ๐Ÿฆน ๐Ÿ’– `รก`, `Sebastiรกn`.
๐Ÿต ๐Ÿ‘ˆ, ๐Ÿ‘ฅ ๐Ÿฅ‡ ๐Ÿ—œ `username` &amp; `password` `bytes` ๐Ÿ”ข ๐Ÿ‘ซ โฎ๏ธ ๐Ÿ” -8๏ธโƒฃ.
โคด๏ธ ๐Ÿ‘ฅ ๐Ÿ’ช โš™๏ธ `secrets.compare_digest()` ๐Ÿšš ๐Ÿ‘ˆ `credentials.username` `"stanleyjobson"`, &amp; ๐Ÿ‘ˆ `credentials.password` `"swordfish"`.
```Python hl_lines="1 11-21"
{!../../../docs_src/security/tutorial007.py!}
```
๐Ÿ‘‰ ๐Ÿ”œ ๐ŸŽ:
```Python
if not (credentials.username == "stanleyjobson") or not (credentials.password == "swordfish"):
# Return some error
...
```
โœ‹๏ธ โš™๏ธ `secrets.compare_digest()` โšซ๏ธ ๐Ÿ”œ ๐Ÿ” ๐Ÿ›ก ๐Ÿ†Ž ๐Ÿ‘Š ๐Ÿค™ "๐Ÿ•ฐ ๐Ÿ‘Š".
### โฒ ๐Ÿ‘Š
โœ‹๏ธ โšซ๏ธโ” "โฒ ๐Ÿ‘Š"โ“
โžก๏ธ ๐ŸŒˆ ๐Ÿ‘Š ๐Ÿ”„ ๐Ÿ’ญ ๐Ÿ†” &amp; ๐Ÿ”.
&amp; ๐Ÿ‘ซ ๐Ÿ“จ ๐Ÿ“จ โฎ๏ธ ๐Ÿ†” `johndoe` &amp; ๐Ÿ” `love123`.
โคด๏ธ ๐Ÿ ๐Ÿ“Ÿ ๐Ÿ‘† ๐Ÿˆธ ๐Ÿ”œ ๐ŸŒ“ ๐Ÿ•ณ ๐Ÿ’–:
```Python
if "johndoe" == "stanleyjobson" and "love123" == "swordfish":
...
```
โœ‹๏ธ โ–ถ๏ธ๏ธ ๐Ÿ™ ๐Ÿ ๐Ÿ”ฌ ๐Ÿฅ‡ `j` `johndoe` ๐Ÿฅ‡ `s` `stanleyjobson`, โšซ๏ธ ๐Ÿ”œ ๐Ÿ“จ `False`, โ†ฉ๏ธ โšซ๏ธ โช ๐Ÿ’ญ ๐Ÿ‘ˆ ๐Ÿ“š 2๏ธโƒฃ ๐ŸŽป ๐Ÿšซ ๐ŸŽ, ๐Ÿ’ญ ๐Ÿ‘ˆ "๐Ÿ“ค ๐Ÿ™…โ€โ™‚ ๐Ÿ’ช ๐Ÿ—‘ ๐ŸŒ… ๐Ÿ“Š โš– ๐ŸŽ‚ ๐Ÿ”ค". &amp; ๐Ÿ‘† ๐Ÿˆธ ๐Ÿ”œ ๐Ÿ’ฌ "โŒ ๐Ÿ‘ฉโ€๐Ÿ’ป โš–๏ธ ๐Ÿ”".
โœ‹๏ธ โคด๏ธ ๐Ÿ‘Š ๐Ÿ”„ โฎ๏ธ ๐Ÿ†” `stanleyjobsox` &amp; ๐Ÿ” `love123`.
&amp; ๐Ÿ‘† ๐Ÿˆธ ๐Ÿ“Ÿ ๐Ÿ”จ ๐Ÿ•ณ ๐Ÿ’–:
```Python
if "stanleyjobsox" == "stanleyjobson" and "love123" == "swordfish":
...
```
๐Ÿ ๐Ÿ”œ โœ”๏ธ ๐Ÿ”ฌ ๐ŸŽ‚ `stanleyjobso` ๐Ÿ‘ฏโ€โ™‚๏ธ `stanleyjobsox` &amp; `stanleyjobson` โญ ๐Ÿค” ๐Ÿ‘ˆ ๐Ÿ‘ฏโ€โ™‚๏ธ ๐ŸŽป ๐Ÿšซ ๐ŸŽ. โšซ๏ธ ๐Ÿ”œ โœŠ โž• โฒ ๐Ÿ“จ ๐Ÿ”™ "โŒ ๐Ÿ‘ฉโ€๐Ÿ’ป โš–๏ธ ๐Ÿ”".
#### ๐Ÿ•ฐ โ” โ„น ๐Ÿ‘Š
๐Ÿ‘ˆ โ˜, ๐Ÿ‘€ ๐Ÿ‘ˆ ๐Ÿ’ฝ โœŠ โฒ ๐Ÿ“ ๐Ÿ“จ "โŒ ๐Ÿ‘ฉโ€๐Ÿ’ป โš–๏ธ ๐Ÿ”" ๐Ÿ“จ, ๐Ÿ‘Š ๐Ÿ”œ ๐Ÿ’ญ ๐Ÿ‘ˆ ๐Ÿ‘ซ ๐Ÿคš _๐Ÿ•ณ_ โ–ถ๏ธ๏ธ, โ–ถ๏ธ ๐Ÿ”ค โ–ถ๏ธ๏ธ.
&amp; โคด๏ธ ๐Ÿ‘ซ ๐Ÿ’ช ๐Ÿ”„ ๐Ÿ”„ ๐Ÿค” ๐Ÿ‘ˆ โšซ๏ธ ๐ŸŽฒ ๐Ÿ•ณ ๐ŸŒ– ๐ŸŽ `stanleyjobsox` ๐ŸŒ˜ `johndoe`.
#### "๐Ÿ•ด" ๐Ÿ‘Š
โ†—๏ธ, ๐Ÿ‘Š ๐Ÿ”œ ๐Ÿšซ ๐Ÿ”„ ๐ŸŒ ๐Ÿ‘‰ โœ‹, ๐Ÿ‘ซ ๐Ÿ”œ โœ ๐Ÿ“‹ โšซ๏ธ, ๐ŸŽฒ โฎ๏ธ ๐Ÿ’ฏ โš–๏ธ ๐Ÿ’ฏ ๐Ÿ’ฏ ๐Ÿ“ ๐Ÿฅˆ. &amp; ๐Ÿ”œ ๐Ÿคš 1๏ธโƒฃ โž• โ˜‘ ๐Ÿ”ค ๐Ÿ•ฐ.
โœ‹๏ธ ๐Ÿ”จ ๐Ÿ‘ˆ, โฒ โš–๏ธ ๐Ÿ“† ๐Ÿ‘Š ๐Ÿ”œ โœ”๏ธ ๐Ÿ’ญ โ˜‘ ๐Ÿ†” &amp; ๐Ÿ”, โฎ๏ธ "โ„น" ๐Ÿ‘† ๐Ÿˆธ, โš™๏ธ ๐Ÿ•ฐ โœŠ โ”.
#### ๐Ÿ”ง โšซ๏ธ โฎ๏ธ `secrets.compare_digest()`
โœ‹๏ธ ๐Ÿ‘† ๐Ÿ“Ÿ ๐Ÿ‘ฅ ๐Ÿค™ โš™๏ธ `secrets.compare_digest()`.
๐Ÿ“, โšซ๏ธ ๐Ÿ”œ โœŠ ๐ŸŽ ๐Ÿ•ฐ ๐Ÿ”ฌ `stanleyjobsox` `stanleyjobson` ๐ŸŒ˜ โšซ๏ธ โœŠ ๐Ÿ”ฌ `johndoe` `stanleyjobson`. &amp; ๐ŸŽ ๐Ÿ”.
๐Ÿ‘ˆ ๐ŸŒŒ, โš™๏ธ `secrets.compare_digest()` ๐Ÿ‘† ๐Ÿˆธ ๐Ÿ“Ÿ, โšซ๏ธ ๐Ÿ”œ ๐Ÿ”’ ๐Ÿ›ก ๐Ÿ‘‰ ๐ŸŽ‚ โ†” ๐Ÿ’‚โ€โ™‚ ๐Ÿ‘Š.
### ๐Ÿ“จ โŒ
โฎ๏ธ ๐Ÿ” ๐Ÿ‘ˆ ๐ŸŽ“ โŒ, ๐Ÿ“จ `HTTPException` โฎ๏ธ ๐Ÿ‘” ๐Ÿ“Ÿ 4๏ธโƒฃ0๏ธโƒฃ1๏ธโƒฃ (๐ŸŽ ๐Ÿ“จ ๐Ÿ•โ” ๐Ÿ™…โ€โ™‚ ๐ŸŽ“ ๐Ÿšš) &amp; ๐Ÿšฎ ๐ŸŽš `WWW-Authenticate` โš’ ๐Ÿ–ฅ ๐ŸŽฆ ๐Ÿ’ณ ๐Ÿ“‹ ๐Ÿ”„:
```Python hl_lines="23-27"
{!../../../docs_src/security/tutorial007.py!}
```

16
docs/em/docs/advanced/security/index.md

@ -0,0 +1,16 @@
# ๐Ÿง ๐Ÿ’‚โ€โ™‚ - ๐ŸŽถ
## ๐ŸŒ– โš’
๐Ÿ“ค โž• โš’ ๐Ÿต ๐Ÿ’‚โ€โ™‚ โ†–๏ธ โšช๏ธโžก๏ธ ๐Ÿ• ๐Ÿ“” [๐Ÿ”ฐ - ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿฆฎ: ๐Ÿ’‚โ€โ™‚](../../tutorial/security/){.internal-link target=_blank}.
!!! tip
โญ ๐Ÿ“„ **๐Ÿšซ ๐ŸŽฏ "๐Ÿง"**.
&amp; โšซ๏ธ ๐Ÿ’ช ๐Ÿ‘ˆ ๐Ÿ‘† โš™๏ธ ๐Ÿ’ผ, โš— 1๏ธโƒฃ ๐Ÿ‘ซ.
## โœ ๐Ÿ”ฐ ๐Ÿฅ‡
โญ ๐Ÿ“„ ๐Ÿค” ๐Ÿ‘† โช โœ ๐Ÿ‘‘ [๐Ÿ”ฐ - ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿฆฎ: ๐Ÿ’‚โ€โ™‚](../../tutorial/security/){.internal-link target=_blank}.
๐Ÿ‘ซ ๐ŸŒ โš“๏ธ ๐Ÿ”› ๐ŸŽ ๐Ÿ”ง, โœ‹๏ธ โœ” โž• ๐Ÿ› ๏ธ.

269
docs/em/docs/advanced/security/oauth2-scopes.md

@ -0,0 +1,269 @@
# Oauth2๏ธโƒฃ โ†”
๐Ÿ‘† ๐Ÿ’ช โš™๏ธ Oauth2๏ธโƒฃ โ†” ๐Ÿ”— โฎ๏ธ **FastAPI**, ๐Ÿ‘ซ ๐Ÿ› ๏ธ ๐Ÿ‘ท ๐Ÿ’Ž.
๐Ÿ‘‰ ๐Ÿ”œ โœ” ๐Ÿ‘† โœ”๏ธ ๐ŸŒ– ๐Ÿ‘Œ-๐Ÿงฝ โœ” โš™๏ธ, ๐Ÿ“„ Oauth2๏ธโƒฃ ๐Ÿฉ, ๐Ÿ› ๏ธ ๐Ÿ”˜ ๐Ÿ‘† ๐Ÿ—„ ๐Ÿˆธ (&amp; ๐Ÿ› ๏ธ ๐Ÿฉบ).
Oauth2๏ธโƒฃ โฎ๏ธ โ†” ๐Ÿ› ๏ธ โš™๏ธ ๐Ÿ“š ๐Ÿฆ ๐Ÿค ๐Ÿ•โ€๐Ÿฆบ, ๐Ÿ’– ๐Ÿ‘ฑ๐Ÿ“”, ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ”, ๐Ÿ“‚, ๐Ÿคธโ€โ™‚, ๐Ÿ‘ฑ๐Ÿ“”, โ™’๏ธ. ๐Ÿ‘ซ โš™๏ธ โšซ๏ธ ๐Ÿšš ๐ŸŽฏ โœ” ๐Ÿ‘ฉโ€๐Ÿ’ป &amp; ๐Ÿˆธ.
๐Ÿ”  ๐Ÿ•ฐ ๐Ÿ‘† "๐Ÿ•น โฎ๏ธ" ๐Ÿ‘ฑ๐Ÿ“”, ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ”, ๐Ÿ“‚, ๐Ÿคธโ€โ™‚, ๐Ÿ‘ฑ๐Ÿ“”, ๐Ÿ‘ˆ ๐Ÿˆธ โš™๏ธ Oauth2๏ธโƒฃ โฎ๏ธ โ†”.
๐Ÿ‘‰ ๐Ÿ“„ ๐Ÿ‘† ๐Ÿ”œ ๐Ÿ‘€ โ” ๐Ÿ› ๏ธ ๐Ÿค &amp; โœ” โฎ๏ธ ๐ŸŽ Oauth2๏ธโƒฃ โฎ๏ธ โ†” ๐Ÿ‘† **FastAPI** ๐Ÿˆธ.
!!! warning
๐Ÿ‘‰ ๐ŸŒ… โš–๏ธ ๐ŸŒ˜ ๐Ÿง ๐Ÿ“„. ๐Ÿšฅ ๐Ÿ‘† โ–ถ๏ธ, ๐Ÿ‘† ๐Ÿ’ช ๐Ÿšถ โšซ๏ธ.
๐Ÿ‘† ๐Ÿšซ ๐ŸŽฏ ๐Ÿ’ช Oauth2๏ธโƒฃ โ†”, &amp; ๐Ÿ‘† ๐Ÿ’ช ๐Ÿต ๐Ÿค &amp; โœ” ๐Ÿ‘ ๐Ÿ‘† ๐Ÿ’š.
โœ‹๏ธ Oauth2๏ธโƒฃ โฎ๏ธ โ†” ๐Ÿ’ช ๐ŸŽ† ๐Ÿ› ๏ธ ๐Ÿ”˜ ๐Ÿ‘† ๐Ÿ› ๏ธ (โฎ๏ธ ๐Ÿ—„) &amp; ๐Ÿ‘† ๐Ÿ› ๏ธ ๐Ÿฉบ.
๐Ÿ‘, ๐Ÿ‘† ๐Ÿ› ๏ธ ๐Ÿ“š โ†”, โš–๏ธ ๐Ÿ™† ๐ŸŽ ๐Ÿ’‚โ€โ™‚/โœ” ๐Ÿ“„, ๐Ÿ‘ ๐Ÿ‘† ๐Ÿ’ช, ๐Ÿ‘† ๐Ÿ“Ÿ.
๐Ÿ“š ๐Ÿ’ผ, Oauth2๏ธโƒฃ โฎ๏ธ โ†” ๐Ÿ’ช ๐Ÿ‘น.
โœ‹๏ธ ๐Ÿšฅ ๐Ÿ‘† ๐Ÿ’ญ ๐Ÿ‘† ๐Ÿ’ช โšซ๏ธ, โš–๏ธ ๐Ÿ‘† ๐Ÿ˜Ÿ, ๐Ÿšง ๐Ÿ‘‚.
## Oauth2๏ธโƒฃ โ†” &amp; ๐Ÿ—„
Oauth2๏ธโƒฃ ๐Ÿ”ง ๐Ÿ”ฌ "โ†”" ๐Ÿ“‡ ๐ŸŽป ๐ŸŽ ๐Ÿš€.
๐ŸŽš ๐Ÿ”  ๐Ÿ‘‰ ๐ŸŽป ๐Ÿ’ช โœ”๏ธ ๐Ÿ™† ๐Ÿ“, โœ‹๏ธ ๐Ÿ”œ ๐Ÿšซ ๐Ÿ”Œ ๐Ÿš€.
๐Ÿ‘ซ โ†” ๐ŸŽจ "โœ”".
๐Ÿ—„ (โœ… ๐Ÿ› ๏ธ ๐Ÿฉบ), ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ”ฌ "๐Ÿ’‚โ€โ™‚ โš–".
๐Ÿ•โ” 1๏ธโƒฃ ๐Ÿ‘ซ ๐Ÿ’‚โ€โ™‚ โš– โš™๏ธ Oauth2๏ธโƒฃ, ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ“ฃ &amp; โš™๏ธ โ†”.
๐Ÿ”  "โ†”" ๐ŸŽป (๐Ÿต ๐Ÿš€).
๐Ÿ‘ซ ๐Ÿ›Ž โš™๏ธ ๐Ÿ“ฃ ๐ŸŽฏ ๐Ÿ’‚โ€โ™‚ โœ”, ๐Ÿ–ผ:
* `users:read` โš–๏ธ `users:write` โš  ๐Ÿ–ผ.
* `instagram_basic` โš™๏ธ ๐Ÿ‘ฑ๐Ÿ“” / ๐Ÿ‘ฑ๐Ÿ“”.
* `https://www.googleapis.com/auth/drive` โš™๏ธ ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ”.
!!! info
Oauth2๏ธโƒฃ "โ†”" ๐ŸŽป ๐Ÿ‘ˆ ๐Ÿ“ฃ ๐ŸŽฏ โœ” โœ”.
โšซ๏ธ ๐Ÿšซ ๐Ÿค” ๐Ÿšฅ โšซ๏ธ โœ”๏ธ ๐ŸŽ ๐Ÿฆน ๐Ÿ’– `:` โš–๏ธ ๐Ÿšฅ โšซ๏ธ ๐Ÿ“›.
๐Ÿ‘ˆ โ„น ๐Ÿ› ๏ธ ๐ŸŽฏ.
Oauth2๏ธโƒฃ ๐Ÿ‘ซ ๐ŸŽป.
## ๐ŸŒ ๐ŸŽ‘
๐Ÿฅ‡, โžก๏ธ ๐Ÿ”œ ๐Ÿ‘€ ๐Ÿ• ๐Ÿ‘ˆ ๐Ÿ”€ โšช๏ธโžก๏ธ ๐Ÿ–ผ ๐Ÿ‘‘ **๐Ÿ”ฐ - ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿฆฎ** [Oauth2๏ธโƒฃ โฎ๏ธ ๐Ÿ” (&amp; ๐Ÿ”), ๐Ÿ“จ โฎ๏ธ ๐Ÿฅ™ ๐Ÿค](../../tutorial/security/oauth2-jwt.md){.internal-link target=_blank}. ๐Ÿ”œ โš™๏ธ Oauth2๏ธโƒฃ โ†”:
```Python hl_lines="2 4 8 12 46 64 105 107-115 121-124 128-134 139 153"
{!../../../docs_src/security/tutorial005.py!}
```
๐Ÿ”œ โžก๏ธ ๐Ÿ“„ ๐Ÿ‘ˆ ๐Ÿ”€ ๐Ÿ” ๐Ÿ”.
## Oauth2๏ธโƒฃ ๐Ÿ’‚โ€โ™‚ โš–
๐Ÿฅ‡ ๐Ÿ”€ ๐Ÿ‘ˆ ๐Ÿ”œ ๐Ÿ‘ฅ ๐Ÿ“ฃ Oauth2๏ธโƒฃ ๐Ÿ’‚โ€โ™‚ โš– โฎ๏ธ 2๏ธโƒฃ ๐Ÿ’ช โ†”, `me` &amp; `items`.
`scopes` ๐Ÿ”ข ๐Ÿ“จ `dict` โฎ๏ธ ๐Ÿ”  โ†” ๐Ÿ”‘ &amp; ๐Ÿ“› ๐Ÿ’ฒ:
```Python hl_lines="62-65"
{!../../../docs_src/security/tutorial005.py!}
```
โ†ฉ๏ธ ๐Ÿ‘ฅ ๐Ÿ”œ ๐Ÿ“ฃ ๐Ÿ“š โ†”, ๐Ÿ‘ซ ๐Ÿ”œ ๐ŸŽฆ ๐Ÿ†™ ๐Ÿ› ๏ธ ๐Ÿฉบ ๐Ÿ•โ” ๐Ÿ‘† ๐Ÿ•น-/โœ”.
&amp; ๐Ÿ‘† ๐Ÿ”œ ๐Ÿ’ช ๐Ÿ–Š โ” โ†” ๐Ÿ‘† ๐Ÿ’š ๐Ÿค ๐Ÿ”: `me` &amp; `items`.
๐Ÿ‘‰ ๐ŸŽ ๐Ÿ› ๏ธ โš™๏ธ ๐Ÿ•โ” ๐Ÿ‘† ๐Ÿค โœ” โช ๐Ÿšจ โฎ๏ธ ๐Ÿ‘ฑ๐Ÿ“”, ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ”, ๐Ÿ“‚, โ™’๏ธ:
<img src="/img/tutorial/security/image11.png">
## ๐Ÿฅ™ ๐Ÿค โฎ๏ธ โ†”
๐Ÿ”œ, ๐Ÿ”€ ๐Ÿค *โžก ๐Ÿ› ๏ธ* ๐Ÿ“จ โ†” ๐Ÿ“จ.
๐Ÿ‘ฅ โš™๏ธ ๐ŸŽ `OAuth2PasswordRequestForm`. โšซ๏ธ ๐Ÿ”Œ ๐Ÿ  `scopes` โฎ๏ธ `list` `str`, โฎ๏ธ ๐Ÿ”  โ†” โšซ๏ธ ๐Ÿ“จ ๐Ÿ“จ.
&amp; ๐Ÿ‘ฅ ๐Ÿ“จ โ†” ๐Ÿ• ๐Ÿฅ™ ๐Ÿค.
!!! danger
๐Ÿฆ, ๐Ÿ“ฅ ๐Ÿ‘ฅ โŽ โ†” ๐Ÿ“จ ๐Ÿ”— ๐Ÿค.
โœ‹๏ธ ๐Ÿ‘† ๐Ÿˆธ, ๐Ÿ’‚โ€โ™‚, ๐Ÿ‘† ๐Ÿ”œ โš’ ๐Ÿ’ญ ๐Ÿ‘† ๐Ÿ•ด ๐Ÿšฎ โ†” ๐Ÿ‘ˆ ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿค™ ๐Ÿ’ช โœ”๏ธ, โš–๏ธ ๐Ÿ• ๐Ÿ‘† โœ”๏ธ ๐Ÿ”.
```Python hl_lines="153"
{!../../../docs_src/security/tutorial005.py!}
```
## ๐Ÿ“ฃ โ†” *โžก ๐Ÿ› ๏ธ* &amp; ๐Ÿ”—
๐Ÿ”œ ๐Ÿ‘ฅ ๐Ÿ“ฃ ๐Ÿ‘ˆ *โžก ๐Ÿ› ๏ธ* `/users/me/items/` ๐Ÿšš โ†” `items`.
๐Ÿ‘‰, ๐Ÿ‘ฅ ๐Ÿ—„ &amp; โš™๏ธ `Security` โšช๏ธโžก๏ธ `fastapi`.
๐Ÿ‘† ๐Ÿ’ช โš™๏ธ `Security` ๐Ÿ“ฃ ๐Ÿ”— (๐Ÿ’– `Depends`), โœ‹๏ธ `Security` ๐Ÿ“จ ๐Ÿ”ข `scopes` โฎ๏ธ ๐Ÿ“‡ โ†” (๐ŸŽป).
๐Ÿ‘‰ ๐Ÿ’ผ, ๐Ÿ‘ฅ ๐Ÿšถโ€โ™€๏ธ ๐Ÿ”— ๐Ÿ”ข `get_current_active_user` `Security` (๐ŸŽ ๐ŸŒŒ ๐Ÿ‘ฅ ๐Ÿ”œ โฎ๏ธ `Depends`).
โœ‹๏ธ ๐Ÿ‘ฅ ๐Ÿšถโ€โ™€๏ธ `list` โ†”, ๐Ÿ‘‰ ๐Ÿ’ผ โฎ๏ธ 1๏ธโƒฃ โ†”: `items` (โšซ๏ธ ๐Ÿ’ช โœ”๏ธ ๐ŸŒ…).
&amp; ๐Ÿ”— ๐Ÿ”ข `get_current_active_user` ๐Ÿ’ช ๐Ÿ“ฃ ๐ŸŽง-๐Ÿ”—, ๐Ÿšซ ๐Ÿ•ด โฎ๏ธ `Depends` โœ‹๏ธ โฎ๏ธ `Security`. ๐Ÿ“ฃ ๐Ÿšฎ ๐Ÿ‘ ๐ŸŽง-๐Ÿ”— ๐Ÿ”ข (`get_current_user`), &amp; ๐ŸŒ– โ†” ๐Ÿ“„.
๐Ÿ‘‰ ๐Ÿ’ผ, โšซ๏ธ ๐Ÿšš โ†” `me` (โšซ๏ธ ๐Ÿ’ช ๐Ÿšš ๐ŸŒ… ๐ŸŒ˜ 1๏ธโƒฃ โ†”).
!!! note
๐Ÿ‘† ๐Ÿšซ ๐ŸŽฏ ๐Ÿ’ช ๐Ÿšฎ ๐ŸŽ โ†” ๐ŸŽ ๐Ÿฅ‰.
๐Ÿ‘ฅ ๐Ÿ”จ โšซ๏ธ ๐Ÿ“ฅ ๐ŸŽฆ โ” **FastAPI** ๐Ÿต โ†” ๐Ÿ“ฃ ๐ŸŽ ๐ŸŽš.
```Python hl_lines="4 139 166"
{!../../../docs_src/security/tutorial005.py!}
```
!!! info "๐Ÿ“ก โ„น"
`Security` ๐Ÿค™ ๐Ÿฟ `Depends`, &amp; โšซ๏ธ โœ”๏ธ 1๏ธโƒฃ โž• ๐Ÿ”ข ๐Ÿ‘ˆ ๐Ÿ‘ฅ ๐Ÿ”œ ๐Ÿ‘€ โช.
โœ‹๏ธ โš™๏ธ `Security` โ†ฉ๏ธ `Depends`, **FastAPI** ๐Ÿ”œ ๐Ÿ’ญ ๐Ÿ‘ˆ โšซ๏ธ ๐Ÿ’ช ๐Ÿ“ฃ ๐Ÿ’‚โ€โ™‚ โ†”, โš™๏ธ ๐Ÿ‘ซ ๐Ÿ”˜, &amp; ๐Ÿ“„ ๐Ÿ› ๏ธ โฎ๏ธ ๐Ÿ—„.
โœ‹๏ธ ๐Ÿ•โ” ๐Ÿ‘† ๐Ÿ—„ `Query`, `Path`, `Depends`, `Security` &amp; ๐ŸŽ โšช๏ธโžก๏ธ `fastapi`, ๐Ÿ‘ˆ ๐Ÿค™ ๐Ÿ”ข ๐Ÿ‘ˆ ๐Ÿ“จ ๐ŸŽ ๐ŸŽ“.
## โš™๏ธ `SecurityScopes`
๐Ÿ”œ โ„น ๐Ÿ”— `get_current_user`.
๐Ÿ‘‰ 1๏ธโƒฃ โš™๏ธ ๐Ÿ”— ๐Ÿ”›.
๐Ÿ“ฅ ๐Ÿ‘ฅ โš™๏ธ ๐ŸŽ Oauth2๏ธโƒฃ โš– ๐Ÿ‘ฅ โœ โญ, ๐Ÿ“ฃ โšซ๏ธ ๐Ÿ”—: `oauth2_scheme`.
โ†ฉ๏ธ ๐Ÿ‘‰ ๐Ÿ”— ๐Ÿ”ข ๐Ÿšซ โœ”๏ธ ๐Ÿ™† โ†” ๐Ÿ“„ โšซ๏ธ, ๐Ÿ‘ฅ ๐Ÿ’ช โš™๏ธ `Depends` โฎ๏ธ `oauth2_scheme`, ๐Ÿ‘ฅ ๐Ÿšซ โœ”๏ธ โš™๏ธ `Security` ๐Ÿ•โ” ๐Ÿ‘ฅ ๐Ÿšซ ๐Ÿ’ช โœ” ๐Ÿ’‚โ€โ™‚ โ†”.
๐Ÿ‘ฅ ๐Ÿ“ฃ ๐ŸŽ ๐Ÿ”ข ๐Ÿ†Ž `SecurityScopes`, ๐Ÿ—„ โšช๏ธโžก๏ธ `fastapi.security`.
๐Ÿ‘‰ `SecurityScopes` ๐ŸŽ“ ๐ŸŽ `Request` (`Request` โš™๏ธ ๐Ÿคš ๐Ÿ“จ ๐ŸŽš ๐Ÿ”—).
```Python hl_lines="8 105"
{!../../../docs_src/security/tutorial005.py!}
```
## โš™๏ธ `scopes`
๐Ÿ”ข `security_scopes` ๐Ÿ”œ ๐Ÿ†Ž `SecurityScopes`.
โšซ๏ธ ๐Ÿ”œ โœ”๏ธ ๐Ÿ  `scopes` โฎ๏ธ ๐Ÿ“‡ โš— ๐ŸŒ โ†” โœ” โšซ๏ธ &amp; ๐ŸŒ ๐Ÿ”— ๐Ÿ‘ˆ โš™๏ธ ๐Ÿ‘‰ ๐ŸŽง-๐Ÿ”—. ๐Ÿ‘ˆ โ›“, ๐ŸŒ "โš“๏ธ"... ๐Ÿ‘‰ ๐Ÿ’ช ๐Ÿ”Š ๐Ÿ˜จ, โšซ๏ธ ๐Ÿ”ฌ ๐Ÿ”„ โช ๐Ÿ”›.
`security_scopes` ๐ŸŽš (๐ŸŽ“ `SecurityScopes`) ๐Ÿšš `scope_str` ๐Ÿ”ข โฎ๏ธ ๐Ÿ‘ ๐ŸŽป, ๐Ÿ”Œ ๐Ÿ‘ˆ โ†” ๐Ÿ‘ฝ ๐Ÿš€ (๐Ÿ‘ฅ ๐Ÿ”œ โš™๏ธ โšซ๏ธ).
๐Ÿ‘ฅ โœ `HTTPException` ๐Ÿ‘ˆ ๐Ÿ‘ฅ ๐Ÿ’ช ๐Ÿค-โš™๏ธ (`raise`) โช ๐Ÿ“š โ˜.
๐Ÿ‘‰ โš , ๐Ÿ‘ฅ ๐Ÿ”Œ โ†” ๐Ÿšš (๐Ÿšฅ ๐Ÿ™†) ๐ŸŽป ๐Ÿ‘ฝ ๐Ÿš€ (โš™๏ธ `scope_str`). ๐Ÿ‘ฅ ๐Ÿšฎ ๐Ÿ‘ˆ ๐ŸŽป โš— โ†” `WWW-Authenticate` ๐ŸŽš (๐Ÿ‘‰ ๐Ÿ• ๐Ÿ”Œ).
```Python hl_lines="105 107-115"
{!../../../docs_src/security/tutorial005.py!}
```
## โœ” `username` &amp; ๐Ÿ’ฝ ๐Ÿ’ 
๐Ÿ‘ฅ โœ” ๐Ÿ‘ˆ ๐Ÿ‘ฅ ๐Ÿคš `username`, &amp; โš— โ†”.
&amp; โคด๏ธ ๐Ÿ‘ฅ โœ” ๐Ÿ‘ˆ ๐Ÿ“Š โฎ๏ธ Pydantic ๐Ÿท (โœŠ `ValidationError` โš ), &amp; ๐Ÿšฅ ๐Ÿ‘ฅ ๐Ÿคš โŒ ๐Ÿ‘‚ ๐Ÿฅ™ ๐Ÿค โš–๏ธ โš– ๐Ÿ“Š โฎ๏ธ Pydantic, ๐Ÿ‘ฅ ๐Ÿคš `HTTPException` ๐Ÿ‘ฅ โœ โญ.
๐Ÿ‘ˆ, ๐Ÿ‘ฅ โ„น Pydantic ๐Ÿท `TokenData` โฎ๏ธ ๐Ÿ†• ๐Ÿ  `scopes`.
โš– ๐Ÿ“Š โฎ๏ธ Pydantic ๐Ÿ‘ฅ ๐Ÿ’ช โš’ ๐Ÿ’ญ ๐Ÿ‘ˆ ๐Ÿ‘ฅ โœ”๏ธ, ๐Ÿ–ผ, โšซ๏ธโ” `list` `str` โฎ๏ธ โ†” &amp; `str` โฎ๏ธ `username`.
โ†ฉ๏ธ, ๐Ÿ–ผ, `dict`, โš–๏ธ ๐Ÿ•ณ ๐Ÿ™†, โšซ๏ธ ๐Ÿ’ช ๐Ÿ’” ๐Ÿˆธ โ˜ โช, โš’ โšซ๏ธ ๐Ÿ’‚โ€โ™‚ โš .
๐Ÿ‘ฅ โœ” ๐Ÿ‘ˆ ๐Ÿ‘ฅ โœ”๏ธ ๐Ÿ‘ฉโ€๐Ÿ’ป โฎ๏ธ ๐Ÿ‘ˆ ๐Ÿ†”, &amp; ๐Ÿšฅ ๐Ÿšซ, ๐Ÿ‘ฅ ๐Ÿคš ๐Ÿ‘ˆ ๐ŸŽ โš  ๐Ÿ‘ฅ โœ โญ.
```Python hl_lines="46 116-127"
{!../../../docs_src/security/tutorial005.py!}
```
## โœ” `scopes`
๐Ÿ‘ฅ ๐Ÿ”œ โœ” ๐Ÿ‘ˆ ๐ŸŒ โ†” โœ”, ๐Ÿ‘‰ ๐Ÿ”— &amp; ๐ŸŒ โš“๏ธ (๐Ÿ”Œ *โžก ๐Ÿ› ๏ธ*), ๐Ÿ”Œ โ†” ๐Ÿšš ๐Ÿค ๐Ÿ“จ, โช ๐Ÿคš `HTTPException`.
๐Ÿ‘‰, ๐Ÿ‘ฅ โš™๏ธ `security_scopes.scopes`, ๐Ÿ‘ˆ ๐Ÿ”Œ `list` โฎ๏ธ ๐ŸŒ ๐Ÿ‘ซ โ†” `str`.
```Python hl_lines="128-134"
{!../../../docs_src/security/tutorial005.py!}
```
## ๐Ÿ”— ๐ŸŒฒ &amp; โ†”
โžก๏ธ ๐Ÿ“„ ๐Ÿ”„ ๐Ÿ‘‰ ๐Ÿ”— ๐ŸŒฒ &amp; โ†”.
`get_current_active_user` ๐Ÿ”— โœ”๏ธ ๐ŸŽง-๐Ÿ”— ๐Ÿ”› `get_current_user`, โ†” `"me"` ๐Ÿ“ฃ `get_current_active_user` ๐Ÿ”œ ๐Ÿ”Œ ๐Ÿ“‡ โœ” โ†” `security_scopes.scopes` ๐Ÿšถโ€โ™€๏ธ `get_current_user`.
*โžก ๐Ÿ› ๏ธ* โšซ๏ธ ๐Ÿ“ฃ โ†”, `"items"`, ๐Ÿ‘‰ ๐Ÿ”œ ๐Ÿ“‡ `security_scopes.scopes` ๐Ÿšถโ€โ™€๏ธ `get_current_user`.
๐Ÿ“ฅ โ” ๐Ÿ”— ๐Ÿ”— &amp; โ†” ๐Ÿ‘€ ๐Ÿ’–:
* *โžก ๐Ÿ› ๏ธ* `read_own_items` โœ”๏ธ:
* โœ” โ†” `["items"]` โฎ๏ธ ๐Ÿ”—:
* `get_current_active_user`:
* ๐Ÿ”— ๐Ÿ”ข `get_current_active_user` โœ”๏ธ:
* โœ” โ†” `["me"]` โฎ๏ธ ๐Ÿ”—:
* `get_current_user`:
* ๐Ÿ”— ๐Ÿ”ข `get_current_user` โœ”๏ธ:
* ๐Ÿ™…โ€โ™‚ โ†” โœ” โšซ๏ธ.
* ๐Ÿ”— โš™๏ธ `oauth2_scheme`.
* `security_scopes` ๐Ÿ”ข ๐Ÿ†Ž `SecurityScopes`:
* ๐Ÿ‘‰ `security_scopes` ๐Ÿ”ข โœ”๏ธ ๐Ÿ  `scopes` โฎ๏ธ `list` โš— ๐ŸŒ ๐Ÿ‘ซ โ†” ๐Ÿ“ฃ ๐Ÿ”›,:
* `security_scopes.scopes` ๐Ÿ”œ ๐Ÿ”Œ `["me", "items"]` *โžก ๐Ÿ› ๏ธ* `read_own_items`.
* `security_scopes.scopes` ๐Ÿ”œ ๐Ÿ”Œ `["me"]` *โžก ๐Ÿ› ๏ธ* `read_users_me`, โ†ฉ๏ธ โšซ๏ธ ๐Ÿ“ฃ ๐Ÿ”— `get_current_active_user`.
* `security_scopes.scopes` ๐Ÿ”œ ๐Ÿ”Œ `[]` (๐Ÿ•ณ) *โžก ๐Ÿ› ๏ธ* `read_system_status`, โ†ฉ๏ธ โšซ๏ธ ๐Ÿšซ ๐Ÿ“ฃ ๐Ÿ™† `Security` โฎ๏ธ `scopes`, &amp; ๐Ÿšฎ ๐Ÿ”—, `get_current_user`, ๐Ÿšซ ๐Ÿ“ฃ ๐Ÿ™† `scope` ๐Ÿ‘ฏโ€โ™‚๏ธ.
!!! tip
โš  &amp; "๐ŸŽฑ" ๐Ÿ‘œ ๐Ÿ“ฅ ๐Ÿ‘ˆ `get_current_user` ๐Ÿ”œ โœ”๏ธ ๐ŸŽ ๐Ÿ“‡ `scopes` โœ… ๐Ÿ”  *โžก ๐Ÿ› ๏ธ*.
๐ŸŒ โš“๏ธ ๐Ÿ”› `scopes` ๐Ÿ“ฃ ๐Ÿ”  *โžก ๐Ÿ› ๏ธ* &amp; ๐Ÿ”  ๐Ÿ”— ๐Ÿ”— ๐ŸŒฒ ๐Ÿ‘ˆ ๐ŸŽฏ *โžก ๐Ÿ› ๏ธ*.
## ๐ŸŒ– โ„น ๐Ÿ”ƒ `SecurityScopes`
๐Ÿ‘† ๐Ÿ’ช โš™๏ธ `SecurityScopes` ๐Ÿ™† โ˜, &amp; ๐Ÿ’— ๐Ÿฅ‰, โšซ๏ธ ๐Ÿšซ โœ”๏ธ "๐ŸŒฑ" ๐Ÿ”—.
โšซ๏ธ ๐Ÿ”œ ๐Ÿ•ง โœ”๏ธ ๐Ÿ’‚โ€โ™‚ โ†” ๐Ÿ“ฃ โฎ๏ธ `Security` ๐Ÿ”— &amp; ๐ŸŒ โš“๏ธ **๐Ÿ‘ˆ ๐ŸŽฏ** *โžก ๐Ÿ› ๏ธ* &amp; **๐Ÿ‘ˆ ๐ŸŽฏ** ๐Ÿ”— ๐ŸŒฒ.
โ†ฉ๏ธ `SecurityScopes` ๐Ÿ”œ โœ”๏ธ ๐ŸŒ โ†” ๐Ÿ“ฃ โš“๏ธ, ๐Ÿ‘† ๐Ÿ’ช โš™๏ธ โšซ๏ธ โœ” ๐Ÿ‘ˆ ๐Ÿค โœ”๏ธ ๐Ÿšš โ†” ๐Ÿ‡จ๐Ÿ‡ซ ๐Ÿ”— ๐Ÿ”ข, &amp; โคด๏ธ ๐Ÿ“ฃ ๐ŸŽ โ†” ๐Ÿ“„ ๐ŸŽ *โžก ๐Ÿ› ๏ธ*.
๐Ÿ‘ซ ๐Ÿ”œ โœ… โžก ๐Ÿ”  *โžก ๐Ÿ› ๏ธ*.
## โœ… โšซ๏ธ
๐Ÿšฅ ๐Ÿ‘† ๐Ÿ“‚ ๐Ÿ› ๏ธ ๐Ÿฉบ, ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ”“ &amp; โœ” โ” โ†” ๐Ÿ‘† ๐Ÿ’š โœ”.
<img src="/img/tutorial/security/image11.png">
๐Ÿšฅ ๐Ÿ‘† ๐Ÿšซ ๐Ÿ–Š ๐Ÿ™† โ†”, ๐Ÿ‘† ๐Ÿ”œ "๐Ÿ”“", โœ‹๏ธ ๐Ÿ•โ” ๐Ÿ‘† ๐Ÿ”„ ๐Ÿ” `/users/me/` โš–๏ธ `/users/me/items/` ๐Ÿ‘† ๐Ÿ”œ ๐Ÿคš โŒ ๐Ÿ’ฌ ๐Ÿ‘ˆ ๐Ÿ‘† ๐Ÿšซ โœ”๏ธ ๐Ÿฅƒ โœ”. ๐Ÿ‘† ๐Ÿ”œ ๐Ÿ’ช ๐Ÿ” `/status/`.
&amp; ๐Ÿšฅ ๐Ÿ‘† ๐Ÿ–Š โ†” `me` โœ‹๏ธ ๐Ÿšซ โ†” `items`, ๐Ÿ‘† ๐Ÿ”œ ๐Ÿ’ช ๐Ÿ” `/users/me/` โœ‹๏ธ ๐Ÿšซ `/users/me/items/`.
๐Ÿ‘ˆ โšซ๏ธโ” ๐Ÿ”œ ๐Ÿ”จ ๐Ÿฅ‰ ๐Ÿฅณ ๐Ÿˆธ ๐Ÿ‘ˆ ๐Ÿ”„ ๐Ÿ” 1๏ธโƒฃ ๐Ÿ‘ซ *โžก ๐Ÿ› ๏ธ* โฎ๏ธ ๐Ÿค ๐Ÿšš ๐Ÿ‘ฉโ€๐Ÿ’ป, โš“๏ธ ๐Ÿ”› โ” ๐Ÿ“š โœ” ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿค ๐Ÿˆธ.
## ๐Ÿ”ƒ ๐Ÿฅ‰ ๐Ÿฅณ ๐Ÿ› ๏ธ
๐Ÿ‘‰ ๐Ÿ–ผ ๐Ÿ‘ฅ โš™๏ธ Oauth2๏ธโƒฃ "๐Ÿ”" ๐Ÿ’ง.
๐Ÿ‘‰ โ˜‘ ๐Ÿ•โ” ๐Ÿ‘ฅ ๐Ÿšจ ๐Ÿ‘† ๐Ÿ‘ ๐Ÿˆธ, ๐ŸŽฒ โฎ๏ธ ๐Ÿ‘† ๐Ÿ‘ ๐Ÿ•ธ.
โ†ฉ๏ธ ๐Ÿ‘ฅ ๐Ÿ’ช ๐Ÿ’™ โšซ๏ธ ๐Ÿ“จ `username` &amp; `password`, ๐Ÿ‘ฅ ๐ŸŽ› โšซ๏ธ.
โœ‹๏ธ ๐Ÿšฅ ๐Ÿ‘† ๐Ÿ— Oauth2๏ธโƒฃ ๐Ÿˆธ ๐Ÿ‘ˆ ๐ŸŽ ๐Ÿ”œ ๐Ÿ”— (โžก, ๐Ÿšฅ ๐Ÿ‘† ๐Ÿ— ๐Ÿค ๐Ÿ•โ€๐Ÿฆบ ๐ŸŒ“ ๐Ÿ‘ฑ๐Ÿ“”, ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ”, ๐Ÿ“‚, โ™’๏ธ.) ๐Ÿ‘† ๐Ÿ”œ โš™๏ธ 1๏ธโƒฃ ๐ŸŽ ๐Ÿ’ง.
๐ŸŒ… โš  ๐Ÿ”‘ ๐Ÿ’ง.
๐Ÿ† ๐Ÿ” ๐Ÿ“Ÿ ๐Ÿ’ง, โœ‹๏ธ ๐ŸŒ– ๐Ÿ— ๐Ÿ› ๏ธ โšซ๏ธ ๐Ÿšš ๐ŸŒ… ๐Ÿ“ถ. โšซ๏ธ ๐ŸŒ… ๐Ÿ—, ๐Ÿ“š ๐Ÿ•โ€๐Ÿฆบ ๐Ÿ”š ๐Ÿ†™ โœ” ๐Ÿ”‘ ๐Ÿ’ง.
!!! note
โšซ๏ธ โš  ๐Ÿ‘ˆ ๐Ÿ”  ๐Ÿค ๐Ÿ•โ€๐Ÿฆบ ๐Ÿ“› ๐Ÿ‘ซ ๐Ÿ’ง ๐ŸŽ ๐ŸŒŒ, โš’ โšซ๏ธ ๐Ÿ• ๐Ÿ‘ซ ๐Ÿท.
โœ‹๏ธ ๐Ÿ”š, ๐Ÿ‘ซ ๐Ÿ› ๏ธ ๐ŸŽ Oauth2๏ธโƒฃ ๐Ÿฉ.
**FastAPI** ๐Ÿ”Œ ๐Ÿš™ ๐ŸŒ ๐Ÿ‘ซ Oauth2๏ธโƒฃ ๐Ÿค ๐Ÿ’ง `fastapi.security.oauth2`.
## `Security` ๐Ÿ‘จโ€๐ŸŽจ `dependencies`
๐ŸŽ ๐ŸŒŒ ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ”ฌ `list` `Depends` ๐Ÿ‘จโ€๐ŸŽจ `dependencies` ๐Ÿ”ข (๐Ÿ”ฌ [๐Ÿ”— โžก ๐Ÿ› ๏ธ ๐Ÿ‘จโ€๐ŸŽจ](../../tutorial/dependencies/dependencies-in-path-operation-decorators.md){.internal-link target=_blank}), ๐Ÿ‘† ๐Ÿ’ช โš™๏ธ `Security` โฎ๏ธ `scopes` ๐Ÿ“ค.

382
docs/em/docs/advanced/settings.md

@ -0,0 +1,382 @@
# โš’ &amp; ๐ŸŒ ๐Ÿ”ข
๐Ÿ“š ๐Ÿ’ผ ๐Ÿ‘† ๐Ÿˆธ ๐Ÿ’ช ๐Ÿ’ช ๐Ÿ”ข โš’ โš–๏ธ ๐Ÿ“ณ, ๐Ÿ–ผ ใŠ™ ๐Ÿ”‘, ๐Ÿ’ฝ ๐ŸŽ“, ๐ŸŽ“ ๐Ÿ“ง ๐Ÿ•โ€๐Ÿฆบ, โ™’๏ธ.
๐Ÿ† ๐Ÿ‘ซ โš’ ๐Ÿ”ข (๐Ÿ’ช ๐Ÿ”€), ๐Ÿ’– ๐Ÿ’ฝ ๐Ÿ“›. &amp; ๐Ÿ“š ๐Ÿ’ช ๐Ÿšฟ, ๐Ÿ’– ใŠ™.
๐Ÿ‘‰ ๐Ÿค” โšซ๏ธ โš  ๐Ÿšš ๐Ÿ‘ซ ๐ŸŒ ๐Ÿ”ข ๐Ÿ‘ˆ โœ ๐Ÿˆธ.
## ๐ŸŒ ๐Ÿ”ข
!!! tip
๐Ÿšฅ ๐Ÿ‘† โช ๐Ÿ’ญ โšซ๏ธโ” "๐ŸŒ ๐Ÿ”ข" &amp; โ” โš™๏ธ ๐Ÿ‘ซ, ๐Ÿ’ญ ๐Ÿ†“ ๐Ÿšถ โญ ๐Ÿ“„ ๐Ÿ”›.
<a href="https://en.wikipedia.org/wiki/Environment_variable" class="external-link" target="_blank">๐ŸŒ ๐Ÿ”ข</a> (๐Ÿ’ญ "๐Ÿ‡จ๐Ÿ‡ป {") ๐Ÿ”ข ๐Ÿ‘ˆ ๐Ÿ–– ๐Ÿž ๐Ÿ ๐Ÿ“Ÿ, ๐Ÿƒโ€โ™‚ โš™๏ธ, &amp; ๐Ÿ’ช โœ ๐Ÿ‘† ๐Ÿ ๐Ÿ“Ÿ (โš–๏ธ ๐ŸŽ ๐Ÿ“‹ ๐Ÿ‘).
๐Ÿ‘† ๐Ÿ’ช โœ &amp; โš™๏ธ ๐ŸŒ ๐Ÿ”ข ๐Ÿš, ๐Ÿต ๐Ÿ’†โ€โ™‚ ๐Ÿ:
=== "๐Ÿ’พ, ๐Ÿ‡ธ๐Ÿ‡ป, ๐Ÿšช ๐ŸŽ‰"
<div class="termy">
```console
// You could create an env var MY_NAME with
$ export MY_NAME="Wade Wilson"
// Then you could use it with other programs, like
$ echo "Hello $MY_NAME"
Hello Wade Wilson
```
</div>
=== "๐Ÿšช ๐Ÿ“‹"
<div class="termy">
```console
// Create an env var MY_NAME
$ $Env:MY_NAME = "Wade Wilson"
// Use it with other programs, like
$ echo "Hello $Env:MY_NAME"
Hello Wade Wilson
```
</div>
### โœ ๐Ÿ‡จ๐Ÿ‡ป {๐Ÿ
๐Ÿ‘† ๐Ÿ’ช โœ ๐ŸŒ ๐Ÿ”ข ๐Ÿž ๐Ÿ, ๐Ÿ“ถ (โš–๏ธ โฎ๏ธ ๐Ÿ™† ๐ŸŽ ๐Ÿ‘ฉโ€๐Ÿ”ฌ), &amp; โคด๏ธ โœ ๐Ÿ‘ซ ๐Ÿ.
๐Ÿ–ผ ๐Ÿ‘† ๐Ÿ’ช โœ”๏ธ ๐Ÿ“ `main.py` โฎ๏ธ:
```Python hl_lines="3"
import os
name = os.getenv("MY_NAME", "World")
print(f"Hello {name} from Python")
```
!!! tip
๐Ÿฅˆ โŒ <a href="https://docs.python.org/3.8/library/os.html#os.getenv" class="external-link" target="_blank">`os.getenv()`</a> ๐Ÿ”ข ๐Ÿ’ฒ ๐Ÿ“จ.
๐Ÿšฅ ๐Ÿšซ ๐Ÿšš, โšซ๏ธ `None` ๐Ÿ”ข, ๐Ÿ“ฅ ๐Ÿ‘ฅ ๐Ÿšš `"World"` ๐Ÿ”ข ๐Ÿ’ฒ โš™๏ธ.
โคด๏ธ ๐Ÿ‘† ๐Ÿ’ช ๐Ÿค™ ๐Ÿ‘ˆ ๐Ÿ ๐Ÿ“‹:
<div class="termy">
```console
// Here we don't set the env var yet
$ python main.py
// As we didn't set the env var, we get the default value
Hello World from Python
// But if we create an environment variable first
$ export MY_NAME="Wade Wilson"
// And then call the program again
$ python main.py
// Now it can read the environment variable
Hello Wade Wilson from Python
```
</div>
๐ŸŒ ๐Ÿ”ข ๐Ÿ’ช โš’ ๐Ÿž ๐Ÿ“Ÿ, โœ‹๏ธ ๐Ÿ’ช โœ ๐Ÿ“Ÿ, &amp; ๐Ÿšซ โœ”๏ธ ๐Ÿช (๐Ÿ’• `git`) โฎ๏ธ ๐ŸŽ‚ ๐Ÿ“, โšซ๏ธ โš  โš™๏ธ ๐Ÿ‘ซ ๐Ÿ“ณ โš–๏ธ โš’.
๐Ÿ‘† ๐Ÿ’ช โœ ๐ŸŒ ๐Ÿ”ข ๐Ÿ•ด ๐ŸŽฏ ๐Ÿ“‹ ๐Ÿ‘ผ, ๐Ÿ‘ˆ ๐Ÿ•ด ๐Ÿ’ช ๐Ÿ‘ˆ ๐Ÿ“‹, &amp; ๐Ÿ•ด ๐Ÿšฎ ๐Ÿ“.
๐Ÿ‘ˆ, โœ โšซ๏ธ โ–ถ๏ธ๏ธ โญ ๐Ÿ“‹ โšซ๏ธ, ๐Ÿ”› ๐ŸŽ โธ:
<div class="termy">
```console
// Create an env var MY_NAME in line for this program call
$ MY_NAME="Wade Wilson" python main.py
// Now it can read the environment variable
Hello Wade Wilson from Python
// The env var no longer exists afterwards
$ python main.py
Hello World from Python
```
</div>
!!! tip
๐Ÿ‘† ๐Ÿ’ช โœ ๐ŸŒ… ๐Ÿ”ƒ โšซ๏ธ <a href="https://12factor.net/config" class="external-link" target="_blank">1๏ธโƒฃ2๏ธโƒฃ-โš– ๐Ÿ“ฑ: ๐Ÿ“</a>.
### ๐Ÿ†Ž &amp; ๐Ÿ”ฌ
๐Ÿ‘ซ ๐ŸŒ ๐Ÿ”ข ๐Ÿ’ช ๐Ÿ•ด ๐Ÿต โœ ๐ŸŽป, ๐Ÿ‘ซ ๐Ÿ”ข ๐Ÿ &amp; โœ”๏ธ ๐Ÿ”— โฎ๏ธ ๐ŸŽ ๐Ÿ“‹ &amp; ๐ŸŽ‚ โš™๏ธ (&amp; โฎ๏ธ ๐ŸŽ ๐Ÿƒโ€โ™‚ โš™๏ธ, ๐Ÿ’พ, ๐Ÿšช, ๐Ÿ‡ธ๐Ÿ‡ป).
๐Ÿ‘ˆ โ›“ ๐Ÿ‘ˆ ๐Ÿ™† ๐Ÿ’ฒ โœ ๐Ÿ โšช๏ธโžก๏ธ ๐ŸŒ ๐Ÿ”ข ๐Ÿ”œ `str`, &amp; ๐Ÿ™† ๐Ÿ› ๏ธ ๐ŸŽ ๐Ÿ†Ž โš–๏ธ ๐Ÿ”ฌ โœ”๏ธ ๐Ÿ”จ ๐Ÿ“Ÿ.
## Pydantic `Settings`
๐Ÿ‘, Pydantic ๐Ÿšš ๐Ÿ‘‘ ๐Ÿš™ ๐Ÿต ๐Ÿ‘ซ โš’ ๐Ÿ‘Ÿ โšช๏ธโžก๏ธ ๐ŸŒ ๐Ÿ”ข โฎ๏ธ <a href="https://pydantic-docs.helpmanual.io/usage/settings/" class="external-link" target="_blank">Pydantic: โš’ ๐Ÿงพ</a>.
### โœ `Settings` ๐ŸŽš
๐Ÿ—„ `BaseSettings` โšช๏ธโžก๏ธ Pydantic &amp; โœ ๐ŸŽง-๐ŸŽ“, ๐Ÿ“ถ ๐ŸŒ… ๐Ÿ’– โฎ๏ธ Pydantic ๐Ÿท.
๐ŸŽ ๐ŸŒŒ โฎ๏ธ Pydantic ๐Ÿท, ๐Ÿ‘† ๐Ÿ“ฃ ๐ŸŽ“ ๐Ÿ”ข โฎ๏ธ ๐Ÿ†Ž โœ, &amp; ๐ŸŽฒ ๐Ÿ”ข ๐Ÿ’ฒ.
๐Ÿ‘† ๐Ÿ’ช โš™๏ธ ๐ŸŒ ๐ŸŽ ๐Ÿ”ฌ โš’ &amp; ๐Ÿงฐ ๐Ÿ‘† โš™๏ธ Pydantic ๐Ÿท, ๐Ÿ’– ๐ŸŽ ๐Ÿ“Š ๐Ÿ†Ž &amp; ๐ŸŒ– ๐Ÿ”ฌ โฎ๏ธ `Field()`.
```Python hl_lines="2 5-8 11"
{!../../../docs_src/settings/tutorial001.py!}
```
!!! tip
๐Ÿšฅ ๐Ÿ‘† ๐Ÿ’š ๐Ÿ•ณ โฉ ๐Ÿ“ &amp; ๐Ÿ“‹, ๐Ÿšซ โš™๏ธ ๐Ÿ‘‰ ๐Ÿ–ผ, โš™๏ธ ๐Ÿ 1๏ธโƒฃ ๐Ÿ”›.
โคด๏ธ, ๐Ÿ•โ” ๐Ÿ‘† โœ ๐Ÿ‘ ๐Ÿ‘ˆ `Settings` ๐ŸŽ“ (๐Ÿ‘‰ ๐Ÿ’ผ, `settings` ๐ŸŽš), Pydantic ๐Ÿ”œ โœ ๐ŸŒ ๐Ÿ”ข ๐Ÿ’ผ-๐Ÿ˜› ๐ŸŒŒ,, โ†–-๐Ÿ’ผ ๐Ÿ”ข `APP_NAME` ๐Ÿ”œ โœ ๐Ÿ”ข `app_name`.
โญ โšซ๏ธ ๐Ÿ”œ ๐Ÿ—œ &amp; โœ” ๐Ÿ’ฝ. , ๐Ÿ•โ” ๐Ÿ‘† โš™๏ธ ๐Ÿ‘ˆ `settings` ๐ŸŽš, ๐Ÿ‘† ๐Ÿ”œ โœ”๏ธ ๐Ÿ“Š ๐Ÿ†Ž ๐Ÿ‘† ๐Ÿ“ฃ (โœ… `items_per_user` ๐Ÿ”œ `int`).
### โš™๏ธ `settings`
โคด๏ธ ๐Ÿ‘† ๐Ÿ’ช โš™๏ธ ๐Ÿ†• `settings` ๐ŸŽš ๐Ÿ‘† ๐Ÿˆธ:
```Python hl_lines="18-20"
{!../../../docs_src/settings/tutorial001.py!}
```
### ๐Ÿƒ ๐Ÿ’ฝ
โญ, ๐Ÿ‘† ๐Ÿ”œ ๐Ÿƒ ๐Ÿ’ฝ ๐Ÿšถโ€โ™€๏ธ ๐Ÿ“ณ ๐ŸŒ ๐Ÿ”ข, ๐Ÿ–ผ ๐Ÿ‘† ๐Ÿ’ช โš’ `ADMIN_EMAIL` &amp; `APP_NAME` โฎ๏ธ:
<div class="termy">
```console
$ ADMIN_EMAIL="[email protected]" APP_NAME="ChimichangApp" uvicorn main:app
<span style="color: green;">INFO</span>: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
```
</div>
!!! tip
โš’ ๐Ÿ’— ๐Ÿ‡จ๐Ÿ‡ป {๐Ÿ‘ ๐Ÿ“‹ ๐ŸŽ ๐Ÿ‘ซ โฎ๏ธ ๐Ÿš€, &amp; ๐Ÿšฎ ๐Ÿ‘ซ ๐ŸŒ โญ ๐Ÿ“‹.
&amp; โคด๏ธ `admin_email` โš’ ๐Ÿ”œ โš’ `"[email protected]"`.
`app_name` ๐Ÿ”œ `"ChimichangApp"`.
&amp; `items_per_user` ๐Ÿ”œ ๐Ÿšง ๐Ÿšฎ ๐Ÿ”ข ๐Ÿ’ฒ `50`.
## โš’ โž•1๏ธโƒฃ ๐Ÿ•น
๐Ÿ‘† ๐Ÿ’ช ๐Ÿšฎ ๐Ÿ‘ˆ โš’ โž•1๏ธโƒฃ ๐Ÿ•น ๐Ÿ“ ๐Ÿ‘† ๐Ÿ‘€ [๐Ÿฆ ๐Ÿˆธ - ๐Ÿ’— ๐Ÿ“](../tutorial/bigger-applications.md){.internal-link target=_blank}.
๐Ÿ–ผ, ๐Ÿ‘† ๐Ÿ’ช โœ”๏ธ ๐Ÿ“ `config.py` โฎ๏ธ:
```Python
{!../../../docs_src/settings/app01/config.py!}
```
&amp; โคด๏ธ โš™๏ธ โšซ๏ธ ๐Ÿ“ `main.py`:
```Python hl_lines="3 11-13"
{!../../../docs_src/settings/app01/main.py!}
```
!!! tip
๐Ÿ‘† ๐Ÿ”œ ๐Ÿ’ช ๐Ÿ“ `__init__.py` ๐Ÿ‘† ๐Ÿ‘€ ๐Ÿ”› [๐Ÿฆ ๐Ÿˆธ - ๐Ÿ’— ๐Ÿ“](../tutorial/bigger-applications.md){.internal-link target=_blank}.
## โš’ ๐Ÿ”—
๐Ÿพ โšซ๏ธ 5๏ธโƒฃ๐Ÿ“† โš  ๐Ÿšš โš’ โšช๏ธโžก๏ธ ๐Ÿ”—, โ†ฉ๏ธ โœ”๏ธ ๐ŸŒ ๐ŸŽš โฎ๏ธ `settings` ๐Ÿ‘ˆ โš™๏ธ ๐ŸŒ.
๐Ÿ‘‰ ๐Ÿ’ช โœด๏ธ โš  โฎ๏ธ ๐Ÿ”ฌ, โšซ๏ธ ๐Ÿ“ถ โฉ ๐Ÿ” ๐Ÿ”— โฎ๏ธ ๐Ÿ‘† ๐Ÿ‘ ๐Ÿ›ƒ โš’.
### ๐Ÿ“ ๐Ÿ“
๐Ÿ‘Ÿ โšช๏ธโžก๏ธ โฎ๏ธ ๐Ÿ–ผ, ๐Ÿ‘† `config.py` ๐Ÿ“ ๐Ÿ’ช ๐Ÿ‘€ ๐Ÿ’–:
```Python hl_lines="10"
{!../../../docs_src/settings/app02/config.py!}
```
๐Ÿ‘€ ๐Ÿ‘ˆ ๐Ÿ”œ ๐Ÿ‘ฅ ๐Ÿšซ โœ ๐Ÿ”ข ๐Ÿ‘ `settings = Settings()`.
### ๐Ÿ‘‘ ๐Ÿ“ฑ ๐Ÿ“
๐Ÿ”œ ๐Ÿ‘ฅ โœ ๐Ÿ”— ๐Ÿ‘ˆ ๐Ÿ“จ ๐Ÿ†• `config.Settings()`.
```Python hl_lines="5 11-12"
{!../../../docs_src/settings/app02/main.py!}
```
!!! tip
๐Ÿ‘ฅ ๐Ÿ”œ ๐Ÿ”ฌ `@lru_cache()` ๐Ÿ–.
๐Ÿ”œ ๐Ÿ‘† ๐Ÿ’ช ๐Ÿค” `get_settings()` ๐Ÿ˜ ๐Ÿ”ข.
&amp; โคด๏ธ ๐Ÿ‘ฅ ๐Ÿ’ช ๐Ÿšš โšซ๏ธ โšช๏ธโžก๏ธ *โžก ๐Ÿ› ๏ธ ๐Ÿ”ข* ๐Ÿ”— &amp; โš™๏ธ โšซ๏ธ ๐Ÿ™† ๐Ÿ‘ฅ ๐Ÿ’ช โšซ๏ธ.
```Python hl_lines="16 18-20"
{!../../../docs_src/settings/app02/main.py!}
```
### โš’ &amp; ๐Ÿ”ฌ
โคด๏ธ โšซ๏ธ ๐Ÿ”œ ๐Ÿ“ถ โฉ ๐Ÿšš ๐ŸŽ โš’ ๐ŸŽš โฎ๏ธ ๐Ÿ”ฌ ๐Ÿ— ๐Ÿ”— ๐Ÿ” `get_settings`:
```Python hl_lines="9-10 13 21"
{!../../../docs_src/settings/app02/test_main.py!}
```
๐Ÿ”— ๐Ÿ” ๐Ÿ‘ฅ โš’ ๐Ÿ†• ๐Ÿ’ฒ `admin_email` ๐Ÿ•โ” ๐Ÿ— ๐Ÿ†• `Settings` ๐ŸŽš, &amp; โคด๏ธ ๐Ÿ‘ฅ ๐Ÿ“จ ๐Ÿ‘ˆ ๐Ÿ†• ๐ŸŽš.
โคด๏ธ ๐Ÿ‘ฅ ๐Ÿ’ช ๐Ÿ’ฏ ๐Ÿ‘ˆ โšซ๏ธ โš™๏ธ.
## ๐Ÿ‘‚ `.env` ๐Ÿ“
๐Ÿšฅ ๐Ÿ‘† โœ”๏ธ ๐Ÿ“š โš’ ๐Ÿ‘ˆ ๐ŸŽฒ ๐Ÿ”€ ๐Ÿ“š, ๐ŸŽฒ ๐ŸŽ ๐ŸŒ, โšซ๏ธ 5๏ธโƒฃ๐Ÿ“† โš  ๐Ÿšฎ ๐Ÿ‘ซ ๐Ÿ”› ๐Ÿ“ &amp; โคด๏ธ โœ ๐Ÿ‘ซ โšช๏ธโžก๏ธ โšซ๏ธ ๐Ÿšฅ ๐Ÿ‘ซ ๐ŸŒ ๐Ÿ”ข.
๐Ÿ‘‰ ๐Ÿ’ก โš  ๐Ÿฅƒ ๐Ÿ‘ˆ โšซ๏ธ โœ”๏ธ ๐Ÿ“›, ๐Ÿ‘ซ ๐ŸŒ ๐Ÿ”ข ๐Ÿ›Ž ๐Ÿฅ‰ ๐Ÿ“ `.env`, &amp; ๐Ÿ“ ๐Ÿค™ "๐Ÿ‡จ๐Ÿ‡ป".
!!! tip
๐Ÿ“ โ–ถ๏ธ โฎ๏ธ โฃ (`.`) ๐Ÿ•ตโ€โ™‚ ๐Ÿ“ ๐Ÿ–ฅ-๐Ÿ’– โš™๏ธ, ๐Ÿ’– ๐Ÿ’พ &amp; ๐Ÿ‡ธ๐Ÿ‡ป.
โœ‹๏ธ ๐Ÿ‡จ๐Ÿ‡ป ๐Ÿ“ ๐Ÿšซ ๐Ÿค™ โœ”๏ธ โœ”๏ธ ๐Ÿ‘ˆ โ˜‘ ๐Ÿ“.
Pydantic โœ”๏ธ ๐Ÿ•โ€๐Ÿฆบ ๐Ÿ‘‚ โšช๏ธโžก๏ธ ๐Ÿ‘‰ ๐Ÿ†Ž ๐Ÿ“ โš™๏ธ ๐Ÿ”ข ๐Ÿ—ƒ. ๐Ÿ‘† ๐Ÿ’ช โœ ๐ŸŒ– <a href="https://pydantic-docs.helpmanual.io/usage/settings/#dotenv-env-support" class="external-link" target="_blank">Pydantic โš’: ๐Ÿ‡จ๐Ÿ‡ป (.๐Ÿ‡จ๐Ÿ‡ป) ๐Ÿ•โ€๐Ÿฆบ</a>.
!!! tip
๐Ÿ‘‰ ๐Ÿ‘ท, ๐Ÿ‘† ๐Ÿ’ช `pip install python-dotenv`.
### `.env` ๐Ÿ“
๐Ÿ‘† ๐Ÿ’ช โœ”๏ธ `.env` ๐Ÿ“ โฎ๏ธ:
```bash
ADMIN_EMAIL="[email protected]"
APP_NAME="ChimichangApp"
```
### โœ โš’ โšช๏ธโžก๏ธ `.env`
&amp; โคด๏ธ โ„น ๐Ÿ‘† `config.py` โฎ๏ธ:
```Python hl_lines="9-10"
{!../../../docs_src/settings/app03/config.py!}
```
๐Ÿ“ฅ ๐Ÿ‘ฅ โœ ๐ŸŽ“ `Config` ๐Ÿ”˜ ๐Ÿ‘† Pydantic `Settings` ๐ŸŽ“, &amp; โš’ `env_file` ๐Ÿ“ โฎ๏ธ ๐Ÿ‡จ๐Ÿ‡ป ๐Ÿ“ ๐Ÿ‘ฅ ๐Ÿ’š โš™๏ธ.
!!! tip
`Config` ๐ŸŽ“ โš™๏ธ Pydantic ๐Ÿ“ณ. ๐Ÿ‘† ๐Ÿ’ช โœ ๐ŸŒ– <a href="https://pydantic-docs.helpmanual.io/usage/model_config/" class="external-link" target="_blank">Pydantic ๐Ÿท ๐Ÿ“</a>
### ๐Ÿ— `Settings` ๐Ÿ•ด ๐Ÿ• โฎ๏ธ `lru_cache`
๐Ÿ‘‚ ๐Ÿ“ โšช๏ธโžก๏ธ ๐Ÿ’พ ๐Ÿ›Ž โš  (๐ŸŒ) ๐Ÿ› ๏ธ, ๐Ÿ‘† ๐ŸŽฒ ๐Ÿ’š โšซ๏ธ ๐Ÿ•ด ๐Ÿ• &amp; โคด๏ธ ๐Ÿค-โš™๏ธ ๐ŸŽ โš’ ๐ŸŽš, โ†ฉ๏ธ ๐Ÿ‘‚ โšซ๏ธ ๐Ÿ”  ๐Ÿ“จ.
โœ‹๏ธ ๐Ÿ”  ๐Ÿ•ฐ ๐Ÿ‘ฅ:
```Python
Settings()
```
๐Ÿ†• `Settings` ๐ŸŽš ๐Ÿ”œ โœ, &amp; ๐Ÿ— โšซ๏ธ ๐Ÿ”œ โœ `.env` ๐Ÿ“ ๐Ÿ”„.
๐Ÿšฅ ๐Ÿ”— ๐Ÿ”ข ๐Ÿ’–:
```Python
def get_settings():
return Settings()
```
๐Ÿ‘ฅ ๐Ÿ”œ โœ ๐Ÿ‘ˆ ๐ŸŽš ๐Ÿ”  ๐Ÿ“จ, &amp; ๐Ÿ‘ฅ ๐Ÿ”œ ๐Ÿ‘‚ `.env` ๐Ÿ“ ๐Ÿ”  ๐Ÿ“จ. ๐Ÿ‘ถ ๐Ÿ‘ถ
โœ‹๏ธ ๐Ÿ‘ฅ โš™๏ธ `@lru_cache()` ๐Ÿ‘จโ€๐ŸŽจ ๐Ÿ”› ๐Ÿ”, `Settings` ๐ŸŽš ๐Ÿ”œ โœ ๐Ÿ•ด ๐Ÿ•, ๐Ÿฅ‡ ๐Ÿ•ฐ โšซ๏ธ ๐Ÿค™. ๐Ÿ‘ถ ๐Ÿ‘ถ
```Python hl_lines="1 10"
{!../../../docs_src/settings/app03/main.py!}
```
โคด๏ธ ๐Ÿ™† ๐Ÿ ๐Ÿค™ `get_settings()` ๐Ÿ”— โญ ๐Ÿ“จ, โ†ฉ๏ธ ๐Ÿ› ๏ธ ๐Ÿ”— ๐Ÿ“Ÿ `get_settings()` &amp; ๐Ÿ— ๐Ÿ†• `Settings` ๐ŸŽš, โšซ๏ธ ๐Ÿ”œ ๐Ÿ“จ ๐ŸŽ ๐ŸŽš ๐Ÿ‘ˆ ๐Ÿ“จ ๐Ÿ”› ๐Ÿฅ‡ ๐Ÿค™, ๐Ÿ”„ &amp; ๐Ÿ”„.
#### `lru_cache` ๐Ÿ“ก โ„น
`@lru_cache()` ๐Ÿ”€ ๐Ÿ”ข โšซ๏ธ ๐ŸŽ€ ๐Ÿ“จ ๐ŸŽ ๐Ÿ’ฒ ๐Ÿ‘ˆ ๐Ÿ“จ ๐Ÿฅ‡ ๐Ÿ•ฐ, โ†ฉ๏ธ ๐Ÿ’ป โšซ๏ธ ๐Ÿ”„, ๐Ÿ› ๏ธ ๐Ÿ“Ÿ ๐Ÿ”ข ๐Ÿ”  ๐Ÿ•ฐ.
, ๐Ÿ”ข ๐Ÿ”› โšซ๏ธ ๐Ÿ”œ ๐Ÿ› ๏ธ ๐Ÿ• ๐Ÿ”  ๐ŸŒ€ โŒ. &amp; โคด๏ธ ๐Ÿ’ฒ ๐Ÿ“จ ๐Ÿ”  ๐Ÿ‘ˆ ๐ŸŒ€ โŒ ๐Ÿ”œ โš™๏ธ ๐Ÿ”„ &amp; ๐Ÿ”„ ๐Ÿ•โ” ๐Ÿ”ข ๐Ÿค™ โฎ๏ธ โšซ๏ธโ” ๐ŸŽ ๐ŸŒ€ โŒ.
๐Ÿ–ผ, ๐Ÿšฅ ๐Ÿ‘† โœ”๏ธ ๐Ÿ”ข:
```Python
@lru_cache()
def say_hi(name: str, salutation: str = "Ms."):
return f"Hello {salutation} {name}"
```
๐Ÿ‘† ๐Ÿ“‹ ๐Ÿ’ช ๐Ÿ› ๏ธ ๐Ÿ’– ๐Ÿ‘‰:
```mermaid
sequenceDiagram
participant code as Code
participant function as say_hi()
participant execute as Execute function
rect rgba(0, 255, 0, .1)
code ->> function: say_hi(name="Camila")
function ->> execute: execute function code
execute ->> code: return the result
end
rect rgba(0, 255, 255, .1)
code ->> function: say_hi(name="Camila")
function ->> code: return stored result
end
rect rgba(0, 255, 0, .1)
code ->> function: say_hi(name="Rick")
function ->> execute: execute function code
execute ->> code: return the result
end
rect rgba(0, 255, 0, .1)
code ->> function: say_hi(name="Rick", salutation="Mr.")
function ->> execute: execute function code
execute ->> code: return the result
end
rect rgba(0, 255, 255, .1)
code ->> function: say_hi(name="Rick")
function ->> code: return stored result
end
rect rgba(0, 255, 255, .1)
code ->> function: say_hi(name="Camila")
function ->> code: return stored result
end
```
๐Ÿ’ผ ๐Ÿ‘† ๐Ÿ”— `get_settings()`, ๐Ÿ”ข ๐Ÿšซ โœŠ ๐Ÿ™† โŒ, โšซ๏ธ ๐Ÿ•ง ๐Ÿ“จ ๐ŸŽ ๐Ÿ’ฒ.
๐Ÿ‘ˆ ๐ŸŒŒ, โšซ๏ธ ๐ŸŽญ ๐ŸŒ– ๐Ÿšฅ โšซ๏ธ ๐ŸŒ ๐Ÿ”ข. โœ‹๏ธ โšซ๏ธ โš™๏ธ ๐Ÿ”— ๐Ÿ”ข, โคด๏ธ ๐Ÿ‘ฅ ๐Ÿ’ช ๐Ÿ” โšซ๏ธ ๐Ÿ’ช ๐Ÿ”ฌ.
`@lru_cache()` ๐Ÿ• `functools` โ” ๐Ÿ• ๐Ÿ ๐Ÿฉ ๐Ÿ—ƒ, ๐Ÿ‘† ๐Ÿ’ช โœ ๐ŸŒ… ๐Ÿ”ƒ โšซ๏ธ <a href="https://docs.python.org/3/library/functools.html#functools.lru_cache" class="external-link" target="_blank">๐Ÿ ๐Ÿฉบ `@lru_cache()`</a>.
## ๐ŸŒƒ
๐Ÿ‘† ๐Ÿ’ช โš™๏ธ Pydantic โš’ ๐Ÿต โš’ โš–๏ธ ๐Ÿ“ณ ๐Ÿ‘† ๐Ÿˆธ, โฎ๏ธ ๐ŸŒ ๐Ÿ‹๏ธ Pydantic ๐Ÿท.
* โš™๏ธ ๐Ÿ”— ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ“‰ ๐Ÿ”ฌ.
* ๐Ÿ‘† ๐Ÿ’ช โš™๏ธ `.env` ๐Ÿ“ โฎ๏ธ โšซ๏ธ.
* โš™๏ธ `@lru_cache()` โžก๏ธ ๐Ÿ‘† โŽ ๐Ÿ‘‚ ๐Ÿ‡จ๐Ÿ‡ป ๐Ÿ“ ๐Ÿ”„ &amp; ๐Ÿ”„ ๐Ÿ”  ๐Ÿ“จ, โช ๐Ÿค ๐Ÿ‘† ๐Ÿ” โšซ๏ธ โฎ๏ธ ๐Ÿ”ฌ.

529
docs/em/docs/advanced/sql-databases-peewee.md

@ -0,0 +1,529 @@
# ๐Ÿ—„ (๐Ÿ”—) ๐Ÿ’ฝ โฎ๏ธ ๐Ÿ’
!!! warning
๐Ÿšฅ ๐Ÿ‘† โ–ถ๏ธ, ๐Ÿ”ฐ [๐Ÿ—„ (๐Ÿ”—) ๐Ÿ’ฝ](../tutorial/sql-databases.md){.internal-link target=_blank} ๐Ÿ‘ˆ โš™๏ธ ๐Ÿ‡ธ๐Ÿ‡ฒ ๐Ÿ”œ ๐Ÿฅƒ.
๐Ÿ’ญ ๐Ÿ†“ ๐Ÿšถ ๐Ÿ‘‰.
๐Ÿšฅ ๐Ÿ‘† โ–ถ๏ธ ๐Ÿ— โšช๏ธโžก๏ธ ๐Ÿ–Œ, ๐Ÿ‘† ๐ŸŽฒ ๐Ÿ‘ป ๐Ÿ“† โฎ๏ธ ๐Ÿ‡ธ๐Ÿ‡ฒ ๐Ÿœ ([๐Ÿ—„ (๐Ÿ”—) ๐Ÿ’ฝ](../tutorial/sql-databases.md){.internal-link target=_blank}), โš–๏ธ ๐Ÿ™† ๐ŸŽ ๐Ÿ” ๐Ÿœ.
๐Ÿšฅ ๐Ÿ‘† โช โœ”๏ธ ๐Ÿ“Ÿ ๐Ÿงข ๐Ÿ‘ˆ โš™๏ธ <a href="https://docs.peewee-orm.com/en/latest/" class="external-link" target="_blank">๐Ÿ’ ๐Ÿœ</a>, ๐Ÿ‘† ๐Ÿ’ช โœ… ๐Ÿ“ฅ โ” โš™๏ธ โšซ๏ธ โฎ๏ธ **FastAPI**.
!!! warning "๐Ÿ 3๏ธโƒฃ.7๏ธโƒฃ โž• โœ”"
๐Ÿ‘† ๐Ÿ”œ ๐Ÿ’ช ๐Ÿ 3๏ธโƒฃ.7๏ธโƒฃ โš–๏ธ ๐Ÿ”› ๐Ÿ”’ โš™๏ธ ๐Ÿ’ โฎ๏ธ FastAPI.
## ๐Ÿ’ ๐Ÿ”
๐Ÿ’ ๐Ÿšซ ๐Ÿ”ง ๐Ÿ” ๐Ÿ› ๏ธ, โš–๏ธ โฎ๏ธ ๐Ÿ‘ซ ๐Ÿคฏ.
๐Ÿ’ โœ”๏ธ ๐Ÿ‹๏ธ ๐Ÿ”‘ ๐Ÿ”ƒ ๐Ÿšฎ ๐Ÿ”ข &amp; ๐Ÿ”ƒ โ” โšซ๏ธ ๐Ÿ”œ โš™๏ธ.
๐Ÿšฅ ๐Ÿ‘† ๐Ÿ› ๏ธ ๐Ÿˆธ โฎ๏ธ ๐Ÿ— ๐Ÿšซ-๐Ÿ” ๐Ÿ› ๏ธ, &amp; ๐Ÿ’ช ๐Ÿ‘ท โฎ๏ธ ๐ŸŒ ๐Ÿšฎ ๐Ÿ”ข, **โšซ๏ธ ๐Ÿ’ช ๐Ÿ‘‘ ๐Ÿงฐ**.
โœ‹๏ธ ๐Ÿšฅ ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ”€ ๐Ÿ”ข, ๐Ÿ•โ€๐Ÿฆบ ๐ŸŒ– ๐ŸŒ˜ 1๏ธโƒฃ ๐Ÿ” ๐Ÿ’ฝ, ๐Ÿ‘ท โฎ๏ธ ๐Ÿ” ๐Ÿ› ๏ธ (๐Ÿ’– FastAPI), โ™’๏ธ, ๐Ÿ‘† ๐Ÿ”œ ๐Ÿ’ช ๐Ÿšฎ ๐Ÿ— โž• ๐Ÿ“Ÿ ๐Ÿ” ๐Ÿ‘ˆ ๐Ÿ”ข.
๐Ÿ‘, โšซ๏ธ ๐Ÿ’ช โšซ๏ธ, &amp; ๐Ÿ“ฅ ๐Ÿ‘† ๐Ÿ”œ ๐Ÿ‘€ โšซ๏ธโ” โšซ๏ธโ” ๐Ÿ“Ÿ ๐Ÿ‘† โœ”๏ธ ๐Ÿšฎ ๐Ÿ’ช โš™๏ธ ๐Ÿ’ โฎ๏ธ FastAPI.
!!! note "๐Ÿ“ก โ„น"
๐Ÿ‘† ๐Ÿ’ช โœ ๐ŸŒ… ๐Ÿ”ƒ ๐Ÿ’ ๐Ÿง ๐Ÿ”ƒ ๐Ÿ” ๐Ÿ <a href="https://docs.peewee-orm.com/en/latest/peewee/database.html#async-with-gevent" class="external-link" target="_blank">๐Ÿฉบ</a>, <a href="https://github.com/coleifer/peewee/issues/263#issuecomment-517347032" class="external-link" target="_blank">โ”</a>, <a href="https://github.com/coleifer/peewee/pull/2072#issuecomment-563215132" class="external-link" target="_blank">๐Ÿ‡ต๐Ÿ‡ท</a>.
## ๐ŸŽ ๐Ÿ“ฑ
๐Ÿ‘ฅ ๐Ÿ”œ โœ ๐ŸŽ ๐Ÿˆธ ๐Ÿ‡ธ๐Ÿ‡ฒ ๐Ÿ”ฐ ([๐Ÿ—„ (๐Ÿ”—) ๐Ÿ’ฝ](../tutorial/sql-databases.md){.internal-link target=_blank}).
๐ŸŒ… ๐Ÿ“Ÿ ๐Ÿค™ ๐ŸŽ.
, ๐Ÿ‘ฅ ๐Ÿ”œ ๐ŸŽฏ ๐Ÿ•ด ๐Ÿ”› ๐Ÿ”บ.
## ๐Ÿ“ ๐Ÿ“Š
โžก๏ธ ๐Ÿ’ฌ ๐Ÿ‘† โœ”๏ธ ๐Ÿ“ ๐Ÿ“› `my_super_project` ๐Ÿ‘ˆ ๐Ÿ”Œ ๐ŸŽง-๐Ÿ“ ๐Ÿค™ `sql_app` โฎ๏ธ ๐Ÿ“Š ๐Ÿ’– ๐Ÿ‘‰:
```
.
โ””โ”€โ”€ sql_app
โ”œโ”€โ”€ __init__.py
โ”œโ”€โ”€ crud.py
โ”œโ”€โ”€ database.py
โ”œโ”€โ”€ main.py
โ””โ”€โ”€ schemas.py
```
๐Ÿ‘‰ ๐ŸŒ– ๐ŸŽ ๐Ÿ“Š ๐Ÿ‘ฅ โœ”๏ธ ๐Ÿ‡ธ๐Ÿ‡ฒ ๐Ÿ”ฐ.
๐Ÿ”œ โžก๏ธ ๐Ÿ‘€ โšซ๏ธโ” ๐Ÿ”  ๐Ÿ“/๐Ÿ•น ๐Ÿ”จ.
## โœ ๐Ÿ’ ๐Ÿ•
โžก๏ธ ๐Ÿ”— ๐Ÿ“ `sql_app/database.py`.
### ๐Ÿฉ ๐Ÿ’ ๐Ÿ“Ÿ
โžก๏ธ ๐Ÿฅ‡ โœ… ๐ŸŒ ๐Ÿ˜ ๐Ÿ’ ๐Ÿ“Ÿ, โœ ๐Ÿ’ ๐Ÿ’ฝ:
```Python hl_lines="3 5 22"
{!../../../docs_src/sql_databases_peewee/sql_app/database.py!}
```
!!! tip
โœ”๏ธ ๐Ÿคฏ ๐Ÿ‘ˆ ๐Ÿšฅ ๐Ÿ‘† ๐Ÿ’š โš™๏ธ ๐ŸŽ ๐Ÿ’ฝ, ๐Ÿ’– โœณ, ๐Ÿ‘† ๐Ÿšซ ๐Ÿšซ ๐Ÿ”€ ๐ŸŽป. ๐Ÿ‘† ๐Ÿ”œ ๐Ÿ’ช โš™๏ธ ๐ŸŽ ๐Ÿ’ ๐Ÿ’ฝ ๐ŸŽ“.
#### ๐Ÿ—’
โŒ:
```Python
check_same_thread=False
```
๐ŸŒ“ 1๏ธโƒฃ ๐Ÿ‡ธ๐Ÿ‡ฒ ๐Ÿ”ฐ:
```Python
connect_args={"check_same_thread": False}
```
...โšซ๏ธ ๐Ÿ’ช ๐Ÿ•ด `SQLite`.
!!! info "๐Ÿ“ก โ„น"
โšซ๏ธโ” ๐ŸŽ ๐Ÿ“ก โ„น [๐Ÿ—„ (๐Ÿ”—) ๐Ÿ’ฝ](../tutorial/sql-databases.md#note){.internal-link target=_blank} โœ”.
### โš’ ๐Ÿ’ ๐Ÿ”-๐Ÿ”— `PeeweeConnectionState`
๐Ÿ‘‘ โ” โฎ๏ธ ๐Ÿ’ &amp; FastAPI ๐Ÿ‘ˆ ๐Ÿ’ โš“๏ธ ๐Ÿ™‡ ๐Ÿ”› <a href="https://docs.python.org/3/library/threading.html#thread-local-data" class="external-link" target="_blank">๐Ÿ `threading.local`</a>, &amp; โšซ๏ธ ๐Ÿšซ โœ”๏ธ ๐ŸŽฏ ๐ŸŒŒ ๐Ÿ” โšซ๏ธ โš–๏ธ โžก๏ธ ๐Ÿ‘† ๐Ÿต ๐Ÿ”—/๐ŸŽ‰ ๐Ÿ”— (๐Ÿ”จ ๐Ÿ‡ธ๐Ÿ‡ฒ ๐Ÿ”ฐ).
&amp; `threading.local` ๐Ÿšซ ๐Ÿ”— โฎ๏ธ ๐Ÿ†• ๐Ÿ” โš’ ๐Ÿ› ๐Ÿ.
!!! note "๐Ÿ“ก โ„น"
`threading.local` โš™๏ธ โœ”๏ธ "๐ŸŽฑ" ๐Ÿ”ข ๐Ÿ‘ˆ โœ”๏ธ ๐ŸŽ ๐Ÿ’ฒ ๐Ÿ”  ๐Ÿงต.
๐Ÿ‘‰ โš  ๐Ÿ— ๐Ÿ› ๏ธ ๐Ÿ— โœ”๏ธ 1๏ธโƒฃ ๐Ÿ‘ ๐Ÿงต ๐Ÿ“ ๐Ÿ“จ, ๐Ÿ™…โ€โ™‚ ๐ŸŒ–, ๐Ÿ™…โ€โ™‚ ๐ŸŒ˜.
โš™๏ธ ๐Ÿ‘‰, ๐Ÿ”  ๐Ÿ“จ ๐Ÿ”œ โœ”๏ธ ๐Ÿšฎ ๐Ÿ‘ ๐Ÿ’ฝ ๐Ÿ”—/๐ŸŽ‰, โ” โ˜‘ ๐Ÿ ๐Ÿฅ….
โœ‹๏ธ FastAPI, โš™๏ธ ๐Ÿ†• ๐Ÿ” โš’, ๐Ÿ’ช ๐Ÿต ๐ŸŒ… ๐ŸŒ˜ 1๏ธโƒฃ ๐Ÿ“จ ๐Ÿ”› ๐ŸŽ ๐Ÿงต. &amp; ๐ŸŽ ๐Ÿ•ฐ, ๐Ÿ‘ ๐Ÿ“จ, โšซ๏ธ ๐Ÿ’ช ๐Ÿƒ ๐Ÿ’— ๐Ÿ‘œ ๐ŸŽ ๐Ÿงต (๐Ÿงต), โš“๏ธ ๐Ÿ”› ๐Ÿšฅ ๐Ÿ‘† โš™๏ธ `async def` โš–๏ธ ๐Ÿ˜ `def`. ๐Ÿ‘‰ โšซ๏ธโ” ๐Ÿค ๐ŸŒ ๐ŸŽญ ๐Ÿ“ˆ FastAPI.
โœ‹๏ธ ๐Ÿ 3๏ธโƒฃ.7๏ธโƒฃ &amp; ๐Ÿ”› ๐Ÿšš ๐ŸŒ– ๐Ÿง ๐ŸŽ› `threading.local`, ๐Ÿ‘ˆ ๐Ÿ’ช โš™๏ธ ๐Ÿฅ‰ ๐ŸŒโ” `threading.local` ๐Ÿ”œ โš™๏ธ, โœ‹๏ธ ๐Ÿ”— โฎ๏ธ ๐Ÿ†• ๐Ÿ” โš’.
๐Ÿ‘ฅ ๐Ÿ”œ โš™๏ธ ๐Ÿ‘ˆ. โšซ๏ธ ๐Ÿค™ <a href="https://docs.python.org/3/library/contextvars.html" class="external-link" target="_blank">`contextvars`</a>.
๐Ÿ‘ฅ ๐Ÿ”œ ๐Ÿ” ๐Ÿ”— ๐Ÿ• ๐Ÿ’ ๐Ÿ‘ˆ โš™๏ธ `threading.local` &amp; โŽ ๐Ÿ‘ซ โฎ๏ธ `contextvars`, โฎ๏ธ ๐Ÿ”— โ„น.
๐Ÿ‘‰ 5๏ธโƒฃ๐Ÿ“† ๐Ÿ˜‘ ๐Ÿ– ๐Ÿ— (&amp; โšซ๏ธ ๐Ÿค™), ๐Ÿ‘† ๐Ÿšซ ๐Ÿค™ ๐Ÿ’ช ๐Ÿ• ๐Ÿค” โ” โšซ๏ธ ๐Ÿ‘ท โš™๏ธ โšซ๏ธ.
๐Ÿ‘ฅ ๐Ÿ”œ โœ `PeeweeConnectionState`:
```Python hl_lines="10-19"
{!../../../docs_src/sql_databases_peewee/sql_app/database.py!}
```
๐Ÿ‘‰ ๐ŸŽ“ ๐Ÿ˜– โšช๏ธโžก๏ธ ๐ŸŽ ๐Ÿ”— ๐ŸŽ“ โš™๏ธ ๐Ÿ’.
โšซ๏ธ โœ”๏ธ ๐ŸŒ โš› โš’ ๐Ÿ’ โš™๏ธ `contextvars` โ†ฉ๏ธ `threading.local`.
`contextvars` ๐Ÿ‘ท ๐Ÿ– ๐ŸŽ ๐ŸŒ˜ `threading.local`. โœ‹๏ธ ๐ŸŽ‚ ๐Ÿ’ ๐Ÿ”— ๐Ÿ“Ÿ ๐Ÿค” ๐Ÿ‘ˆ ๐Ÿ‘‰ ๐ŸŽ“ ๐Ÿ‘ท โฎ๏ธ `threading.local`.
, ๐Ÿ‘ฅ ๐Ÿ’ช โž• ๐ŸŽฑ โš’ โšซ๏ธ ๐Ÿ‘ท ๐Ÿšฅ โšซ๏ธ โš™๏ธ `threading.local`. `__init__`, `__setattr__`, &amp; `__getattr__` ๐Ÿ› ๏ธ ๐ŸŒ โœ” ๐ŸŽฑ ๐Ÿ‘‰ โš™๏ธ ๐Ÿ’ ๐Ÿต ๐Ÿค” ๐Ÿ‘ˆ โšซ๏ธ ๐Ÿ”œ ๐Ÿ”— โฎ๏ธ FastAPI.
!!! tip
๐Ÿ‘‰ ๐Ÿ”œ โš’ ๐Ÿ’ ๐ŸŽญ โ˜‘ ๐Ÿ•โ” โš™๏ธ โฎ๏ธ FastAPI. ๐Ÿšซ ๐ŸŽฒ ๐Ÿ“‚ โš–๏ธ ๐Ÿ“ช ๐Ÿ”— ๐Ÿ‘ˆ โž– โš™๏ธ, ๐Ÿ— โŒ, โ™’๏ธ.
โœ‹๏ธ โšซ๏ธ ๐Ÿšซ ๐Ÿค ๐Ÿ’ ๐Ÿ” ๐Ÿ’Ž-๐Ÿ‹๏ธ. ๐Ÿ‘† ๐Ÿ”œ โš™๏ธ ๐Ÿ˜ `def` ๐Ÿ”ข &amp; ๐Ÿšซ `async def`.
### โš™๏ธ ๐Ÿ›ƒ `PeeweeConnectionState` ๐ŸŽ“
๐Ÿ”œ, ๐Ÿ“ `._state` ๐Ÿ”— ๐Ÿ”ข ๐Ÿ’ ๐Ÿ’ฝ `db` ๐ŸŽš โš™๏ธ ๐Ÿ†• `PeeweeConnectionState`:
```Python hl_lines="24"
{!../../../docs_src/sql_databases_peewee/sql_app/database.py!}
```
!!! tip
โš’ ๐Ÿ’ญ ๐Ÿ‘† ๐Ÿ“ `db._state` *โฎ๏ธ* ๐Ÿ— `db`.
!!! tip
๐Ÿ‘† ๐Ÿ”œ ๐ŸŽ ๐Ÿ™† ๐ŸŽ ๐Ÿ’ ๐Ÿ’ฝ, ๐Ÿ”Œ `PostgresqlDatabase`, `MySQLDatabase`, โ™’๏ธ.
## โœ ๐Ÿ’ฝ ๐Ÿท
โžก๏ธ ๐Ÿ”œ ๐Ÿ‘€ ๐Ÿ“ `sql_app/models.py`.
### โœ ๐Ÿ’ ๐Ÿท ๐Ÿ‘† ๐Ÿ’ฝ
๐Ÿ”œ โœ ๐Ÿ’ ๐Ÿท (๐ŸŽ“) `User` &amp; `Item`.
๐Ÿ‘‰ ๐ŸŽ ๐Ÿ‘† ๐Ÿ”œ ๐Ÿšฅ ๐Ÿ‘† โฉ ๐Ÿ’ ๐Ÿ”ฐ &amp; โ„น ๐Ÿท โœ”๏ธ ๐ŸŽ ๐Ÿ’ฝ ๐Ÿ‡ธ๐Ÿ‡ฒ ๐Ÿ”ฐ.
!!! tip
๐Ÿ’ โš™๏ธ โš– "**๐Ÿท**" ๐Ÿ”— ๐Ÿ‘‰ ๐ŸŽ“ &amp; ๐Ÿ‘ ๐Ÿ‘ˆ ๐Ÿ”— โฎ๏ธ ๐Ÿ’ฝ.
โœ‹๏ธ Pydantic โš™๏ธ โš– "**๐Ÿท**" ๐Ÿ”— ๐Ÿ•ณ ๐ŸŽ, ๐Ÿ’ฝ ๐Ÿ”ฌ, ๐Ÿ› ๏ธ, &amp; ๐Ÿงพ ๐ŸŽ“ &amp; ๐Ÿ‘.
๐Ÿ—„ `db` โšช๏ธโžก๏ธ `database` (๐Ÿ“ `database.py` โšช๏ธโžก๏ธ ๐Ÿ”›) &amp; โš™๏ธ โšซ๏ธ ๐Ÿ“ฅ.
```Python hl_lines="3 6-12 15-21"
{!../../../docs_src/sql_databases_peewee/sql_app/models.py!}
```
!!! tip
๐Ÿ’ โœ ๐Ÿ“š ๐ŸŽฑ ๐Ÿ”ข.
โšซ๏ธ ๐Ÿ”œ ๐Ÿ” ๐Ÿšฎ `id` ๐Ÿ”ข ๐Ÿ”ข ๐Ÿ‘‘ ๐Ÿ”‘.
โšซ๏ธ ๐Ÿ”œ โš’ ๐Ÿ“› ๐Ÿ“ โš“๏ธ ๐Ÿ”› ๐ŸŽ“ ๐Ÿ“›.
`Item`, โšซ๏ธ ๐Ÿ”œ โœ ๐Ÿ”ข `owner_id` โฎ๏ธ ๐Ÿ”ข ๐Ÿ†” `User`. โœ‹๏ธ ๐Ÿ‘ฅ ๐Ÿšซ ๐Ÿ“ฃ โšซ๏ธ ๐Ÿ™†.
## โœ Pydantic ๐Ÿท
๐Ÿ”œ โžก๏ธ โœ… ๐Ÿ“ `sql_app/schemas.py`.
!!! tip
โŽ ๐Ÿ˜จ ๐Ÿ–– ๐Ÿ’ *๐Ÿท* &amp; Pydantic *๐Ÿท*, ๐Ÿ‘ฅ ๐Ÿ”œ โœ”๏ธ ๐Ÿ“ `models.py` โฎ๏ธ ๐Ÿ’ ๐Ÿท, &amp; ๐Ÿ“ `schemas.py` โฎ๏ธ Pydantic ๐Ÿท.
๐Ÿ‘ซ Pydantic ๐Ÿท ๐Ÿ”ฌ ๐ŸŒ… โš–๏ธ ๐ŸŒ˜ "๐Ÿ”—" (โ˜‘ ๐Ÿ“Š ๐Ÿ’ ).
๐Ÿ‘‰ ๐Ÿ”œ โ„น ๐Ÿ‘ฅ โŽ ๐Ÿ˜จ โช โš™๏ธ ๐Ÿ‘ฏโ€โ™‚๏ธ.
### โœ Pydantic *๐Ÿท* / ๐Ÿ”—
โœ ๐ŸŒ ๐ŸŽ Pydantic ๐Ÿท ๐Ÿ‡ธ๐Ÿ‡ฒ ๐Ÿ”ฐ:
```Python hl_lines="16-18 21-22 25-30 34-35 38-39 42-48"
{!../../../docs_src/sql_databases_peewee/sql_app/schemas.py!}
```
!!! tip
๐Ÿ“ฅ ๐Ÿ‘ฅ ๐Ÿ— ๐Ÿท โฎ๏ธ `id`.
๐Ÿ‘ฅ ๐Ÿšซ ๐ŸŽฏ โœ” `id` ๐Ÿ”ข ๐Ÿ’ ๐Ÿท, โœ‹๏ธ ๐Ÿ’ ๐Ÿšฎ 1๏ธโƒฃ ๐Ÿ”.
๐Ÿ‘ฅ โŽ ๐ŸŽฑ `owner_id` ๐Ÿ”ข `Item`.
### โœ `PeeweeGetterDict` Pydantic *๐Ÿท* / ๐Ÿ”—
๐Ÿ•โ” ๐Ÿ‘† ๐Ÿ” ๐Ÿ’› ๐Ÿ’ ๐ŸŽš, ๐Ÿ’– `some_user.items`, ๐Ÿ’ ๐Ÿšซ ๐Ÿšš `list` `Item`.
โšซ๏ธ ๐Ÿšš ๐ŸŽ ๐Ÿ›ƒ ๐ŸŽš ๐ŸŽ“ `ModelSelect`.
โšซ๏ธ ๐Ÿ’ช โœ `list` ๐Ÿšฎ ๐Ÿฌ โฎ๏ธ `list(some_user.items)`.
โœ‹๏ธ ๐ŸŽš โšซ๏ธ ๐Ÿšซ `list`. &amp; โšซ๏ธ ๐Ÿšซ โ˜‘ ๐Ÿ <a href="https://docs.python.org/3/glossary.html#term-generator" class="external-link" target="_blank">๐Ÿš‚</a>. โ†ฉ๏ธ ๐Ÿ‘‰, Pydantic ๐Ÿšซ ๐Ÿ’ญ ๐Ÿ”ข โ” ๐Ÿ—œ โšซ๏ธ `list` Pydantic *๐Ÿท* / ๐Ÿ”—.
โœ‹๏ธ โฎ๏ธ โฌ Pydantic โœ” ๐Ÿšš ๐Ÿ›ƒ ๐ŸŽ“ ๐Ÿ‘ˆ ๐Ÿ˜– โšช๏ธโžก๏ธ `pydantic.utils.GetterDict`, ๐Ÿšš ๐Ÿ› ๏ธ โš™๏ธ ๐Ÿ•โ” โš™๏ธ `orm_mode = True` ๐Ÿ—ƒ ๐Ÿ’ฒ ๐Ÿœ ๐Ÿท ๐Ÿ”ข.
๐Ÿ‘ฅ ๐Ÿ”œ โœ ๐Ÿ›ƒ `PeeweeGetterDict` ๐ŸŽ“ &amp; โš™๏ธ โšซ๏ธ ๐ŸŒ ๐ŸŽ Pydantic *๐Ÿท* / ๐Ÿ”— ๐Ÿ‘ˆ โš™๏ธ `orm_mode`:
```Python hl_lines="3 8-13 31 49"
{!../../../docs_src/sql_databases_peewee/sql_app/schemas.py!}
```
๐Ÿ“ฅ ๐Ÿ‘ฅ โœ… ๐Ÿšฅ ๐Ÿ”ข ๐Ÿ‘ˆ โž– ๐Ÿ” (โœ… `.items` `some_user.items`) ๐Ÿ‘ `peewee.ModelSelect`.
&amp; ๐Ÿšฅ ๐Ÿ‘ˆ ๐Ÿ’ผ, ๐Ÿ“จ `list` โฎ๏ธ โšซ๏ธ.
&amp; โคด๏ธ ๐Ÿ‘ฅ โš™๏ธ โšซ๏ธ Pydantic *๐Ÿท* / ๐Ÿ”— ๐Ÿ‘ˆ โš™๏ธ `orm_mode = True`, โฎ๏ธ ๐Ÿ“ณ ๐Ÿ”ข `getter_dict = PeeweeGetterDict`.
!!! tip
๐Ÿ‘ฅ ๐Ÿ•ด ๐Ÿ’ช โœ 1๏ธโƒฃ `PeeweeGetterDict` ๐ŸŽ“, &amp; ๐Ÿ‘ฅ ๐Ÿ’ช โš™๏ธ โšซ๏ธ ๐ŸŒ Pydantic *๐Ÿท* / ๐Ÿ”—.
## ๐Ÿ’ฉ ๐Ÿ‡จ๐Ÿ‡ป
๐Ÿ”œ โžก๏ธ ๐Ÿ‘€ ๐Ÿ“ `sql_app/crud.py`.
### โœ ๐ŸŒ ๐Ÿ’ฉ ๐Ÿ‡จ๐Ÿ‡ป
โœ ๐ŸŒ ๐ŸŽ ๐Ÿ’ฉ ๐Ÿ‡จ๐Ÿ‡ป ๐Ÿ‡ธ๐Ÿ‡ฒ ๐Ÿ”ฐ, ๐ŸŒ ๐Ÿ“Ÿ ๐Ÿ“ถ ๐ŸŽ:
```Python hl_lines="1 4-5 8-9 12-13 16-20 23-24 27-30"
{!../../../docs_src/sql_databases_peewee/sql_app/crud.py!}
```
๐Ÿ“ค ๐Ÿ”บ โฎ๏ธ ๐Ÿ“Ÿ ๐Ÿ‡ธ๐Ÿ‡ฒ ๐Ÿ”ฐ.
๐Ÿ‘ฅ ๐Ÿšซ ๐Ÿšถโ€โ™€๏ธ `db` ๐Ÿ”ข ๐Ÿคญ. โ†ฉ๏ธ ๐Ÿ‘ฅ โš™๏ธ ๐Ÿท ๐Ÿ”—. ๐Ÿ‘‰ โ†ฉ๏ธ `db` ๐ŸŽš ๐ŸŒ ๐ŸŽš, ๐Ÿ‘ˆ ๐Ÿ”Œ ๐ŸŒ ๐Ÿ”— โš›. ๐Ÿ‘ˆ โšซ๏ธโ” ๐Ÿ‘ฅ โœ”๏ธ ๐ŸŒ `contextvars` โ„น ๐Ÿ”›.
๐Ÿ†–, ๐Ÿ•โ” ๐Ÿ›ฌ ๐Ÿ“š ๐ŸŽš, ๐Ÿ’– `get_users`, ๐Ÿ‘ฅ ๐Ÿ”— ๐Ÿค™ `list`, ๐Ÿ’–:
```Python
list(models.User.select())
```
๐Ÿ‘‰ ๐ŸŽ ๐Ÿค” ๐Ÿ‘ˆ ๐Ÿ‘ฅ โœ”๏ธ โœ ๐Ÿ›ƒ `PeeweeGetterDict`. โœ‹๏ธ ๐Ÿ›ฌ ๐Ÿ•ณ ๐Ÿ‘ˆ โช `list` โ†ฉ๏ธ `peewee.ModelSelect` `response_model` *โžก ๐Ÿ› ๏ธ* โฎ๏ธ `List[models.User]` (๐Ÿ‘ˆ ๐Ÿ‘ฅ ๐Ÿ”œ ๐Ÿ‘€ โช) ๐Ÿ”œ ๐Ÿ‘ท โ˜‘.
## ๐Ÿ‘‘ **FastAPI** ๐Ÿ“ฑ
&amp; ๐Ÿ”œ ๐Ÿ“ `sql_app/main.py` โžก๏ธ ๐Ÿ› ๏ธ &amp; โš™๏ธ ๐ŸŒ ๐ŸŽ ๐Ÿ• ๐Ÿ‘ฅ โœ โญ.
### โœ ๐Ÿ’ฝ ๐Ÿ“
๐Ÿ“ถ ๐Ÿ™ƒ ๐ŸŒŒ โœ ๐Ÿ’ฝ ๐Ÿ“:
```Python hl_lines="9-11"
{!../../../docs_src/sql_databases_peewee/sql_app/main.py!}
```
### โœ ๐Ÿ”—
โœ ๐Ÿ”— ๐Ÿ‘ˆ ๐Ÿ”œ ๐Ÿ”— ๐Ÿ’ฝ โ–ถ๏ธ๏ธ โ–ถ๏ธ ๐Ÿ“จ &amp; ๐Ÿ”Œ โšซ๏ธ ๐Ÿ”š:
```Python hl_lines="23-29"
{!../../../docs_src/sql_databases_peewee/sql_app/main.py!}
```
๐Ÿ“ฅ ๐Ÿ‘ฅ โœ”๏ธ ๐Ÿ› `yield` โ†ฉ๏ธ ๐Ÿ‘ฅ ๐Ÿค™ ๐Ÿšซ โš™๏ธ ๐Ÿ’ฝ ๐ŸŽš ๐Ÿ”—.
โšซ๏ธ ๐Ÿ”— ๐Ÿ’ฝ &amp; โ™ป ๐Ÿ”— ๐Ÿ’ฝ ๐Ÿ”— ๐Ÿ”ข ๐Ÿ‘ˆ ๐Ÿ”ฌ ๐Ÿ”  ๐Ÿ“จ (โš™๏ธ `contextvars` ๐ŸŽฑ โšช๏ธโžก๏ธ ๐Ÿ”›).
โ†ฉ๏ธ ๐Ÿ’ฝ ๐Ÿ”— โš  ๐Ÿ‘ค/๐Ÿ…พ ๐Ÿšง, ๐Ÿ‘‰ ๐Ÿ”— โœ โฎ๏ธ ๐Ÿ˜ `def` ๐Ÿ”ข.
&amp; โคด๏ธ, ๐Ÿ”  *โžก ๐Ÿ› ๏ธ ๐Ÿ”ข* ๐Ÿ‘ˆ ๐Ÿ’ช ๐Ÿ” ๐Ÿ’ฝ ๐Ÿ‘ฅ ๐Ÿšฎ โšซ๏ธ ๐Ÿ”—.
โœ‹๏ธ ๐Ÿ‘ฅ ๐Ÿšซ โš™๏ธ ๐Ÿ’ฒ ๐Ÿ‘ ๐Ÿ‘‰ ๐Ÿ”— (โšซ๏ธ ๐Ÿค™ ๐Ÿšซ ๐Ÿค ๐Ÿ™† ๐Ÿ’ฒ, โšซ๏ธ โœ”๏ธ ๐Ÿ› `yield`). , ๐Ÿ‘ฅ ๐Ÿšซ ๐Ÿšฎ โšซ๏ธ *โžก ๐Ÿ› ๏ธ ๐Ÿ”ข* โœ‹๏ธ *โžก ๐Ÿ› ๏ธ ๐Ÿ‘จโ€๐ŸŽจ* `dependencies` ๐Ÿ”ข:
```Python hl_lines="32 40 47 59 65 72"
{!../../../docs_src/sql_databases_peewee/sql_app/main.py!}
```
### ๐Ÿ”‘ ๐Ÿ”ข ๐ŸŽง-๐Ÿ”—
๐ŸŒ `contextvars` ๐Ÿ• ๐Ÿ‘ท, ๐Ÿ‘ฅ ๐Ÿ’ช โš’ ๐Ÿ’ญ ๐Ÿ‘ฅ โœ”๏ธ ๐Ÿ”ฌ ๐Ÿ’ฒ `ContextVar` ๐Ÿ”  ๐Ÿ“จ ๐Ÿ‘ˆ โš™๏ธ ๐Ÿ’ฝ, &amp; ๐Ÿ‘ˆ ๐Ÿ’ฒ ๐Ÿ”œ โš™๏ธ ๐Ÿ’ฝ ๐Ÿ‡ต๐Ÿ‡ธ (๐Ÿ”—, ๐Ÿ’ต, โ™’๏ธ) ๐ŸŽ‚ ๐Ÿ“จ.
๐Ÿ‘ˆ, ๐Ÿ‘ฅ ๐Ÿ’ช โœ โž•1๏ธโƒฃ `async` ๐Ÿ”— `reset_db_state()` ๐Ÿ‘ˆ โš™๏ธ ๐ŸŽง-๐Ÿ”— `get_db()`. โšซ๏ธ ๐Ÿ”œ โš’ ๐Ÿ’ฒ ๐Ÿ”‘ ๐Ÿ”ข (โฎ๏ธ ๐Ÿ”ข `dict`) ๐Ÿ‘ˆ ๐Ÿ”œ โš™๏ธ ๐Ÿ’ฝ ๐Ÿ‡ต๐Ÿ‡ธ ๐ŸŽ‚ ๐Ÿ“จ. &amp; โคด๏ธ ๐Ÿ”— `get_db()` ๐Ÿ”œ ๐Ÿช โšซ๏ธ ๐Ÿ’ฝ ๐Ÿ‡ต๐Ÿ‡ธ (๐Ÿ”—, ๐Ÿ’ต, โ™’๏ธ).
```Python hl_lines="18-20"
{!../../../docs_src/sql_databases_peewee/sql_app/main.py!}
```
**โญ ๐Ÿ“จ**, ๐Ÿ‘ฅ ๐Ÿ”œ โฒ ๐Ÿ‘ˆ ๐Ÿ”‘ ๐Ÿ”ข ๐Ÿ”„ `async` ๐Ÿ”— `reset_db_state()` &amp; โคด๏ธ โœ ๐Ÿ†• ๐Ÿ”— `get_db()` ๐Ÿ”—, ๐Ÿ‘ˆ ๐Ÿ†• ๐Ÿ“จ ๐Ÿ”œ โœ”๏ธ ๐Ÿšฎ ๐Ÿ‘ ๐Ÿ’ฝ ๐Ÿ‡ต๐Ÿ‡ธ (๐Ÿ”—, ๐Ÿ’ต, โ™’๏ธ).
!!! tip
FastAPI ๐Ÿ” ๐Ÿ› ๏ธ, 1๏ธโƒฃ ๐Ÿ“จ ๐Ÿ’ช โ–ถ๏ธ โž– ๐Ÿ› ๏ธ, &amp; โญ ๐Ÿ, โž•1๏ธโƒฃ ๐Ÿ“จ ๐Ÿ’ช ๐Ÿ“จ &amp; โ–ถ๏ธ ๐Ÿญ ๐Ÿ‘, &amp; โšซ๏ธ ๐ŸŒ ๐Ÿ’ช ๐Ÿ› ๏ธ ๐ŸŽ ๐Ÿงต.
โœ‹๏ธ ๐Ÿ”‘ ๐Ÿ”ข ๐Ÿค” ๐Ÿ‘ซ ๐Ÿ” โš’,, ๐Ÿ’ ๐Ÿ’ฝ ๐Ÿ‡ต๐Ÿ‡ธ โš’ `async` ๐Ÿ”— `reset_db_state()` ๐Ÿ”œ ๐Ÿšง ๐Ÿšฎ ๐Ÿ‘ ๐Ÿ’ฝ ๐ŸŽ‚ ๐ŸŽ‚ ๐Ÿ“จ.
&amp; ๐ŸŽ ๐Ÿ•ฐ, ๐ŸŽ ๐Ÿ› ๏ธ ๐Ÿ“จ ๐Ÿ”œ โœ”๏ธ ๐Ÿšฎ ๐Ÿ‘ ๐Ÿ’ฝ ๐Ÿ‡ต๐Ÿ‡ธ ๐Ÿ‘ˆ ๐Ÿ”œ ๐Ÿ”ฌ ๐ŸŽ‚ ๐Ÿ“จ.
#### ๐Ÿ’ ๐Ÿ—ณ
๐Ÿšฅ ๐Ÿ‘† โš™๏ธ <a href="https://docs.peewee-orm.com/en/latest/peewee/database.html#dynamically-defining-a-database" class="external-link" target="_blank">๐Ÿ’ ๐Ÿ—ณ</a>, โ˜‘ ๐Ÿ’ฝ `db.obj`.
, ๐Ÿ‘† ๐Ÿ”œ โฒ โšซ๏ธ โฎ๏ธ:
```Python hl_lines="3-4"
async def reset_db_state():
database.db.obj._state._state.set(db_state_default.copy())
database.db.obj._state.reset()
```
### โœ ๐Ÿ‘† **FastAPI** *โžก ๐Ÿ› ๏ธ*
๐Ÿ”œ, ๐Ÿ˜’, ๐Ÿ“ฅ ๐Ÿฉ **FastAPI** *โžก ๐Ÿ› ๏ธ* ๐Ÿ“Ÿ.
```Python hl_lines="32-37 40-43 46-53 56-62 65-68 71-79"
{!../../../docs_src/sql_databases_peewee/sql_app/main.py!}
```
### ๐Ÿ”ƒ `def` ๐Ÿ†š `async def`
๐ŸŽ โฎ๏ธ ๐Ÿ‡ธ๐Ÿ‡ฒ, ๐Ÿ‘ฅ ๐Ÿšซ ๐Ÿ”จ ๐Ÿ•ณ ๐Ÿ’–:
```Python
user = await models.User.select().first()
```
...โœ‹๏ธ โ†ฉ๏ธ ๐Ÿ‘ฅ โš™๏ธ:
```Python
user = models.User.select().first()
```
, ๐Ÿ”„, ๐Ÿ‘ฅ ๐Ÿ”œ ๐Ÿ“ฃ *โžก ๐Ÿ› ๏ธ ๐Ÿ”ข* &amp; ๐Ÿ”— ๐Ÿต `async def`, โฎ๏ธ ๐Ÿ˜ `def`,:
```Python hl_lines="2"
# Something goes here
def read_users(skip: int = 0, limit: int = 100):
# Something goes here
```
## ๐Ÿ”ฌ ๐Ÿ’ โฎ๏ธ ๐Ÿ”
๐Ÿ‘‰ ๐Ÿ–ผ ๐Ÿ”Œ โž• *โžก ๐Ÿ› ๏ธ* ๐Ÿ‘ˆ ๐Ÿ”ฌ ๐Ÿ“ ๐Ÿญ ๐Ÿ“จ โฎ๏ธ `time.sleep(sleep_time)`.
โšซ๏ธ ๐Ÿ”œ โœ”๏ธ ๐Ÿ’ฝ ๐Ÿ”— ๐Ÿ“‚ โ–ถ๏ธ &amp; ๐Ÿ”œ โŒ› ๐Ÿฅˆ โญ ๐Ÿ™‡ ๐Ÿ”™. &amp; ๐Ÿ”  ๐Ÿ†• ๐Ÿ“จ ๐Ÿ”œ โŒ› ๐Ÿ• ๐Ÿฅˆ ๐ŸŒ˜.
๐Ÿ‘‰ ๐Ÿ”œ ๐Ÿ’ช โžก๏ธ ๐Ÿ‘† ๐Ÿ’ฏ ๐Ÿ‘ˆ ๐Ÿ‘† ๐Ÿ“ฑ โฎ๏ธ ๐Ÿ’ &amp; FastAPI ๐ŸŽญ โ˜‘ โฎ๏ธ ๐ŸŒ ๐Ÿ’ฉ ๐Ÿ”ƒ ๐Ÿงต.
๐Ÿšฅ ๐Ÿ‘† ๐Ÿ’š โœ… โ” ๐Ÿ’ ๐Ÿ”œ ๐Ÿ’” ๐Ÿ‘† ๐Ÿ“ฑ ๐Ÿšฅ โš™๏ธ ๐Ÿต ๐Ÿ› ๏ธ, ๐Ÿšถ `sql_app/database.py` ๐Ÿ“ &amp; ๐Ÿค โธ:
```Python
# db._state = PeeweeConnectionState()
```
&amp; ๐Ÿ“ `sql_app/main.py` ๐Ÿ“, ๐Ÿค ๐Ÿ’ช `async` ๐Ÿ”— `reset_db_state()` &amp; โŽ โšซ๏ธ โฎ๏ธ `pass`:
```Python
async def reset_db_state():
# database.db._state._state.set(db_state_default.copy())
# database.db._state.reset()
pass
```
โคด๏ธ ๐Ÿƒ ๐Ÿ‘† ๐Ÿ“ฑ โฎ๏ธ Uvicorn:
<div class="termy">
```console
$ uvicorn sql_app.main:app --reload
<span style="color: green;">INFO</span>: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
```
</div>
๐Ÿ“‚ ๐Ÿ‘† ๐Ÿ–ฅ <a href="http://127.0.0.1:8000/docs" class="external-link" target="_blank">http://127.0.0.1:8000/docs</a> &amp; โœ ๐Ÿ‘ฉโ€โคโ€๐Ÿ‘จ ๐Ÿ‘ฉโ€๐Ÿ’ป.
โคด๏ธ ๐Ÿ“‚ 1๏ธโƒฃ0๏ธโƒฃ ๐Ÿ“‘ <a href="http://127.0.0.1:8000/docs#/default/read_slow_users_slowusers__get" class="external-link" target="_blank">http://127.0.0.1:8000/docs#/default/read_๐ŸŒ_๐Ÿ‘ฉโ€๐Ÿ’ป_slowusers_ = </a> ๐ŸŽ ๐Ÿ•ฐ.
๐Ÿšถ *โžก ๐Ÿ› ๏ธ* "๐Ÿคš `/slowusers/`" ๐ŸŒ ๐Ÿ“‘. โš™๏ธ "๐Ÿ”„ โšซ๏ธ ๐Ÿ‘…" ๐Ÿ”ผ &amp; ๐Ÿ› ๏ธ ๐Ÿ“จ ๐Ÿ”  ๐Ÿ“‘, 1๏ธโƒฃ โ–ถ๏ธ๏ธ โฎ๏ธ ๐ŸŽ.
๐Ÿ“‘ ๐Ÿ”œ โŒ› ๐Ÿ– &amp; โคด๏ธ ๐Ÿ‘ซ ๐Ÿ”œ ๐ŸŽฆ `Internal Server Error`.
### โšซ๏ธโ” ๐Ÿ”จ
๐Ÿฅ‡ ๐Ÿ“‘ ๐Ÿ”œ โš’ ๐Ÿ‘† ๐Ÿ“ฑ โœ ๐Ÿ”— ๐Ÿ’ฝ &amp; โŒ› ๐Ÿฅˆ โญ ๐Ÿ™‡ ๐Ÿ”™ &amp; ๐Ÿ“ช ๐Ÿ’ฝ ๐Ÿ”—.
โคด๏ธ, ๐Ÿ“จ โญ ๐Ÿ“‘, ๐Ÿ‘† ๐Ÿ“ฑ ๐Ÿ”œ โŒ› ๐Ÿ• ๐Ÿฅˆ ๐ŸŒ˜, &amp; ๐Ÿ”›.
๐Ÿ‘‰ โ›“ ๐Ÿ‘ˆ โšซ๏ธ ๐Ÿ”œ ๐Ÿ”š ๐Ÿ†™ ๐Ÿ ๐Ÿ ๐Ÿ“‘' ๐Ÿ“จ โช ๐ŸŒ˜ โฎ๏ธ ๐Ÿ•.
โคด๏ธ 1๏ธโƒฃ ๐Ÿ ๐Ÿ“จ ๐Ÿ‘ˆ โŒ› ๐ŸŒ˜ ๐Ÿฅˆ ๐Ÿ”œ ๐Ÿ”„ ๐Ÿ“‚ ๐Ÿ’ฝ ๐Ÿ”—, โœ‹๏ธ 1๏ธโƒฃ ๐Ÿ“š โฎ๏ธ ๐Ÿ“จ ๐ŸŽ ๐Ÿ“‘ ๐Ÿ”œ ๐ŸŽฒ ๐Ÿต ๐ŸŽ ๐Ÿงต ๐Ÿฅ‡ ๐Ÿ•, โšซ๏ธ ๐Ÿ”œ โœ”๏ธ ๐ŸŽ ๐Ÿ’ฝ ๐Ÿ”— ๐Ÿ‘ˆ โช ๐Ÿ“‚, &amp; ๐Ÿ’ ๐Ÿ”œ ๐Ÿšฎ โŒ &amp; ๐Ÿ‘† ๐Ÿ”œ ๐Ÿ‘€ โšซ๏ธ ๐Ÿ“ถ, &amp; ๐Ÿ“จ ๐Ÿ”œ โœ”๏ธ `Internal Server Error`.
๐Ÿ‘‰ ๐Ÿ”œ ๐ŸŽฒ ๐Ÿ”จ ๐ŸŒ… ๐ŸŒ˜ 1๏ธโƒฃ ๐Ÿ“š ๐Ÿ“‘.
๐Ÿšฅ ๐Ÿ‘† โœ”๏ธ ๐Ÿ’— ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ’ฌ ๐Ÿ‘† ๐Ÿ“ฑ โšซ๏ธโ” ๐ŸŽ ๐Ÿ•ฐ, ๐Ÿ‘‰ โšซ๏ธโ” ๐Ÿ’ช ๐Ÿ”จ.
&amp; ๐Ÿ‘† ๐Ÿ“ฑ โ–ถ๏ธ ๐Ÿต ๐ŸŒ… &amp; ๐ŸŒ– ๐Ÿ‘ฉโ€๐Ÿ’ป ๐ŸŽ ๐Ÿ•ฐ, โŒ› ๐Ÿ•ฐ ๐Ÿ‘ ๐Ÿ“จ ๐Ÿ’ช ๐Ÿ“ &amp; ๐Ÿ“ โฒ โŒ.
### ๐Ÿ”ง ๐Ÿ’ โฎ๏ธ FastAPI
๐Ÿ”œ ๐Ÿšถ ๐Ÿ”™ ๐Ÿ“ `sql_app/database.py`, &amp; โœ โธ:
```Python
db._state = PeeweeConnectionState()
```
&amp; ๐Ÿ“ `sql_app/main.py` ๐Ÿ“, โœ ๐Ÿ’ช `async` ๐Ÿ”— `reset_db_state()`:
```Python
async def reset_db_state():
database.db._state._state.set(db_state_default.copy())
database.db._state.reset()
```
โŽ ๐Ÿ‘† ๐Ÿƒโ€โ™‚ ๐Ÿ“ฑ &amp; โ–ถ๏ธ โšซ๏ธ ๐Ÿ”„.
๐Ÿ” ๐ŸŽ ๐Ÿ› ๏ธ โฎ๏ธ 1๏ธโƒฃ0๏ธโƒฃ ๐Ÿ“‘. ๐Ÿ‘‰ ๐Ÿ•ฐ ๐ŸŒ ๐Ÿ‘ซ ๐Ÿ”œ โŒ› &amp; ๐Ÿ‘† ๐Ÿ”œ ๐Ÿคš ๐ŸŒ ๐Ÿ ๐Ÿต โŒ.
...๐Ÿ‘† ๐Ÿ”ง โšซ๏ธ โ—
## ๐Ÿ“„ ๐ŸŒ ๐Ÿ“
๐Ÿ’ญ ๐Ÿ‘† ๐Ÿ”œ โœ”๏ธ ๐Ÿ“ ๐Ÿ“› `my_super_project` (โš–๏ธ ๐Ÿ‘ ๐Ÿ‘† ๐Ÿ’š) ๐Ÿ‘ˆ ๐Ÿ”Œ ๐ŸŽง-๐Ÿ“ ๐Ÿค™ `sql_app`.
`sql_app` ๐Ÿ”œ โœ”๏ธ ๐Ÿ“„ ๐Ÿ“:
* `sql_app/__init__.py`: ๐Ÿ› ๐Ÿ“.
* `sql_app/database.py`:
```Python
{!../../../docs_src/sql_databases_peewee/sql_app/database.py!}
```
* `sql_app/models.py`:
```Python
{!../../../docs_src/sql_databases_peewee/sql_app/models.py!}
```
* `sql_app/schemas.py`:
```Python
{!../../../docs_src/sql_databases_peewee/sql_app/schemas.py!}
```
* `sql_app/crud.py`:
```Python
{!../../../docs_src/sql_databases_peewee/sql_app/crud.py!}
```
* `sql_app/main.py`:
```Python
{!../../../docs_src/sql_databases_peewee/sql_app/main.py!}
```
## ๐Ÿ“ก โ„น
!!! warning
๐Ÿ‘‰ ๐Ÿ“ถ ๐Ÿ“ก โ„น ๐Ÿ‘ˆ ๐Ÿ‘† ๐ŸŽฒ ๐Ÿšซ ๐Ÿ’ช.
### โš 
๐Ÿ’ โš™๏ธ <a href="https://docs.python.org/3/library/threading.html#thread-local-data" class="external-link" target="_blank">`threading.local`</a> ๐Ÿ”ข ๐Ÿช โšซ๏ธ ๐Ÿ’ฝ "๐Ÿ‡ต๐Ÿ‡ธ" ๐Ÿ’ฝ (๐Ÿ”—, ๐Ÿ’ต, โ™’๏ธ).
`threading.local` โœ ๐Ÿ’ฒ ๐ŸŒŸ โฎ๏ธ ๐Ÿงต, โœ‹๏ธ ๐Ÿ” ๐Ÿ› ๏ธ ๐Ÿ”œ ๐Ÿƒ ๐ŸŒ ๐Ÿ“Ÿ (โœ… ๐Ÿ”  ๐Ÿ“จ) ๐ŸŽ ๐Ÿงต, &amp; ๐ŸŽฒ ๐Ÿšซ โœ”.
๐Ÿ”› ๐Ÿ” ๐Ÿ‘ˆ, ๐Ÿ” ๐Ÿ› ๏ธ ๐Ÿ’ช ๐Ÿƒ ๐Ÿ” ๐Ÿ“Ÿ ๐Ÿงต (โš™๏ธ `asyncio.run_in_executor`), โœ‹๏ธ ๐Ÿ”— ๐ŸŽ ๐Ÿ“จ.
๐Ÿ‘‰ โ›“ ๐Ÿ‘ˆ, โฎ๏ธ ๐Ÿ’ โฎ๏ธ ๐Ÿ› ๏ธ, ๐Ÿ’— ๐Ÿ“‹ ๐Ÿ’ช โš™๏ธ ๐ŸŽ `threading.local` ๐Ÿ”ข &amp; ๐Ÿ”š ๐Ÿ†™ ๐Ÿค ๐ŸŽ ๐Ÿ”— &amp; ๐Ÿ’ฝ (๐Ÿ‘ˆ ๐Ÿ‘ซ ๐Ÿšซ๐Ÿ”œ ๐Ÿšซ), &amp; ๐ŸŽ ๐Ÿ•ฐ, ๐Ÿšฅ ๐Ÿ‘ซ ๐Ÿ› ๏ธ ๐Ÿ” ๐Ÿ‘ค/๐Ÿ…พ-๐Ÿšง ๐Ÿ“Ÿ ๐Ÿงต (โฎ๏ธ ๐Ÿ˜ `def` ๐Ÿ”ข FastAPI, *โžก ๐Ÿ› ๏ธ* &amp; ๐Ÿ”—), ๐Ÿ‘ˆ ๐Ÿ“Ÿ ๐Ÿ† ๐Ÿšซ โœ”๏ธ ๐Ÿ” ๐Ÿ’ฝ ๐Ÿ‡ต๐Ÿ‡ธ ๐Ÿ”ข, โช โšซ๏ธ ๐Ÿ• ๐ŸŽ ๐Ÿ“จ &amp; โšซ๏ธ ๐Ÿ”œ ๐Ÿ’ช ๐Ÿคš ๐Ÿ” ๐ŸŽ ๐Ÿ’ฝ ๐Ÿ‡ต๐Ÿ‡ธ.
### ๐Ÿ”‘ ๐Ÿ”ข
๐Ÿ 3๏ธโƒฃ.7๏ธโƒฃ โœ”๏ธ <a href="https://docs.python.org/3/library/contextvars.html" class="external-link" target="_blank">`contextvars`</a> ๐Ÿ‘ˆ ๐Ÿ’ช โœ ๐Ÿ‡ง๐Ÿ‡ฟ ๐Ÿ”ข ๐Ÿ“ถ ๐ŸŽ `threading.local`, โœ‹๏ธ ๐Ÿ”— ๐Ÿ‘ซ ๐Ÿ” โš’.
๐Ÿ“ค ๐Ÿ“š ๐Ÿ‘œ โœ”๏ธ ๐Ÿคฏ.
`ContextVar` โœ”๏ธ โœ ๐Ÿ” ๐Ÿ•น, ๐Ÿ’–:
```Python
some_var = ContextVar("some_var", default="default value")
```
โš’ ๐Ÿ’ฒ โš™๏ธ โฎ๏ธ "๐Ÿ”‘" (โœ… โฎ๏ธ ๐Ÿ“จ) โš™๏ธ:
```Python
some_var.set("new value")
```
๐Ÿคš ๐Ÿ’ฒ ๐Ÿ™† ๐Ÿ”˜ ๐Ÿ”‘ (โœ… ๐Ÿ™† ๐Ÿ• ๐Ÿšš โฎ๏ธ ๐Ÿ“จ) โš™๏ธ:
```Python
some_var.get()
```
### โš’ ๐Ÿ”‘ ๐Ÿ”ข `async` ๐Ÿ”— `reset_db_state()`
๐Ÿšฅ ๐Ÿ• ๐Ÿ” ๐Ÿ“Ÿ โš’ ๐Ÿ’ฒ โฎ๏ธ `some_var.set("updated in function")` (โœ… ๐Ÿ’– `async` ๐Ÿ”—), ๐ŸŽ‚ ๐Ÿ“Ÿ โšซ๏ธ &amp; ๐Ÿ“Ÿ ๐Ÿ‘ˆ ๐Ÿšถ โฎ๏ธ (โœ… ๐Ÿ“Ÿ ๐Ÿ”˜ `async` ๐Ÿ”ข ๐Ÿค™ โฎ๏ธ `await`) ๐Ÿ”œ ๐Ÿ‘€ ๐Ÿ‘ˆ ๐Ÿ†• ๐Ÿ’ฒ.
, ๐Ÿ‘† ๐Ÿ’ผ, ๐Ÿšฅ ๐Ÿ‘ฅ โš’ ๐Ÿ’ ๐Ÿ‡ต๐Ÿ‡ธ ๐Ÿ”ข (โฎ๏ธ ๐Ÿ”ข `dict`) `async` ๐Ÿ”—, ๐ŸŒ ๐ŸŽ‚ ๐Ÿ”— ๐Ÿ“Ÿ ๐Ÿ‘† ๐Ÿ“ฑ ๐Ÿ”œ ๐Ÿ‘€ ๐Ÿ‘‰ ๐Ÿ’ฒ &amp; ๐Ÿ”œ ๐Ÿ’ช โ™ป โšซ๏ธ ๐ŸŽ‚ ๐Ÿ“จ.
&amp; ๐Ÿ”‘ ๐Ÿ”ข ๐Ÿ”œ โš’ ๐Ÿ”„ โญ ๐Ÿ“จ, ๐Ÿšฅ ๐Ÿ‘ซ ๐Ÿ› ๏ธ.
### โš’ ๐Ÿ’ฝ ๐Ÿ‡ต๐Ÿ‡ธ ๐Ÿ”— `get_db()`
`get_db()` ๐Ÿ˜ `def` ๐Ÿ”ข, **FastAPI** ๐Ÿ”œ โš’ โšซ๏ธ ๐Ÿƒ ๐Ÿงต, โฎ๏ธ *๐Ÿ“* "๐Ÿ”‘", ๐Ÿง‘โ€๐Ÿคโ€๐Ÿง‘ ๐ŸŽ ๐Ÿ’ฒ ๐Ÿ”‘ ๐Ÿ”ข ( `dict` โฎ๏ธ โฒ ๐Ÿ’ฝ ๐Ÿ‡ต๐Ÿ‡ธ). โคด๏ธ โšซ๏ธ ๐Ÿ’ช ๐Ÿšฎ ๐Ÿ’ฝ ๐Ÿ‡ต๐Ÿ‡ธ ๐Ÿ‘ˆ `dict`, ๐Ÿ’– ๐Ÿ”—, โ™’๏ธ.
โœ‹๏ธ ๐Ÿšฅ ๐Ÿ’ฒ ๐Ÿ”‘ ๐Ÿ”ข (๐Ÿ”ข `dict`) โš’ ๐Ÿ‘ˆ ๐Ÿ˜ `def` ๐Ÿ”ข, โšซ๏ธ ๐Ÿ”œ โœ ๐Ÿ†• ๐Ÿ’ฒ ๐Ÿ‘ˆ ๐Ÿ”œ ๐Ÿšง ๐Ÿ•ด ๐Ÿ‘ˆ ๐Ÿงต ๐Ÿงต, &amp; ๐ŸŽ‚ ๐Ÿ“Ÿ (๐Ÿ’– *โžก ๐Ÿ› ๏ธ ๐Ÿ”ข*) ๐Ÿšซ๐Ÿ”œ โœ”๏ธ ๐Ÿ” โšซ๏ธ. `get_db()` ๐Ÿ‘ฅ ๐Ÿ’ช ๐Ÿ•ด โš’ ๐Ÿ’ฒ `dict`, โœ‹๏ธ ๐Ÿšซ ๐ŸŽ‚ `dict` โšซ๏ธ.
, ๐Ÿ‘ฅ ๐Ÿ’ช โœ”๏ธ `async` ๐Ÿ”— `reset_db_state()` โš’ `dict` ๐Ÿ”‘ ๐Ÿ”ข. ๐Ÿ‘ˆ ๐ŸŒŒ, ๐ŸŒ ๐Ÿ“Ÿ โœ”๏ธ ๐Ÿ” ๐ŸŽ `dict` ๐Ÿ’ฝ ๐Ÿ‡ต๐Ÿ‡ธ ๐Ÿ‘ ๐Ÿ“จ.
### ๐Ÿ”— &amp; ๐Ÿ”Œ ๐Ÿ”— `get_db()`
โคด๏ธ โญ โ” ๐Ÿ”œ, โšซ๏ธโ” ๐Ÿšซ ๐Ÿ”— &amp; ๐Ÿ”Œ ๐Ÿ’ฝ `async` ๐Ÿ”— โšซ๏ธ, โ†ฉ๏ธ `get_db()`โ“
`async` ๐Ÿ”— โœ”๏ธ `async` ๐Ÿ”‘ ๐Ÿ”ข ๐Ÿ›ก ๐ŸŽ‚ ๐Ÿ“จ, โœ‹๏ธ ๐Ÿ— &amp; ๐Ÿ“ช ๐Ÿ’ฝ ๐Ÿ”— โš  ๐Ÿšง, โšซ๏ธ ๐Ÿ’ช ๐Ÿ“‰ ๐ŸŽญ ๐Ÿšฅ โšซ๏ธ ๐Ÿ“ค.
๐Ÿ‘ฅ ๐Ÿ’ช ๐Ÿ˜ `def` ๐Ÿ”— `get_db()`.

73
docs/em/docs/advanced/sub-applications.md

@ -0,0 +1,73 @@
# ๐ŸŽง ๐Ÿˆธ - ๐Ÿ—ป
๐Ÿšฅ ๐Ÿ‘† ๐Ÿ’ช โœ”๏ธ 2๏ธโƒฃ ๐Ÿ”ฌ FastAPI ๐Ÿˆธ, โฎ๏ธ ๐Ÿ‘ซ ๐Ÿ‘ ๐Ÿ”ฌ ๐Ÿ—„ &amp; ๐Ÿ‘ซ ๐Ÿ‘ ๐Ÿฉบ โšœ, ๐Ÿ‘† ๐Ÿ’ช โœ”๏ธ ๐Ÿ‘‘ ๐Ÿ“ฑ &amp; "๐Ÿ—ป" 1๏ธโƒฃ (โš–๏ธ ๐ŸŒ…) ๐ŸŽง-๐Ÿˆธ(โ“‚).
## ๐Ÿ—œ **FastAPI** ๐Ÿˆธ
"๐Ÿ—œ" โ›“ โŽ ๐Ÿ• "๐Ÿ”ฌ" ๐Ÿˆธ ๐ŸŽฏ โžก, ๐Ÿ‘ˆ โคด๏ธ โœŠ ๐Ÿ’… ๐Ÿšš ๐ŸŒ ๐Ÿ”ฝ ๐Ÿ‘ˆ โžก, โฎ๏ธ _โžก ๐Ÿ› ๏ธ_ ๐Ÿ“ฃ ๐Ÿ‘ˆ ๐ŸŽง-๐Ÿˆธ.
### ๐Ÿ”-๐ŸŽš ๐Ÿˆธ
๐Ÿฅ‡, โœ ๐Ÿ‘‘, ๐Ÿ”-๐ŸŽš, **FastAPI** ๐Ÿˆธ, &amp; ๐Ÿšฎ *โžก ๐Ÿ› ๏ธ*:
```Python hl_lines="3 6-8"
{!../../../docs_src/sub_applications/tutorial001.py!}
```
### ๐ŸŽง-๐Ÿˆธ
โคด๏ธ, โœ ๐Ÿ‘† ๐ŸŽง-๐Ÿˆธ, &amp; ๐Ÿšฎ *โžก ๐Ÿ› ๏ธ*.
๐Ÿ‘‰ ๐ŸŽง-๐Ÿˆธ โž•1๏ธโƒฃ ๐Ÿฉ FastAPI ๐Ÿˆธ, โœ‹๏ธ ๐Ÿ‘‰ 1๏ธโƒฃ ๐Ÿ‘ˆ ๐Ÿ”œ "๐Ÿ—ป":
```Python hl_lines="11 14-16"
{!../../../docs_src/sub_applications/tutorial001.py!}
```
### ๐Ÿ—ป ๐ŸŽง-๐Ÿˆธ
๐Ÿ‘† ๐Ÿ”-๐ŸŽš ๐Ÿˆธ, `app`, ๐Ÿ—ป ๐ŸŽง-๐Ÿˆธ, `subapi`.
๐Ÿ‘‰ ๐Ÿ’ผ, โšซ๏ธ ๐Ÿ”œ ๐Ÿ“Œ โžก `/subapi`:
```Python hl_lines="11 19"
{!../../../docs_src/sub_applications/tutorial001.py!}
```
### โœ… ๐Ÿง ๐Ÿ› ๏ธ ๐Ÿฉบ
๐Ÿ”œ, ๐Ÿƒ `uvicorn` โฎ๏ธ ๐Ÿ‘‘ ๐Ÿ“ฑ, ๐Ÿšฅ ๐Ÿ‘† ๐Ÿ“ `main.py`, โšซ๏ธ ๐Ÿ”œ:
<div class="termy">
```console
$ uvicorn main:app --reload
<span style="color: green;">INFO</span>: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
```
</div>
&amp; ๐Ÿ“‚ ๐Ÿฉบ <a href="http://127.0.0.1:8000/docs" class="external-link" target="_blank">http://127.0.0.1:8000/docs</a>.
๐Ÿ‘† ๐Ÿ”œ ๐Ÿ‘€ ๐Ÿง ๐Ÿ› ๏ธ ๐Ÿฉบ ๐Ÿ‘‘ ๐Ÿ“ฑ, ๐Ÿ”Œ ๐Ÿ•ด ๐Ÿšฎ ๐Ÿ‘ _โžก ๐Ÿ› ๏ธ_:
<img src="/img/tutorial/sub-applications/image01.png">
&amp; โคด๏ธ, ๐Ÿ“‚ ๐Ÿฉบ ๐ŸŽง-๐Ÿˆธ, <a href="http://127.0.0.1:8000/subapi/docs" class="external-link" target="_blank">http://127.0.0.1:8000/subapi/docs</a>.
๐Ÿ‘† ๐Ÿ”œ ๐Ÿ‘€ ๐Ÿง ๐Ÿ› ๏ธ ๐Ÿฉบ ๐ŸŽง-๐Ÿˆธ, โœ… ๐Ÿ•ด ๐Ÿšฎ ๐Ÿ‘ _โžก ๐Ÿ› ๏ธ_, ๐ŸŒ ๐Ÿ”ฝ โ˜‘ ๐ŸŽง-โžก ๐Ÿ”ก `/subapi`:
<img src="/img/tutorial/sub-applications/image02.png">
๐Ÿšฅ ๐Ÿ‘† ๐Ÿ”„ ๐Ÿ”— โฎ๏ธ ๐Ÿ™† 2๏ธโƒฃ ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ”ข, ๐Ÿ‘ซ ๐Ÿ”œ ๐Ÿ‘ท โ˜‘, โ†ฉ๏ธ ๐Ÿ–ฅ ๐Ÿ”œ ๐Ÿ’ช ๐Ÿ’ฌ ๐Ÿ”  ๐ŸŽฏ ๐Ÿ“ฑ โš–๏ธ ๐ŸŽง-๐Ÿ“ฑ.
### ๐Ÿ“ก โ„น: `root_path`
๐Ÿ•โ” ๐Ÿ‘† ๐Ÿ—ป ๐ŸŽง-๐Ÿˆธ ๐Ÿ”ฌ ๐Ÿ”›, FastAPI ๐Ÿ”œ โœŠ ๐Ÿ’… ๐Ÿ”— ๐Ÿ—ป โžก ๐ŸŽง-๐Ÿˆธ โš™๏ธ ๐Ÿ› ๏ธ โšช๏ธโžก๏ธ ๐Ÿ”ซ ๐Ÿ”ง ๐Ÿค™ `root_path`.
๐Ÿ‘ˆ ๐ŸŒŒ, ๐ŸŽง-๐Ÿˆธ ๐Ÿ”œ ๐Ÿ’ญ โš™๏ธ ๐Ÿ‘ˆ โžก ๐Ÿ”ก ๐Ÿฉบ ๐ŸŽš.
&amp; ๐ŸŽง-๐Ÿˆธ ๐Ÿ’ช โœ”๏ธ ๐Ÿšฎ ๐Ÿ‘ ๐Ÿ“Œ ๐ŸŽง-๐Ÿˆธ &amp; ๐ŸŒ ๐Ÿ”œ ๐Ÿ‘ท โ˜‘, โ†ฉ๏ธ FastAPI ๐Ÿต ๐ŸŒ ๐Ÿ‘‰ `root_path`โ“‚ ๐Ÿ”.
๐Ÿ‘† ๐Ÿ”œ ๐Ÿ’ก ๐ŸŒ… ๐Ÿ”ƒ `root_path` &amp; โ” โš™๏ธ โšซ๏ธ ๐ŸŽฏ ๐Ÿ“„ ๐Ÿ”ƒ [โ›… ๐Ÿ—ณ](./behind-a-proxy.md){.internal-link target=_blank}.

77
docs/em/docs/advanced/templates.md

@ -0,0 +1,77 @@
# ๐Ÿ“„
๐Ÿ‘† ๐Ÿ’ช โš™๏ธ ๐Ÿ™† ๐Ÿ“„ ๐Ÿš’ ๐Ÿ‘† ๐Ÿ’š โฎ๏ธ **FastAPI**.
โš  โš’ Jinja2๏ธโƒฃ, ๐ŸŽ 1๏ธโƒฃ โš™๏ธ ๐Ÿบ &amp; ๐ŸŽ ๐Ÿงฐ.
๐Ÿ“ค ๐Ÿš™ ๐Ÿ”— โšซ๏ธ ๐Ÿ’ช ๐Ÿ‘ˆ ๐Ÿ‘† ๐Ÿ’ช โš™๏ธ ๐Ÿ”— ๐Ÿ‘† **FastAPI** ๐Ÿˆธ (๐Ÿšš ๐Ÿ’ƒ).
## โŽ ๐Ÿ”—
โŽ `jinja2`:
<div class="termy">
```console
$ pip install jinja2
---> 100%
```
</div>
## โš™๏ธ `Jinja2Templates`
* ๐Ÿ—„ `Jinja2Templates`.
* โœ `templates` ๐ŸŽš ๐Ÿ‘ˆ ๐Ÿ‘† ๐Ÿ’ช ๐Ÿค-โš™๏ธ โช.
* ๐Ÿ“ฃ `Request` ๐Ÿ”ข *โžก ๐Ÿ› ๏ธ* ๐Ÿ‘ˆ ๐Ÿ”œ ๐Ÿ“จ ๐Ÿ“„.
* โš™๏ธ `templates` ๐Ÿ‘† โœ โœ &amp; ๐Ÿ“จ `TemplateResponse`, ๐Ÿšถโ€โ™€๏ธ `request` 1๏ธโƒฃ ๐Ÿ”‘-๐Ÿ’ฒ ๐Ÿ‘ซ Jinja2๏ธโƒฃ "๐Ÿ”‘".
```Python hl_lines="4 11 15-16"
{!../../../docs_src/templates/tutorial001.py!}
```
!!! note
๐Ÿ‘€ ๐Ÿ‘ˆ ๐Ÿ‘† โœ”๏ธ ๐Ÿšถโ€โ™€๏ธ `request` ๐Ÿ• ๐Ÿ”‘-๐Ÿ’ฒ ๐Ÿ‘ซ ๐Ÿ”‘ Jinja2๏ธโƒฃ. , ๐Ÿ‘† โœ”๏ธ ๐Ÿ“ฃ โšซ๏ธ ๐Ÿ‘† *โžก ๐Ÿ› ๏ธ*.
!!! tip
๐Ÿ“ฃ `response_class=HTMLResponse` ๐Ÿฉบ ๐ŸŽš ๐Ÿ”œ ๐Ÿ’ช ๐Ÿ’ญ ๐Ÿ‘ˆ ๐Ÿ“จ ๐Ÿ”œ ๐Ÿ•ธ.
!!! note "๐Ÿ“ก โ„น"
๐Ÿ‘† ๐Ÿ’ช โš™๏ธ `from starlette.templating import Jinja2Templates`.
**FastAPI** ๐Ÿšš ๐ŸŽ `starlette.templating` `fastapi.templating` ๐Ÿช ๐Ÿ‘†, ๐Ÿ‘ฉโ€๐Ÿ’ป. โœ‹๏ธ ๐ŸŒ… ๐Ÿ’ช ๐Ÿ“จ ๐Ÿ‘Ÿ ๐Ÿ”— โšช๏ธโžก๏ธ ๐Ÿ’ƒ. ๐ŸŽ โฎ๏ธ `Request` &amp; `StaticFiles`.
## โœ ๐Ÿ“„
โคด๏ธ ๐Ÿ‘† ๐Ÿ’ช โœ ๐Ÿ“„ `templates/item.html` โฎ๏ธ:
```jinja hl_lines="7"
{!../../../docs_src/templates/templates/item.html!}
```
โšซ๏ธ ๐Ÿ”œ ๐ŸŽฆ `id` โœŠ โšช๏ธโžก๏ธ "๐Ÿ”‘" `dict` ๐Ÿ‘† ๐Ÿšถโ€โ™€๏ธ:
```Python
{"request": request, "id": id}
```
## ๐Ÿ“„ &amp; ๐ŸŽป ๐Ÿ“
&amp; ๐Ÿ‘† ๐Ÿ’ช โš™๏ธ `url_for()` ๐Ÿ”˜ ๐Ÿ“„, &amp; โš™๏ธ โšซ๏ธ, ๐Ÿ–ผ, โฎ๏ธ `StaticFiles` ๐Ÿ‘† ๐Ÿ“Œ.
```jinja hl_lines="4"
{!../../../docs_src/templates/templates/item.html!}
```
๐Ÿ‘‰ ๐Ÿ–ผ, โšซ๏ธ ๐Ÿ”œ ๐Ÿ”— ๐ŸŽš ๐Ÿ“ `static/styles.css` โฎ๏ธ:
```CSS hl_lines="4"
{!../../../docs_src/templates/static/styles.css!}
```
&amp; โ†ฉ๏ธ ๐Ÿ‘† โš™๏ธ `StaticFiles`, ๐Ÿ‘ˆ ๐ŸŽš ๐Ÿ“ ๐Ÿ”œ ๐Ÿฆ ๐Ÿ” ๐Ÿ‘† **FastAPI** ๐Ÿˆธ ๐Ÿ“› `/static/styles.css`.
## ๐ŸŒ… โ„น
๐ŸŒ… โ„น, ๐Ÿ”Œ โ” ๐Ÿ’ฏ ๐Ÿ“„, โœ… <a href="https://www.starlette.io/templates/" class="external-link" target="_blank">๐Ÿ’ƒ ๐Ÿฉบ ๐Ÿ”› ๐Ÿ“„</a>.

95
docs/em/docs/advanced/testing-database.md

@ -0,0 +1,95 @@
# ๐Ÿ”ฌ ๐Ÿ’ฝ
๐Ÿ‘† ๐Ÿ’ช โš™๏ธ ๐ŸŽ ๐Ÿ”— ๐Ÿ” โšช๏ธโžก๏ธ [๐Ÿ”ฌ ๐Ÿ”— โฎ๏ธ ๐Ÿ”](testing-dependencies.md){.internal-link target=_blank} ๐Ÿ“‰ ๐Ÿ’ฝ ๐Ÿ”ฌ.
๐Ÿ‘† ๐Ÿ’ช ๐Ÿ’š โš’ ๐Ÿ†™ ๐ŸŽ ๐Ÿ’ฝ ๐Ÿ”ฌ, ๐Ÿ’พ ๐Ÿ’ฝ โฎ๏ธ ๐Ÿ’ฏ, ๐Ÿค-๐Ÿฅง โšซ๏ธ โฎ๏ธ ๐Ÿ”ฌ ๐Ÿ’ฝ, โ™’๏ธ.
๐Ÿ‘‘ ๐Ÿ’ญ โšซ๏ธโ” ๐ŸŽ ๐Ÿ‘† ๐Ÿ‘€ ๐Ÿ‘ˆ โฎ๏ธ ๐Ÿ“ƒ.
## ๐Ÿšฎ ๐Ÿ’ฏ ๐Ÿ—„ ๐Ÿ“ฑ
โžก๏ธ โ„น ๐Ÿ–ผ โšช๏ธโžก๏ธ [๐Ÿ—„ (๐Ÿ”—) ๐Ÿ’ฝ](../tutorial/sql-databases.md){.internal-link target=_blank} โš™๏ธ ๐Ÿ”ฌ ๐Ÿ’ฝ.
๐ŸŒ ๐Ÿ“ฑ ๐Ÿ“Ÿ ๐ŸŽ, ๐Ÿ‘† ๐Ÿ’ช ๐Ÿšถ ๐Ÿ”™ ๐Ÿ‘ˆ ๐Ÿ“ƒ โœ… โ” โšซ๏ธ.
๐Ÿ•ด ๐Ÿ”€ ๐Ÿ“ฅ ๐Ÿ†• ๐Ÿ”ฌ ๐Ÿ“.
๐Ÿ‘† ๐Ÿ˜ ๐Ÿ”— `get_db()` ๐Ÿ”œ ๐Ÿ“จ ๐Ÿ’ฝ ๐ŸŽ‰.
๐Ÿ’ฏ, ๐Ÿ‘† ๐Ÿ’ช โš™๏ธ ๐Ÿ”— ๐Ÿ” ๐Ÿ“จ ๐Ÿ‘† *๐Ÿ›ƒ* ๐Ÿ’ฝ ๐ŸŽ‰ โ†ฉ๏ธ 1๏ธโƒฃ ๐Ÿ‘ˆ ๐Ÿ”œ โš™๏ธ ๐Ÿ›Ž.
๐Ÿ‘‰ ๐Ÿ–ผ ๐Ÿ‘ฅ ๐Ÿ”œ โœ ๐Ÿ• ๐Ÿ’ฝ ๐Ÿ•ด ๐Ÿ’ฏ.
## ๐Ÿ“ ๐Ÿ“Š
๐Ÿ‘ฅ โœ ๐Ÿ†• ๐Ÿ“ `sql_app/tests/test_sql_app.py`.
๐Ÿ†• ๐Ÿ“ ๐Ÿ“Š ๐Ÿ‘€ ๐Ÿ’–:
``` hl_lines="9-11"
.
โ””โ”€โ”€ sql_app
โ”œโ”€โ”€ __init__.py
โ”œโ”€โ”€ crud.py
โ”œโ”€โ”€ database.py
โ”œโ”€โ”€ main.py
โ”œโ”€โ”€ models.py
โ”œโ”€โ”€ schemas.py
โ””โ”€โ”€ tests
โ”œโ”€โ”€ __init__.py
โ””โ”€โ”€ test_sql_app.py
```
## โœ ๐Ÿ†• ๐Ÿ’ฝ ๐ŸŽ‰
๐Ÿฅ‡, ๐Ÿ‘ฅ โœ ๐Ÿ†• ๐Ÿ’ฝ ๐ŸŽ‰ โฎ๏ธ ๐Ÿ†• ๐Ÿ’ฝ.
๐Ÿ’ฏ ๐Ÿ‘ฅ ๐Ÿ”œ โš™๏ธ ๐Ÿ“ `test.db` โ†ฉ๏ธ `sql_app.db`.
โœ‹๏ธ ๐ŸŽ‚ ๐ŸŽ‰ ๐Ÿ“Ÿ ๐ŸŒ… โš–๏ธ ๐ŸŒ˜ ๐ŸŽ, ๐Ÿ‘ฅ ๐Ÿ“ โšซ๏ธ.
```Python hl_lines="8-13"
{!../../../docs_src/sql_databases/sql_app/tests/test_sql_app.py!}
```
!!! tip
๐Ÿ‘† ๐Ÿ’ช ๐Ÿ“‰ โŽ ๐Ÿ‘ˆ ๐Ÿ“Ÿ ๐Ÿšฎ โšซ๏ธ ๐Ÿ”ข &amp; โš™๏ธ โšซ๏ธ โšช๏ธโžก๏ธ ๐Ÿ‘ฏโ€โ™‚๏ธ `database.py` &amp; `tests/test_sql_app.py`.
๐Ÿฆ &amp; ๐ŸŽฏ ๐Ÿ”› ๐ŸŽฏ ๐Ÿ”ฌ ๐Ÿ“Ÿ, ๐Ÿ‘ฅ ๐Ÿ–จ โšซ๏ธ.
## โœ ๐Ÿ’ฝ
โ†ฉ๏ธ ๐Ÿ”œ ๐Ÿ‘ฅ ๐Ÿ”œ โš™๏ธ ๐Ÿ†• ๐Ÿ’ฝ ๐Ÿ†• ๐Ÿ“, ๐Ÿ‘ฅ ๐Ÿ’ช โš’ ๐Ÿ’ญ ๐Ÿ‘ฅ โœ ๐Ÿ’ฝ โฎ๏ธ:
```Python
Base.metadata.create_all(bind=engine)
```
๐Ÿ‘ˆ ๐Ÿ›Ž ๐Ÿค™ `main.py`, โœ‹๏ธ โธ `main.py` โš™๏ธ ๐Ÿ’ฝ ๐Ÿ“ `sql_app.db`, &amp; ๐Ÿ‘ฅ ๐Ÿ’ช โš’ ๐Ÿ’ญ ๐Ÿ‘ฅ โœ `test.db` ๐Ÿ’ฏ.
๐Ÿ‘ฅ ๐Ÿšฎ ๐Ÿ‘ˆ โธ ๐Ÿ“ฅ, โฎ๏ธ ๐Ÿ†• ๐Ÿ“.
```Python hl_lines="16"
{!../../../docs_src/sql_databases/sql_app/tests/test_sql_app.py!}
```
## ๐Ÿ”— ๐Ÿ”
๐Ÿ”œ ๐Ÿ‘ฅ โœ ๐Ÿ”— ๐Ÿ” &amp; ๐Ÿšฎ โšซ๏ธ ๐Ÿ” ๐Ÿ‘† ๐Ÿ“ฑ.
```Python hl_lines="19-24 27"
{!../../../docs_src/sql_databases/sql_app/tests/test_sql_app.py!}
```
!!! tip
๐Ÿ“Ÿ `override_get_db()` ๐ŸŒ– โšซ๏ธโ” ๐ŸŽ `get_db()`, โœ‹๏ธ `override_get_db()` ๐Ÿ‘ฅ โš™๏ธ `TestingSessionLocal` ๐Ÿ”ฌ ๐Ÿ’ฝ โ†ฉ๏ธ.
## ๐Ÿ’ฏ ๐Ÿ“ฑ
โคด๏ธ ๐Ÿ‘ฅ ๐Ÿ’ช ๐Ÿ’ฏ ๐Ÿ“ฑ ๐Ÿ›Ž.
```Python hl_lines="32-47"
{!../../../docs_src/sql_databases/sql_app/tests/test_sql_app.py!}
```
&amp; ๐ŸŒ ๐Ÿ› ๏ธ ๐Ÿ‘ฅ โš’ ๐Ÿ’ฝ โฎ๏ธ ๐Ÿ’ฏ ๐Ÿ”œ `test.db` ๐Ÿ’ฝ โ†ฉ๏ธ ๐Ÿ‘‘ `sql_app.db`.

49
docs/em/docs/advanced/testing-dependencies.md

@ -0,0 +1,49 @@
# ๐Ÿ”ฌ ๐Ÿ”— โฎ๏ธ ๐Ÿ”
## ๐Ÿ”‘ ๐Ÿ”— โฎ๏ธ ๐Ÿ”ฌ
๐Ÿ“ค ๐Ÿ˜ ๐ŸŒโ” ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ’š ๐Ÿ” ๐Ÿ”— โฎ๏ธ ๐Ÿ”ฌ.
๐Ÿ‘† ๐Ÿšซ ๐Ÿ’š โฎ๏ธ ๐Ÿ”— ๐Ÿƒ (๐Ÿšซ ๐Ÿ™† ๐ŸŽง-๐Ÿ”— โšซ๏ธ ๐Ÿ’ช โœ”๏ธ).
โ†ฉ๏ธ, ๐Ÿ‘† ๐Ÿ’š ๐Ÿšš ๐ŸŽ ๐Ÿ”— ๐Ÿ‘ˆ ๐Ÿ”œ โš™๏ธ ๐Ÿ•ด โฎ๏ธ ๐Ÿ’ฏ (๐ŸŽฒ ๐Ÿ•ด ๐ŸŽฏ ๐Ÿ’ฏ), &amp; ๐Ÿ”œ ๐Ÿšš ๐Ÿ’ฒ ๐Ÿ‘ˆ ๐Ÿ’ช โš™๏ธ ๐ŸŒโ” ๐Ÿ’ฒ โฎ๏ธ ๐Ÿ”— โš™๏ธ.
### โš™๏ธ ๐Ÿ’ผ: ๐Ÿ”ข ๐Ÿ•โ€๐Ÿฆบ
๐Ÿ–ผ ๐Ÿ’ช ๐Ÿ‘ˆ ๐Ÿ‘† โœ”๏ธ ๐Ÿ”ข ๐Ÿค ๐Ÿ•โ€๐Ÿฆบ ๐Ÿ‘ˆ ๐Ÿ‘† ๐Ÿ’ช ๐Ÿค™.
๐Ÿ‘† ๐Ÿ“จ โšซ๏ธ ๐Ÿค &amp; โšซ๏ธ ๐Ÿ“จ ๐Ÿ”“ ๐Ÿ‘ฉโ€๐Ÿ’ป.
๐Ÿ‘‰ ๐Ÿ•โ€๐Ÿฆบ 5๏ธโƒฃ๐Ÿ“† ๐Ÿ”Œ ๐Ÿ‘† ๐Ÿ“ ๐Ÿ“จ, &amp; ๐Ÿค™ โšซ๏ธ ๐Ÿ’ช โœŠ โž• ๐Ÿ•ฐ ๐ŸŒ˜ ๐Ÿšฅ ๐Ÿ‘† โœ”๏ธ ๐Ÿ”ง ๐ŸŽ ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ’ฏ.
๐Ÿ‘† ๐ŸŽฒ ๐Ÿ’š ๐Ÿ’ฏ ๐Ÿ”ข ๐Ÿ•โ€๐Ÿฆบ ๐Ÿ•, โœ‹๏ธ ๐Ÿšซ ๐ŸŽฏ ๐Ÿค™ โšซ๏ธ ๐Ÿ”  ๐Ÿ’ฏ ๐Ÿ‘ˆ ๐Ÿƒ.
๐Ÿ‘‰ ๐Ÿ’ผ, ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ” ๐Ÿ”— ๐Ÿ‘ˆ ๐Ÿค™ ๐Ÿ‘ˆ ๐Ÿ•โ€๐Ÿฆบ, &amp; โš™๏ธ ๐Ÿ›ƒ ๐Ÿ”— ๐Ÿ‘ˆ ๐Ÿ“จ ๐ŸŽ ๐Ÿ‘ฉโ€๐Ÿ’ป, ๐Ÿ•ด ๐Ÿ‘† ๐Ÿ’ฏ.
### โš™๏ธ `app.dependency_overrides` ๐Ÿ”ข
๐Ÿ‘ซ ๐Ÿ’ผ, ๐Ÿ‘† **FastAPI** ๐Ÿˆธ โœ”๏ธ ๐Ÿ”ข `app.dependency_overrides`, โšซ๏ธ ๐Ÿ™… `dict`.
๐Ÿ” ๐Ÿ”— ๐Ÿ”ฌ, ๐Ÿ‘† ๐Ÿšฎ ๐Ÿ”‘ โฎ๏ธ ๐Ÿ”— (๐Ÿ”ข), &amp; ๐Ÿ’ฒ, ๐Ÿ‘† ๐Ÿ”— ๐Ÿ” (โž•1๏ธโƒฃ ๐Ÿ”ข).
&amp; โคด๏ธ **FastAPI** ๐Ÿ”œ ๐Ÿค™ ๐Ÿ‘ˆ ๐Ÿ” โ†ฉ๏ธ โฎ๏ธ ๐Ÿ”—.
```Python hl_lines="28-29 32"
{!../../../docs_src/dependency_testing/tutorial001.py!}
```
!!! tip
๐Ÿ‘† ๐Ÿ’ช โš’ ๐Ÿ”— ๐Ÿ” ๐Ÿ”— โš™๏ธ ๐Ÿ™† ๐Ÿ‘† **FastAPI** ๐Ÿˆธ.
โฎ๏ธ ๐Ÿ”— ๐Ÿ’ช โš™๏ธ *โžก ๐Ÿ› ๏ธ ๐Ÿ”ข*, *โžก ๐Ÿ› ๏ธ ๐Ÿ‘จโ€๐ŸŽจ* (๐Ÿ•โ” ๐Ÿ‘† ๐Ÿšซ โš™๏ธ ๐Ÿ“จ ๐Ÿ’ฒ), `.include_router()` ๐Ÿค™, โ™’๏ธ.
FastAPI ๐Ÿ”œ ๐Ÿ’ช ๐Ÿ” โšซ๏ธ.
โคด๏ธ ๐Ÿ‘† ๐Ÿ’ช โฒ ๐Ÿ‘† ๐Ÿ” (โŽ ๐Ÿ‘ซ) โš’ `app.dependency_overrides` ๐Ÿ› `dict`:
```Python
app.dependency_overrides = {}
```
!!! tip
๐Ÿšฅ ๐Ÿ‘† ๐Ÿ’š ๐Ÿ” ๐Ÿ”— ๐Ÿ•ด โฎ๏ธ ๐Ÿ’ฏ, ๐Ÿ‘† ๐Ÿ’ช โš’ ๐Ÿ” โ–ถ๏ธ ๐Ÿ’ฏ (๐Ÿ”˜ ๐Ÿ’ฏ ๐Ÿ”ข) &amp; โฒ โšซ๏ธ ๐Ÿ”š (๐Ÿ”š ๐Ÿ’ฏ ๐Ÿ”ข).

7
docs/em/docs/advanced/testing-events.md

@ -0,0 +1,7 @@
# ๐Ÿ”ฌ ๐ŸŽ‰: ๐Ÿ•ด - ๐Ÿคซ
๐Ÿ•โ” ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ‘† ๐ŸŽ‰ ๐Ÿ•โ€๐Ÿฆบ (`startup` &amp; `shutdown`) ๐Ÿƒ ๐Ÿ‘† ๐Ÿ’ฏ, ๐Ÿ‘† ๐Ÿ’ช โš™๏ธ `TestClient` โฎ๏ธ `with` ๐Ÿ“„:
```Python hl_lines="9-12 20-24"
{!../../../docs_src/app_testing/tutorial003.py!}
```

12
docs/em/docs/advanced/testing-websockets.md

@ -0,0 +1,12 @@
# ๐Ÿ”ฌ *๏ธโƒฃ
๐Ÿ‘† ๐Ÿ’ช โš™๏ธ ๐ŸŽ `TestClient` ๐Ÿ’ฏ*๏ธโƒฃ.
๐Ÿ‘‰, ๐Ÿ‘† โš™๏ธ `TestClient` `with` ๐Ÿ“„, ๐Ÿ”—*๏ธโƒฃ:
```Python hl_lines="27-31"
{!../../../docs_src/app_testing/tutorial002.py!}
```
!!! note
๐ŸŒ… โ„น, โœ… ๐Ÿ’ƒ ๐Ÿงพ <a href="https://www.starlette.io/testclient/#testing-websocket-sessions" class="external-link" target="_blank">๐Ÿ”ฌ *๏ธโƒฃ </a>.

52
docs/em/docs/advanced/using-request-directly.md

@ -0,0 +1,52 @@
# โš™๏ธ ๐Ÿ“จ ๐Ÿ”—
๐Ÿ†™ ๐Ÿ”œ, ๐Ÿ‘† โœ”๏ธ ๐Ÿ“ฃ ๐Ÿ• ๐Ÿ“จ ๐Ÿ‘ˆ ๐Ÿ‘† ๐Ÿ’ช โฎ๏ธ ๐Ÿ‘ซ ๐Ÿ†Ž.
โœŠ ๐Ÿ“Š โšช๏ธโžก๏ธ:
* โžก ๐Ÿ”ข.
* ๐ŸŽš.
* ๐Ÿช.
* โ™’๏ธ.
&amp; ๐Ÿ”จ, **FastAPI** โš– ๐Ÿ‘ˆ ๐Ÿ’ฝ, ๐Ÿญ โšซ๏ธ &amp; ๐Ÿญ ๐Ÿงพ ๐Ÿ‘† ๐Ÿ› ๏ธ ๐Ÿ”.
โœ‹๏ธ ๐Ÿ“ค โš  ๐ŸŒโ” ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ’ช ๐Ÿ” `Request` ๐ŸŽš ๐Ÿ”—.
## โ„น ๐Ÿ”ƒ `Request` ๐ŸŽš
**FastAPI** ๐Ÿค™ **๐Ÿ’ƒ** ๐Ÿ”˜, โฎ๏ธ ๐Ÿงฝ ๐Ÿ“š ๐Ÿงฐ ๐Ÿ”› ๐Ÿ”, ๐Ÿ‘† ๐Ÿ’ช โš™๏ธ ๐Ÿ’ƒ <a href="https://www.starlette.io/requests/" class="external-link" target="_blank">`Request`</a> ๐ŸŽš ๐Ÿ”— ๐Ÿ•โ” ๐Ÿ‘† ๐Ÿ’ช.
โšซ๏ธ ๐Ÿ”œ โ›“ ๐Ÿ‘ˆ ๐Ÿšฅ ๐Ÿ‘† ๐Ÿคš ๐Ÿ“Š โšช๏ธโžก๏ธ `Request` ๐ŸŽš ๐Ÿ”— (๐Ÿ–ผ, โœ ๐Ÿ’ช) โšซ๏ธ ๐Ÿ† ๐Ÿšซ โœ”, ๐Ÿ—œ โš–๏ธ ๐Ÿ“„ (โฎ๏ธ ๐Ÿ—„, ๐Ÿง ๐Ÿ› ๏ธ ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ”ข) FastAPI.
๐Ÿ‘ ๐Ÿ™† ๐ŸŽ ๐Ÿ”ข ๐Ÿ“ฃ ๐Ÿ›Ž (๐Ÿ–ผ, ๐Ÿ’ช โฎ๏ธ Pydantic ๐Ÿท) ๐Ÿ”œ โœ”, ๐Ÿ—œ, โœ, โ™’๏ธ.
โœ‹๏ธ ๐Ÿ“ค ๐ŸŽฏ ๐Ÿ’ผ ๐ŸŒโ” โšซ๏ธ โš  ๐Ÿคš `Request` ๐ŸŽš.
## โš™๏ธ `Request` ๐ŸŽš ๐Ÿ”—
โžก๏ธ ๐ŸŒˆ ๐Ÿ‘† ๐Ÿ’š ๐Ÿคš ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ“ข ๐Ÿ“ข/๐Ÿฆ  ๐Ÿ”˜ ๐Ÿ‘† *โžก ๐Ÿ› ๏ธ ๐Ÿ”ข*.
๐Ÿ‘ˆ ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ” ๐Ÿ“จ ๐Ÿ”—.
```Python hl_lines="1 7-8"
{!../../../docs_src/using_request_directly/tutorial001.py!}
```
๐Ÿ“ฃ *โžก ๐Ÿ› ๏ธ ๐Ÿ”ข* ๐Ÿ”ข โฎ๏ธ ๐Ÿ†Ž โž– `Request` **FastAPI** ๐Ÿ”œ ๐Ÿ’ญ ๐Ÿšถโ€โ™€๏ธ `Request` ๐Ÿ‘ˆ ๐Ÿ”ข.
!!! tip
๐Ÿ—’ ๐Ÿ‘ˆ ๐Ÿ‘‰ ๐Ÿ’ผ, ๐Ÿ‘ฅ ๐Ÿ“ฃ โžก ๐Ÿ”ข โคด๏ธ ๐Ÿ“จ ๐Ÿ”ข.
, โžก ๐Ÿ”ข ๐Ÿ”œ โš—, โœ”, ๐Ÿ—œ โœ” ๐Ÿ†Ž &amp; โœ โฎ๏ธ ๐Ÿ—„.
๐ŸŽ ๐ŸŒŒ, ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ“ฃ ๐Ÿ™† ๐ŸŽ ๐Ÿ”ข ๐Ÿ›Ž, &amp; โžก, ๐Ÿคš `Request` ๐Ÿ’โ€โ™‚๏ธ.
## `Request` ๐Ÿงพ
๐Ÿ‘† ๐Ÿ’ช โœ ๐ŸŒ… โ„น ๐Ÿ”ƒ <a href="https://www.starlette.io/requests/" class="external-link" target="_blank">`Request` ๐ŸŽš ๐Ÿ›‚ ๐Ÿ’ƒ ๐Ÿงพ ๐Ÿ•ธ</a>.
!!! note "๐Ÿ“ก โ„น"
๐Ÿ‘† ๐Ÿ’ช โš™๏ธ `from starlette.requests import Request`.
**FastAPI** ๐Ÿšš โšซ๏ธ ๐Ÿ”— ๐Ÿช ๐Ÿ‘†, ๐Ÿ‘ฉโ€๐Ÿ’ป. โœ‹๏ธ โšซ๏ธ ๐Ÿ‘Ÿ ๐Ÿ”— โšช๏ธโžก๏ธ ๐Ÿ’ƒ.

184
docs/em/docs/advanced/websockets.md

@ -0,0 +1,184 @@
# *๏ธโƒฃ
๐Ÿ‘† ๐Ÿ’ช โš™๏ธ <a href="https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API" class="external-link" target="_blank"> *๏ธโƒฃ </a> โฎ๏ธ **FastAPI**.
## โŽ `WebSockets`
๐Ÿฅ‡ ๐Ÿ‘† ๐Ÿ’ช โŽ `WebSockets`:
<div class="termy">
```console
$ pip install websockets
---> 100%
```
</div>
## *๏ธโƒฃ ๐Ÿ‘ฉโ€๐Ÿ’ป
### ๐Ÿญ
๐Ÿ‘† ๐Ÿญ โš™๏ธ, ๐Ÿ‘† ๐ŸŽฒ โœ”๏ธ ๐Ÿ•ธ โœ โฎ๏ธ ๐Ÿ› ๐Ÿ› ๏ธ ๐Ÿ’– ๐Ÿ˜ฅ, Vue.js โš–๏ธ ๐Ÿ“.
&amp; ๐Ÿ”— โš™๏ธ *๏ธโƒฃ โฎ๏ธ ๐Ÿ‘† ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ‘† ๐Ÿ”œ ๐ŸŽฒ โš™๏ธ ๐Ÿ‘† ๐Ÿ•ธ ๐Ÿš™.
โš–๏ธ ๐Ÿ‘† ๐Ÿ’ช โœ”๏ธ ๐Ÿ‡ฆ๐Ÿ‡ธ ๐Ÿ“ฑ ๐Ÿˆธ ๐Ÿ‘ˆ ๐Ÿ”— โฎ๏ธ ๐Ÿ‘† *๏ธโƒฃ ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ”—, ๐Ÿ‡ฆ๐Ÿ‡ธ ๐Ÿ“Ÿ.
โš–๏ธ ๐Ÿ‘† 5๏ธโƒฃ๐Ÿ“† โœ”๏ธ ๐Ÿ™† ๐ŸŽ ๐ŸŒŒ ๐Ÿ”— โฎ๏ธ *๏ธโƒฃ ๐Ÿ”—.
---
โœ‹๏ธ ๐Ÿ‘‰ ๐Ÿ–ผ, ๐Ÿ‘ฅ ๐Ÿ”œ โš™๏ธ ๐Ÿ“ถ ๐Ÿ™… ๐Ÿ•ธ ๐Ÿ“„ โฎ๏ธ ๐Ÿ•ธ, ๐ŸŒ ๐Ÿ”˜ ๐Ÿ“ ๐ŸŽป.
๐Ÿ‘‰, โ†—๏ธ, ๐Ÿšซ โš– &amp; ๐Ÿ‘† ๐Ÿšซ๐Ÿ”œ โš™๏ธ โšซ๏ธ ๐Ÿญ.
๐Ÿญ ๐Ÿ‘† ๐Ÿ”œ โœ”๏ธ 1๏ธโƒฃ ๐ŸŽ› ๐Ÿ”›.
โœ‹๏ธ โšซ๏ธ ๐Ÿ™… ๐ŸŒŒ ๐ŸŽฏ ๐Ÿ”› ๐Ÿ’ฝ-๐Ÿš„ *๏ธโƒฃ &amp; โœ”๏ธ ๐Ÿ‘ท ๐Ÿ–ผ:
```Python hl_lines="2 6-38 41-43"
{!../../../docs_src/websockets/tutorial001.py!}
```
## โœ `websocket`
๐Ÿ‘† **FastAPI** ๐Ÿˆธ, โœ `websocket`:
```Python hl_lines="1 46-47"
{!../../../docs_src/websockets/tutorial001.py!}
```
!!! note "๐Ÿ“ก โ„น"
๐Ÿ‘† ๐Ÿ’ช โš™๏ธ `from starlette.websockets import WebSocket`.
**FastAPI** ๐Ÿšš ๐ŸŽ `WebSocket` ๐Ÿ”— ๐Ÿช ๐Ÿ‘†, ๐Ÿ‘ฉโ€๐Ÿ’ป. โœ‹๏ธ โšซ๏ธ ๐Ÿ‘Ÿ ๐Ÿ”— โšช๏ธโžก๏ธ ๐Ÿ’ƒ.
## โŒ› ๐Ÿ“ง &amp; ๐Ÿ“จ ๐Ÿ“ง
๐Ÿ‘† *๏ธโƒฃ ๐Ÿ›ฃ ๐Ÿ‘† ๐Ÿ’ช `await` ๐Ÿ“ง &amp; ๐Ÿ“จ ๐Ÿ“ง.
```Python hl_lines="48-52"
{!../../../docs_src/websockets/tutorial001.py!}
```
๐Ÿ‘† ๐Ÿ’ช ๐Ÿ“จ &amp; ๐Ÿ“จ ๐Ÿ’ฑ, โœ, &amp; ๐ŸŽป ๐Ÿ’ฝ.
## ๐Ÿ”„ โšซ๏ธ
๐Ÿšฅ ๐Ÿ‘† ๐Ÿ“ ๐Ÿ“› `main.py`, ๐Ÿƒ ๐Ÿ‘† ๐Ÿˆธ โฎ๏ธ:
<div class="termy">
```console
$ uvicorn main:app --reload
<span style="color: green;">INFO</span>: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
```
</div>
๐Ÿ“‚ ๐Ÿ‘† ๐Ÿ–ฅ <a href="http://127.0.0.1:8000" class="external-link" target="_blank">http://127.0.0.1:8000</a>.
๐Ÿ‘† ๐Ÿ”œ ๐Ÿ‘€ ๐Ÿ™… ๐Ÿ“ƒ ๐Ÿ’–:
<img src="/img/tutorial/websockets/image01.png">
๐Ÿ‘† ๐Ÿ’ช ๐Ÿ†Ž ๐Ÿ“ง ๐Ÿ”ข ๐Ÿ“ฆ, &amp; ๐Ÿ“จ ๐Ÿ‘ซ:
<img src="/img/tutorial/websockets/image02.png">
&amp; ๐Ÿ‘† **FastAPI** ๐Ÿˆธ โฎ๏ธ *๏ธโƒฃ ๐Ÿ”œ ๐Ÿ“จ ๐Ÿ”™:
<img src="/img/tutorial/websockets/image03.png">
๐Ÿ‘† ๐Ÿ’ช ๐Ÿ“จ (&amp; ๐Ÿ“จ) ๐Ÿ“š ๐Ÿ“ง:
<img src="/img/tutorial/websockets/image04.png">
&amp; ๐ŸŒ ๐Ÿ‘ซ ๐Ÿ”œ โš™๏ธ ๐ŸŽ *๏ธโƒฃ ๐Ÿ”—.
## โš™๏ธ `Depends` &amp; ๐ŸŽ
*๏ธโƒฃ ๐Ÿ”— ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ—„ โšช๏ธโžก๏ธ `fastapi` &amp; โš™๏ธ:
* `Depends`
* `Security`
* `Cookie`
* `Header`
* `Path`
* `Query`
๐Ÿ‘ซ ๐Ÿ‘ท ๐ŸŽ ๐ŸŒŒ ๐ŸŽ FastAPI ๐Ÿ”—/*โžก ๐Ÿ› ๏ธ*:
```Python hl_lines="66-77 76-91"
{!../../../docs_src/websockets/tutorial002.py!}
```
!!! info
๐Ÿ‘‰ *๏ธโƒฃ โšซ๏ธ ๐Ÿšซ ๐Ÿค™ โš’ ๐Ÿ”‘ ๐Ÿคš `HTTPException`, โ†ฉ๏ธ ๐Ÿ‘ฅ ๐Ÿคš `WebSocketException`.
๐Ÿ‘† ๐Ÿ’ช โš™๏ธ ๐Ÿ“ช ๐Ÿ“Ÿ โšช๏ธโžก๏ธ <a href="https://tools.ietf.org/html/rfc6455#section-7.4.1" class="external-link" target="_blank">โ˜‘ ๐Ÿ“Ÿ ๐Ÿ”ฌ ๐Ÿ”ง</a>.
### ๐Ÿ”„ *๏ธโƒฃ โฎ๏ธ ๐Ÿ”—
๐Ÿšฅ ๐Ÿ‘† ๐Ÿ“ ๐Ÿ“› `main.py`, ๐Ÿƒ ๐Ÿ‘† ๐Ÿˆธ โฎ๏ธ:
<div class="termy">
```console
$ uvicorn main:app --reload
<span style="color: green;">INFO</span>: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
```
</div>
๐Ÿ“‚ ๐Ÿ‘† ๐Ÿ–ฅ <a href="http://127.0.0.1:8000" class="external-link" target="_blank">http://127.0.0.1:8000</a>.
๐Ÿ“ค ๐Ÿ‘† ๐Ÿ’ช โš’:
* "๐Ÿฌ ๐Ÿ†”", โš™๏ธ โžก.
* "๐Ÿค" โš™๏ธ ๐Ÿ”ข ๐Ÿ”ข.
!!! tip
๐Ÿ‘€ ๐Ÿ‘ˆ ๐Ÿ”ข `token` ๐Ÿ”œ ๐Ÿต ๐Ÿ”—.
โฎ๏ธ ๐Ÿ‘ˆ ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ”— *๏ธโƒฃ &amp; โคด๏ธ ๐Ÿ“จ &amp; ๐Ÿ“จ ๐Ÿ“ง:
<img src="/img/tutorial/websockets/image05.png">
## ๐Ÿšš ๐Ÿ”€ &amp; ๐Ÿ’— ๐Ÿ‘ฉโ€๐Ÿ’ป
๐Ÿ•โ” *๏ธโƒฃ ๐Ÿ”— ๐Ÿ“ช, `await websocket.receive_text()` ๐Ÿ”œ ๐Ÿคš `WebSocketDisconnect` โš , โ” ๐Ÿ‘† ๐Ÿ’ช โคด๏ธ โœŠ &amp; ๐Ÿต ๐Ÿ’– ๐Ÿ‘‰ ๐Ÿ–ผ.
```Python hl_lines="81-83"
{!../../../docs_src/websockets/tutorial003.py!}
```
๐Ÿ”„ โšซ๏ธ ๐Ÿ‘…:
* ๐Ÿ“‚ ๐Ÿ“ฑ โฎ๏ธ ๐Ÿ“š ๐Ÿ–ฅ ๐Ÿ“‘.
* โœ ๐Ÿ“ง โšช๏ธโžก๏ธ ๐Ÿ‘ซ.
* โคด๏ธ ๐Ÿ” 1๏ธโƒฃ ๐Ÿ“‘.
๐Ÿ‘ˆ ๐Ÿ”œ ๐Ÿคš `WebSocketDisconnect` โš , &amp; ๐ŸŒ ๐ŸŽ ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ”œ ๐Ÿ“จ ๐Ÿ“ง ๐Ÿ’–:
```
Client #1596980209979 left the chat
```
!!! tip
๐Ÿ“ฑ ๐Ÿ”› โญ &amp; ๐Ÿ™… ๐Ÿ–ผ ๐ŸŽฆ โ” ๐Ÿต &amp; ๐Ÿ“ป ๐Ÿ“ง ๐Ÿ“š *๏ธโƒฃ ๐Ÿ”—.
โœ‹๏ธ โœ”๏ธ ๐Ÿคฏ ๐Ÿ‘ˆ, ๐ŸŒ ๐Ÿต ๐Ÿ’พ, ๐Ÿ‘ ๐Ÿ“‡, โšซ๏ธ ๐Ÿ”œ ๐Ÿ•ด ๐Ÿ‘ท โช ๐Ÿ› ๏ธ ๐Ÿƒ, &amp; ๐Ÿ”œ ๐Ÿ•ด ๐Ÿ‘ท โฎ๏ธ ๐Ÿ‘ ๐Ÿ› ๏ธ.
๐Ÿšฅ ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ•ณ โฉ ๐Ÿ› ๏ธ โฎ๏ธ FastAPI โœ‹๏ธ ๐Ÿ‘ˆ ๐ŸŒ– ๐Ÿ‹๏ธ, ๐Ÿ•โ€๐Ÿฆบ โœณ, โœณ โš–๏ธ ๐ŸŽ, โœ… <a href="https://github.com/encode/broadcaster" class="external-link" target="_blank">๐Ÿ—œ/๐Ÿ“ป</a>.
## ๐ŸŒ… โ„น
๐Ÿ’ก ๐ŸŒ… ๐Ÿ”ƒ ๐ŸŽ›, โœ… ๐Ÿ’ƒ ๐Ÿงพ:
* <a href="https://www.starlette.io/websockets/" class="external-link" target="_blank"> `WebSocket` ๐ŸŽ“</a>.
* <a href="https://www.starlette.io/endpoints/#websocketendpoint" class="external-link" target="_blank">๐ŸŽ“-โš“๏ธ *๏ธโƒฃ ๐Ÿšš</a>.

37
docs/em/docs/advanced/wsgi.md

@ -0,0 +1,37 @@
# โœ… ๐Ÿ‡จ๐Ÿ‡ป - ๐Ÿบ, โœณ, ๐ŸŽ
๐Ÿ‘† ๐Ÿ’ช ๐Ÿ—ป ๐Ÿ‡จ๐Ÿ‡ป ๐Ÿˆธ ๐Ÿ‘† ๐Ÿ‘€ โฎ๏ธ [๐ŸŽง ๐Ÿˆธ - ๐Ÿ—ป](./sub-applications.md){.internal-link target=_blank}, [โ›… ๐Ÿ—ณ](./behind-a-proxy.md){.internal-link target=_blank}.
๐Ÿ‘ˆ, ๐Ÿ‘† ๐Ÿ’ช โš™๏ธ `WSGIMiddleware` &amp; โš™๏ธ โšซ๏ธ ๐ŸŽ ๐Ÿ‘† ๐Ÿ‡จ๐Ÿ‡ป ๐Ÿˆธ, ๐Ÿ–ผ, ๐Ÿบ, โœณ, โ™’๏ธ.
## โš™๏ธ `WSGIMiddleware`
๐Ÿ‘† ๐Ÿ’ช ๐Ÿ—„ `WSGIMiddleware`.
โคด๏ธ ๐ŸŽ ๐Ÿ‡จ๐Ÿ‡ป (โœ… ๐Ÿบ) ๐Ÿ“ฑ โฎ๏ธ ๐Ÿ› ๏ธ.
&amp; โคด๏ธ ๐Ÿ—ป ๐Ÿ‘ˆ ๐Ÿ”ฝ โžก.
```Python hl_lines="2-3 22"
{!../../../docs_src/wsgi/tutorial001.py!}
```
## โœ… โšซ๏ธ
๐Ÿ”œ, ๐Ÿ”  ๐Ÿ“จ ๐Ÿ”ฝ โžก `/v1/` ๐Ÿ”œ ๐Ÿต ๐Ÿบ ๐Ÿˆธ.
&amp; ๐ŸŽ‚ ๐Ÿ”œ ๐Ÿต **FastAPI**.
๐Ÿšฅ ๐Ÿ‘† ๐Ÿƒ โšซ๏ธ โฎ๏ธ Uvicorn &amp; ๐Ÿšถ <a href="http://localhost:8000/v1/" class="external-link" target="_blank">http://localhost:8000/v1/</a> ๐Ÿ‘† ๐Ÿ”œ ๐Ÿ‘€ ๐Ÿ“จ โšช๏ธโžก๏ธ ๐Ÿบ:
```txt
Hello, World from Flask!
```
&amp; ๐Ÿšฅ ๐Ÿ‘† ๐Ÿšถ <a href="http://localhost:8000/v2" class="external-link" target="_blank">http://localhost:8000/v2</a> ๐Ÿ‘† ๐Ÿ”œ ๐Ÿ‘€ ๐Ÿ“จ โšช๏ธโžก๏ธ FastAPI:
```JSON
{
"message": "Hello World"
}
```

414
docs/em/docs/alternatives.md

@ -0,0 +1,414 @@
# ๐ŸŽ›, ๐ŸŒˆ &amp; ๐Ÿ”บ
โšซ๏ธโ” ๐Ÿ˜ฎ **FastAPI**, โ” โšซ๏ธ ๐Ÿ”ฌ ๐ŸŽ ๐ŸŽ› &amp; โšซ๏ธโ” โšซ๏ธ ๐Ÿ‡ญ๐Ÿ‡ฒ โšช๏ธโžก๏ธ ๐Ÿ‘ซ.
## ๐ŸŽถ
**FastAPI** ๐Ÿšซ๐Ÿ”œ ๐Ÿ”€ ๐Ÿšฅ ๐Ÿšซ โฎ๏ธ ๐Ÿ‘ท ๐ŸŽ.
๐Ÿ“ค โœ”๏ธ ๐Ÿ“š ๐Ÿงฐ โœ โญ ๐Ÿ‘ˆ โœ”๏ธ โ„น ๐Ÿ˜ฎ ๐Ÿšฎ ๐Ÿ—.
๐Ÿ‘ค โœ”๏ธ โŽ ๐Ÿ— ๐Ÿ†• ๐Ÿ› ๏ธ ๐Ÿ“š 1๏ธโƒฃ2๏ธโƒฃ๐Ÿ—“๏ธ. ๐Ÿฅ‡ ๐Ÿ‘ค ๐Ÿ”„ โŽ ๐ŸŒ โš’ ๐Ÿ“” **FastAPI** โš™๏ธ ๐Ÿ“š ๐ŸŽ ๐Ÿ› ๏ธ, ๐Ÿ”Œ-๐Ÿ”Œ, &amp; ๐Ÿงฐ.
โœ‹๏ธ โ˜, ๐Ÿ“ค ๐Ÿ™…โ€โ™‚ ๐ŸŽ ๐ŸŽ› ๐ŸŒ˜ ๐Ÿ— ๐Ÿ•ณ ๐Ÿ‘ˆ ๐Ÿšš ๐ŸŒ ๐Ÿ‘ซ โš’, โœŠ ๐Ÿ† ๐Ÿ’ญ โšช๏ธโžก๏ธ โฎ๏ธ ๐Ÿงฐ, &amp; ๐ŸŒ€ ๐Ÿ‘ซ ๐Ÿ† ๐ŸŒŒ ๐Ÿ’ช, โš™๏ธ ๐Ÿ‡ช๐Ÿ‡ธ โš’ ๐Ÿ‘ˆ โž–๐Ÿšซ ๐Ÿ’ช โญ (๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ โž• ๐Ÿ†Ž ๐Ÿ”‘).
## โฎ๏ธ ๐Ÿงฐ
### <a href="https://www.djangoproject.com/" class="external-link" target="_blank">โœณ</a>
โšซ๏ธ ๐ŸŒ… ๐ŸŒŸ ๐Ÿ ๐Ÿ› ๏ธ &amp; ๐Ÿ›Ž ๐Ÿ•ด. โšซ๏ธ โš™๏ธ ๐Ÿ— โš™๏ธ ๐Ÿ’– ๐Ÿ‘ฑ๐Ÿ“”.
โšซ๏ธ ๐Ÿ“ถ ๐Ÿ˜† ๐Ÿ”— โฎ๏ธ ๐Ÿ”— ๐Ÿ’ฝ (๐Ÿ’– โœณ โš–๏ธ โœณ),, โœ”๏ธ โ˜ ๐Ÿ’ฝ (๐Ÿ’– ๐Ÿ—„, โœณ, ๐Ÿ‘ธ, โ™’๏ธ) ๐Ÿ‘‘ ๐Ÿช ๐Ÿš’ ๐Ÿšซ ๐Ÿ“ถ โฉ.
โšซ๏ธ โœ ๐Ÿ— ๐Ÿ•ธ ๐Ÿ‘ฉโ€๐Ÿ’ป, ๐Ÿšซ โœ ๐Ÿ”— โš™๏ธ ๐Ÿ› ๐Ÿ•ธ (๐Ÿ’– ๐Ÿ˜ฅ, Vue.js &amp; ๐Ÿ“) โš–๏ธ ๐ŸŽ โš™๏ธ (๐Ÿ’– <abbr title="Internet of Things">โ˜</abbr> ๐Ÿ“ณ) ๐Ÿ”— โฎ๏ธ โšซ๏ธ.
### <a href="https://www.django-rest-framework.org/" class="external-link" target="_blank">โœณ ๐ŸŽ‚ ๐Ÿ› ๏ธ</a>
โœณ ๐ŸŽ‚ ๐Ÿ› ๏ธ โœ ๐Ÿ—œ ๐Ÿงฐ ๐Ÿ— ๐Ÿ•ธ ๐Ÿ”— โš™๏ธ โœณ ๐Ÿ”˜, ๐Ÿ“‰ ๐Ÿšฎ ๐Ÿ› ๏ธ ๐Ÿ› ๏ธ.
โšซ๏ธ โš™๏ธ ๐Ÿ“š ๐Ÿข โœ… ๐ŸฆŽ, ๐ŸŸฅ ๐Ÿ‘’ &amp; ๐ŸŽŸ.
โšซ๏ธ ๐Ÿ• ๐Ÿฅ‡ ๐Ÿ–ผ **๐Ÿง ๐Ÿ› ๏ธ ๐Ÿงพ**, &amp; ๐Ÿ‘‰ ๐ŸŽฏ ๐Ÿ• ๐Ÿฅ‡ ๐Ÿ’ญ ๐Ÿ‘ˆ ๐Ÿ˜ฎ "๐Ÿ”Ž" **FastAPI**.
!!! note
โœณ ๐ŸŽ‚ ๐Ÿ› ๏ธ โœ โœก ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ›. ๐ŸŽ ๐Ÿ‘ผ ๐Ÿ’ƒ &amp; Uvicorn, ๐Ÿ”› โ” **FastAPI** โš“๏ธ.
!!! check "๐Ÿ˜ฎ **FastAPI** "
โœ”๏ธ ๐Ÿง ๐Ÿ› ๏ธ ๐Ÿงพ ๐Ÿ•ธ ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ”ข.
### <a href="https://flask.palletsprojects.com" class="external-link" target="_blank">๐Ÿบ</a>
๐Ÿบ "๐Ÿ•ธ", โšซ๏ธ ๐Ÿšซ ๐Ÿ”Œ ๐Ÿ’ฝ ๐Ÿ› ๏ธ ๐Ÿšซ ๐Ÿ“š ๐Ÿ‘œ ๐Ÿ‘ˆ ๐Ÿ‘Ÿ ๐Ÿ”ข โœณ.
๐Ÿ‘‰ ๐Ÿฆ &amp; ๐Ÿ’ช โœ” ๐Ÿ”จ ๐Ÿ‘œ ๐Ÿ’– โš™๏ธ โ˜ ๐Ÿ’ฝ ๐Ÿ‘‘ ๐Ÿ’ฝ ๐Ÿ’พ โš™๏ธ.
โšซ๏ธ ๐Ÿ“ถ ๐Ÿ™…, โšซ๏ธ ๐Ÿ“ถ ๐Ÿ‹๏ธ ๐Ÿ’ก, ๐Ÿ‘ ๐Ÿงพ ๐Ÿคš ๐Ÿ™ ๐Ÿ“ก โ˜.
โšซ๏ธ ๐Ÿ›Ž โš™๏ธ ๐ŸŽ ๐Ÿˆธ ๐Ÿ‘ˆ ๐Ÿšซ ๐ŸŽฏ ๐Ÿ’ช ๐Ÿ’ฝ, ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿงพ, โš–๏ธ ๐Ÿ™† ๐Ÿ“š โš’ ๐Ÿ‘ˆ ๐Ÿ‘Ÿ ๐Ÿค-๐Ÿ— โœณ. ๐Ÿ‘ ๐Ÿ“š ๐Ÿ‘ซ โš’ ๐Ÿ’ช ๐Ÿšฎ โฎ๏ธ ๐Ÿ”Œ-๐Ÿ”Œ.
๐Ÿ‘‰ โš– ๐Ÿ•, &amp; โž– "๐Ÿ•ธ" ๐Ÿ‘ˆ ๐Ÿ’ช โ†” ๐Ÿ“” โšซ๏ธโ” โšซ๏ธโ” ๐Ÿ’ช ๐Ÿ”‘ โš’ ๐Ÿ‘ˆ ๐Ÿ‘ค ๐Ÿ’š ๐Ÿšง.
๐Ÿ‘ ๐Ÿฆ ๐Ÿบ, โšซ๏ธ ๐Ÿ˜‘ ๐Ÿ’– ๐Ÿ‘ ๐Ÿ ๐Ÿ— ๐Ÿ”—. โญ ๐Ÿ‘œ ๐Ÿ”Ž "โœณ ๐ŸŽ‚ ๐Ÿ› ๏ธ" ๐Ÿบ.
!!! check "๐Ÿ˜ฎ **FastAPI** "
โ—พ-๐Ÿ› ๏ธ. โš’ โšซ๏ธ โฉ ๐ŸŒ€ &amp; ๐Ÿ ๐Ÿงฐ &amp; ๐Ÿ• ๐Ÿ’ช.
โœ”๏ธ ๐Ÿ™… &amp; โฉ โš™๏ธ ๐Ÿ•น โš™๏ธ.
### <a href="https://requests.readthedocs.io" class="external-link" target="_blank">๐Ÿ“จ</a>
**FastAPI** ๐Ÿšซ ๐Ÿค™ ๐ŸŽ› **๐Ÿ“จ**. ๐Ÿ‘ซ โ†” ๐Ÿ“ถ ๐ŸŽ.
โšซ๏ธ ๐Ÿ”œ ๐Ÿค™ โš  โš™๏ธ ๐Ÿ“จ *๐Ÿ”˜* FastAPI ๐Ÿˆธ.
โœ‹๏ธ, FastAPI ๐Ÿคš ๐ŸŒˆ โšช๏ธโžก๏ธ ๐Ÿ“จ.
**๐Ÿ“จ** ๐Ÿ—ƒ *๐Ÿ”—* โฎ๏ธ ๐Ÿ”— (๐Ÿ‘ฉโ€๐Ÿ’ป), โช **FastAPI** ๐Ÿ—ƒ *๐Ÿ—* ๐Ÿ”— (๐Ÿ’ฝ).
๐Ÿ‘ซ, ๐ŸŒ– โš–๏ธ ๐ŸŒ˜, ๐Ÿ”„ ๐Ÿ”š, ๐Ÿ”— ๐Ÿ”  ๐ŸŽ.
๐Ÿ“จ โœ”๏ธ ๐Ÿ“ถ ๐Ÿ™… &amp; ๐Ÿ‹๏ธ ๐Ÿ”ง, โšซ๏ธ ๐Ÿ“ถ โฉ โš™๏ธ, โฎ๏ธ ๐Ÿค” ๐Ÿ”ข. โœ‹๏ธ ๐ŸŽ ๐Ÿ•ฐ, โšซ๏ธ ๐Ÿ“ถ ๐Ÿ‹๏ธ &amp; ๐Ÿ›ƒ.
๐Ÿ‘ˆ โšซ๏ธโ”, ๐Ÿ’ฌ ๐Ÿ›‚ ๐Ÿ•ธ:
&gt; ๐Ÿ“จ 1๏ธโƒฃ ๐Ÿ† โฌ ๐Ÿ ๐Ÿ“ฆ ๐ŸŒ ๐Ÿ•ฐ
๐ŸŒŒ ๐Ÿ‘† โš™๏ธ โšซ๏ธ ๐Ÿ“ถ ๐Ÿ™…. ๐Ÿ–ผ, `GET` ๐Ÿ“จ, ๐Ÿ‘† ๐Ÿ”œ โœ:
```Python
response = requests.get("http://example.com/some/url")
```
FastAPI ๐Ÿ˜‘ ๐Ÿ› ๏ธ *โžก ๐Ÿ› ๏ธ* ๐Ÿ’ช ๐Ÿ‘€ ๐Ÿ’–:
```Python hl_lines="1"
@app.get("/some/url")
def read_url():
return {"message": "Hello World"}
```
๐Ÿ‘€ ๐Ÿ”€ `requests.get(...)` &amp; `@app.get(...)`.
!!! check "๐Ÿ˜ฎ **FastAPI** "
* โœ”๏ธ ๐Ÿ™… &amp; ๐Ÿ‹๏ธ ๐Ÿ› ๏ธ.
* โš™๏ธ ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ” ๐Ÿ‘ฉโ€๐Ÿ”ฌ ๐Ÿ“› (๐Ÿ› ๏ธ) ๐Ÿ”—, ๐ŸŽฏ &amp; ๐Ÿ‹๏ธ ๐ŸŒŒ.
* โœ”๏ธ ๐Ÿค” ๐Ÿ”ข, โœ‹๏ธ ๐Ÿ‹๏ธ ๐Ÿ›ƒ.
### <a href="https://swagger.io/" class="external-link" target="_blank">๐Ÿฆ</a> / <a href="https://github.com/OAI/OpenAPI-Specification/" class="external-link" target="_blank">๐Ÿ—„</a>
๐Ÿ‘‘ โš’ ๐Ÿ‘ค ๐Ÿ’š โšช๏ธโžก๏ธ โœณ ๐ŸŽ‚ ๐Ÿ› ๏ธ ๐Ÿง ๐Ÿ› ๏ธ ๐Ÿงพ.
โคด๏ธ ๐Ÿ‘ค ๐Ÿ”Ž ๐Ÿ‘ˆ ๐Ÿ“ค ๐Ÿฉ ๐Ÿ“„ ๐Ÿ”—, โš™๏ธ ๐ŸŽป (โš–๏ธ ๐Ÿ“, โ†” ๐ŸŽป) ๐Ÿค™ ๐Ÿฆ.
&amp; ๐Ÿ“ค ๐Ÿ•ธ ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ”ข ๐Ÿฆ ๐Ÿ› ๏ธ โช โœ. , ๐Ÿ’†โ€โ™‚ ๐Ÿ’ช ๐Ÿ— ๐Ÿฆ ๐Ÿงพ ๐Ÿ› ๏ธ ๐Ÿ”œ โœ” โš™๏ธ ๐Ÿ‘‰ ๐Ÿ•ธ ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ”ข ๐Ÿ”.
โ˜, ๐Ÿฆ ๐Ÿ‘ ๐Ÿ’พ ๐Ÿ›, ๐Ÿ“ ๐Ÿ—„.
๐Ÿ‘ˆ โšซ๏ธโ” ๐Ÿ•โ” ๐Ÿ’ฌ ๐Ÿ”ƒ โฌ 2๏ธโƒฃ.0๏ธโƒฃ โšซ๏ธ โš  ๐Ÿ’ฌ "๐Ÿฆ", &amp; โฌ 3๏ธโƒฃ โž• "๐Ÿ—„".
!!! check "๐Ÿ˜ฎ **FastAPI** "
๐Ÿ› ๏ธ &amp; โš™๏ธ ๐Ÿ“‚ ๐Ÿฉ ๐Ÿ› ๏ธ ๐Ÿ”ง, โ†ฉ๏ธ ๐Ÿ›ƒ ๐Ÿ”—.
&amp; ๐Ÿ› ๏ธ ๐Ÿฉ-โš“๏ธ ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ”ข ๐Ÿงฐ:
* <a href="https://github.com/swagger-api/swagger-ui" class="external-link" target="_blank">๐Ÿฆ ๐ŸŽš</a>
* <a href="https://github.com/Rebilly/ReDoc" class="external-link" target="_blank">๐Ÿ“„</a>
๐Ÿ‘ซ 2๏ธโƒฃ ๐Ÿ‘ โž– ๐Ÿ“ถ ๐ŸŒŸ &amp; โš–, โœ‹๏ธ ๐Ÿ”จ โฉ ๐Ÿ”Ž, ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ”Ž ๐Ÿ’ฏ ๐ŸŒ– ๐ŸŽ› ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ”ข ๐Ÿ—„ (๐Ÿ‘ˆ ๐Ÿ‘† ๐Ÿ’ช โš™๏ธ โฎ๏ธ **FastAPI**).
### ๐Ÿบ ๐ŸŽ‚ ๐Ÿ› ๏ธ
๐Ÿ“ค ๐Ÿ“š ๐Ÿบ ๐ŸŽ‚ ๐Ÿ› ๏ธ, โœ‹๏ธ โฎ๏ธ ๐Ÿ’ฐ ๐Ÿ•ฐ &amp; ๐Ÿ‘ท ๐Ÿ”˜ ๐Ÿ”ฌ ๐Ÿ‘ซ, ๐Ÿ‘ค ๐Ÿ”Ž ๐Ÿ‘ˆ ๐Ÿ“š ๐Ÿ˜ž โš–๏ธ ๐Ÿšซ, โฎ๏ธ ๐Ÿ“š ๐Ÿง โ” ๐Ÿ‘ˆ โš’ ๐Ÿ‘ซ ๐Ÿ™ƒ.
### <a href="https://marshmallow.readthedocs.io/en/stable/" class="external-link" target="_blank">๐Ÿญ</a>
1๏ธโƒฃ ๐Ÿ‘‘ โš’ ๐Ÿ’ช ๐Ÿ› ๏ธ โš™๏ธ ๐Ÿ“Š "<abbr title="also called marshalling, conversion">๐Ÿ› ๏ธ</abbr>" โ” โœŠ ๐Ÿ“Š โšช๏ธโžก๏ธ ๐Ÿ“Ÿ (๐Ÿ) &amp; ๐Ÿญ โšซ๏ธ ๐Ÿ”˜ ๐Ÿ•ณ ๐Ÿ‘ˆ ๐Ÿ’ช ๐Ÿ“จ ๐Ÿ”˜ ๐Ÿ•ธ. ๐Ÿ–ผ, ๐Ÿญ ๐ŸŽš โš— ๐Ÿ“Š โšช๏ธโžก๏ธ ๐Ÿ’ฝ ๐Ÿ”˜ ๐ŸŽป ๐ŸŽš. ๐Ÿญ `datetime` ๐ŸŽš ๐Ÿ”˜ ๐ŸŽป, โ™’๏ธ.
โž•1๏ธโƒฃ ๐Ÿฆ โš’ ๐Ÿ’š ๐Ÿ”— ๐Ÿ’ฝ ๐Ÿ”ฌ, โš’ ๐Ÿ’ญ ๐Ÿ‘ˆ ๐Ÿ’ฝ โ˜‘, ๐Ÿค ๐ŸŽฏ ๐Ÿ”ข. ๐Ÿ–ผ, ๐Ÿ‘ˆ ๐Ÿ‘ `int`, &amp; ๐Ÿšซ ๐ŸŽฒ ๐ŸŽป. ๐Ÿ‘‰ โœด๏ธ โš  ๐Ÿ“จ ๐Ÿ’ฝ.
๐Ÿต ๐Ÿ’ฝ ๐Ÿ”ฌ โš™๏ธ, ๐Ÿ‘† ๐Ÿ”œ โœ”๏ธ ๐ŸŒ โœ… โœ‹, ๐Ÿ“Ÿ.
๐Ÿ‘ซ โš’ โšซ๏ธโ” ๐Ÿญ ๐Ÿ— ๐Ÿšš. โšซ๏ธ ๐Ÿ‘‘ ๐Ÿ—ƒ, &amp; ๐Ÿ‘ค โœ”๏ธ โš™๏ธ โšซ๏ธ ๐Ÿ“š โญ.
โœ‹๏ธ โšซ๏ธ โœ โญ ๐Ÿ“ค ๐Ÿ”€ ๐Ÿ ๐Ÿ†Ž ๐Ÿ”‘. , ๐Ÿ”ฌ ๐Ÿ”  <abbr title="the definition of how data should be formed">๐Ÿ”—</abbr> ๐Ÿ‘† ๐Ÿ’ช โš™๏ธ ๐ŸŽฏ ๐Ÿ‡จ๐Ÿ‡ป &amp; ๐ŸŽ“ ๐Ÿšš ๐Ÿญ.
!!! check "๐Ÿ˜ฎ **FastAPI** "
โš™๏ธ ๐Ÿ“Ÿ ๐Ÿ”ฌ "๐Ÿ”—" ๐Ÿ‘ˆ ๐Ÿšš ๐Ÿ’ฝ ๐Ÿ†Ž &amp; ๐Ÿ”ฌ, ๐Ÿ”.
### <a href="https://webargs.readthedocs.io/en/latest/" class="external-link" target="_blank">Webarg</a>
โž•1๏ธโƒฃ ๐Ÿฆ โš’ โœ” ๐Ÿ”— <abbr title="reading and converting to Python data">โœ</abbr> ๐Ÿ“Š โšช๏ธโžก๏ธ ๐Ÿ“จ ๐Ÿ“จ.
Webarg ๐Ÿงฐ ๐Ÿ‘ˆ โš’ ๐Ÿšš ๐Ÿ‘ˆ ๐Ÿ”› ๐Ÿ” ๐Ÿ“š ๐Ÿ› ๏ธ, ๐Ÿ”Œ ๐Ÿบ.
โšซ๏ธ โš™๏ธ ๐Ÿญ ๐Ÿ”˜ ๐Ÿ’ฝ ๐Ÿ”ฌ. &amp; โšซ๏ธ โœ ๐ŸŽ ๐Ÿ‘ฉโ€๐Ÿ’ป.
โšซ๏ธ ๐Ÿ‘‘ ๐Ÿงฐ &amp; ๐Ÿ‘ค โœ”๏ธ โš™๏ธ โšซ๏ธ ๐Ÿ“š ๐Ÿ’โ€โ™‚๏ธ, โญ โœ”๏ธ **FastAPI**.
!!! info
Webarg โœ ๐ŸŽ ๐Ÿญ ๐Ÿ‘ฉโ€๐Ÿ’ป.
!!! check "๐Ÿ˜ฎ **FastAPI** "
โœ”๏ธ ๐Ÿง ๐Ÿ”ฌ ๐Ÿ“จ ๐Ÿ“จ ๐Ÿ’ฝ.
### <a href="https://apispec.readthedocs.io/en/stable/" class="external-link" target="_blank">APISpec</a>
๐Ÿญ &amp; Webarg ๐Ÿšš ๐Ÿ”ฌ, โœ &amp; ๐Ÿ› ๏ธ ๐Ÿ”Œ-๐Ÿ”Œ.
โœ‹๏ธ ๐Ÿงพ โŒ. โคด๏ธ APISpec โœ.
โšซ๏ธ ๐Ÿ”Œ-๐Ÿ“š ๐Ÿ› ๏ธ (&amp; ๐Ÿ“ค ๐Ÿ”Œ-๐Ÿ’ƒ ๐Ÿ’โ€โ™‚๏ธ).
๐ŸŒŒ โšซ๏ธ ๐Ÿ‘ท ๐Ÿ‘ˆ ๐Ÿ‘† โœ ๐Ÿ”‘ ๐Ÿ”— โš™๏ธ ๐Ÿ“ ๐Ÿ“ ๐Ÿ”˜ #๏ธโƒฃ ๐Ÿ”  ๐Ÿ”ข ๐Ÿšš ๐Ÿ›ฃ.
&amp; โšซ๏ธ ๐Ÿ— ๐Ÿ—„ ๐Ÿ”—.
๐Ÿ‘ˆ โ” โšซ๏ธ ๐Ÿ‘ท ๐Ÿบ, ๐Ÿ’ƒ, ๐Ÿ†˜, โ™’๏ธ.
โœ‹๏ธ โคด๏ธ, ๐Ÿ‘ฅ โœ”๏ธ ๐Ÿ”„ โš  โœ”๏ธ โ—พ-โ•, ๐Ÿ”˜ ๐Ÿ ๐ŸŽป (๐Ÿฆ ๐Ÿ“).
๐Ÿ‘จโ€๐ŸŽจ ๐Ÿ’ช ๐Ÿšซ โ„น ๐ŸŒ… โฎ๏ธ ๐Ÿ‘ˆ. &amp; ๐Ÿšฅ ๐Ÿ‘ฅ ๐Ÿ”€ ๐Ÿ”ข โš–๏ธ ๐Ÿญ ๐Ÿ”— &amp; ๐Ÿ’ญ ๐Ÿ”€ ๐Ÿ‘ˆ ๐Ÿ“#๏ธโƒฃ, ๐Ÿ— ๐Ÿ”— ๐Ÿ”œ โŒ.
!!! info
APISpec โœ ๐ŸŽ ๐Ÿญ ๐Ÿ‘ฉโ€๐Ÿ’ป.
!!! check "๐Ÿ˜ฎ **FastAPI** "
๐Ÿ•โ€๐Ÿฆบ ๐Ÿ“‚ ๐Ÿฉ ๐Ÿ› ๏ธ, ๐Ÿ—„.
### <a href="https://flask-apispec.readthedocs.io/en/latest/" class="external-link" target="_blank">๐Ÿบ-Apispec</a>
โšซ๏ธ ๐Ÿบ ๐Ÿ”Œ -, ๐Ÿ‘ˆ ๐Ÿ‘” ๐Ÿ‘ฏโ€โ™‚๏ธ Webarg, ๐Ÿญ &amp; APISpec.
โšซ๏ธ โš™๏ธ โ„น โšช๏ธโžก๏ธ Webarg &amp; ๐Ÿญ ๐Ÿ” ๐Ÿ— ๐Ÿ—„ ๐Ÿ”—, โš™๏ธ APISpec.
โšซ๏ธ ๐Ÿ‘‘ ๐Ÿงฐ, ๐Ÿ“ถ ๐Ÿ”ฝ-๐Ÿ“ˆ. โšซ๏ธ ๐Ÿ”œ ๐ŸŒŒ ๐ŸŒ– ๐ŸŒŸ ๐ŸŒ˜ ๐Ÿ“š ๐Ÿบ ๐Ÿ”Œ-๐Ÿ”Œ ๐Ÿ‘… ๐Ÿ“ค. โšซ๏ธ ๐Ÿ’ช โ†ฉ๏ธ ๐Ÿšฎ ๐Ÿงพ โž– ๐Ÿ’โ€โ™‚๏ธ ๐Ÿฉฒ &amp; ๐Ÿ“.
๐Ÿ‘‰ โŽ โœ”๏ธ โœ ๐Ÿ“ (โž•1๏ธโƒฃ โ•) ๐Ÿ”˜ ๐Ÿ โœ.
๐Ÿ‘‰ ๐ŸŒ€ ๐Ÿบ, ๐Ÿบ-Apispec โฎ๏ธ ๐Ÿญ &amp; Webarg ๐Ÿ‘‡ ๐Ÿ’• ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ“š โญ ๐Ÿ— **FastAPI**.
โš™๏ธ โšซ๏ธ โ†˜๏ธ ๐Ÿ— ๐Ÿ“š ๐Ÿบ ๐ŸŒ•-๐Ÿ“š ๐Ÿš‚. ๐Ÿ‘ซ ๐Ÿ‘‘ ๐Ÿ“š ๐Ÿ‘ค (&amp; ๐Ÿ“š ๐Ÿ”ข ๐Ÿ‰) โœ”๏ธ โš™๏ธ ๐Ÿ†™ ๐Ÿ”œ:
* <a href="https://github.com/tiangolo/full-stack" class="external-link" target="_blank">https://github.com/tiangolo/full-stack</a>
* <a href="https://github.com/tiangolo/full-stack-flask-couchbase" class="external-link" target="_blank">https://github.com/tiangolo/full-stack-flask-couchbase</a>
* <a href="https://github.com/tiangolo/full-stack-flask-couchdb" class="external-link" target="_blank">https://github.com/tiangolo/full-stack-flask-couchdb</a>
&amp; ๐Ÿ‘ซ ๐ŸŽ ๐ŸŒ•-๐Ÿ“š ๐Ÿš‚ ๐Ÿงข [**FastAPI** ๐Ÿ— ๐Ÿš‚](project-generation.md){.internal-link target=_blank}.
!!! info
๐Ÿบ-Apispec โœ ๐ŸŽ ๐Ÿญ ๐Ÿ‘ฉโ€๐Ÿ’ป.
!!! check "๐Ÿ˜ฎ **FastAPI** "
๐Ÿ— ๐Ÿ—„ ๐Ÿ”— ๐Ÿ”, โšช๏ธโžก๏ธ ๐ŸŽ ๐Ÿ“Ÿ ๐Ÿ‘ˆ ๐Ÿ”ฌ ๐Ÿ› ๏ธ &amp; ๐Ÿ”ฌ.
### <a href="https://nestjs.com/" class="external-link" target="_blank">NestJS</a> (&amp; <a href="https://angular.io/" class="external-link" target="_blank">๐Ÿ“</a>)
๐Ÿ‘‰ โž–๐Ÿšซ ๐Ÿšซ ๐Ÿ, NestJS ๐Ÿ•ธ (๐Ÿ“•) โœณ ๐Ÿ› ๏ธ ๐Ÿ˜ฎ ๐Ÿ“.
โšซ๏ธ ๐Ÿ† ๐Ÿ•ณ ๐Ÿ™ ๐ŸŽ โšซ๏ธโ” ๐Ÿ’ช ๐Ÿ”จ โฎ๏ธ ๐Ÿบ-Apispec.
โšซ๏ธ โœ”๏ธ ๐Ÿ› ๏ธ ๐Ÿ”— ๐Ÿ’‰ โš™๏ธ, ๐Ÿ˜ฎ ๐Ÿ“ 2๏ธโƒฃ. โšซ๏ธ ๐Ÿšš ๐Ÿค-ยฎ "๐Ÿ’‰" (๐Ÿ’– ๐ŸŒ ๐ŸŽ ๐Ÿ”— ๐Ÿ’‰ โš™๏ธ ๐Ÿ‘ค ๐Ÿ’ญ),, โšซ๏ธ ๐Ÿšฎ ๐ŸŽญ &amp; ๐Ÿ“Ÿ ๐Ÿ”.
๐Ÿ”ข ๐Ÿ”ฌ โฎ๏ธ ๐Ÿ“• ๐Ÿ†Ž (๐ŸŽ ๐Ÿ ๐Ÿ†Ž ๐Ÿ”‘), ๐Ÿ‘จโ€๐ŸŽจ ๐Ÿ•โ€๐Ÿฆบ ๐Ÿ‘.
โœ‹๏ธ ๐Ÿ“• ๐Ÿ“Š ๐Ÿšซ ๐Ÿ›ก โฎ๏ธ ๐Ÿ“น ๐Ÿ•ธ, โšซ๏ธ ๐Ÿšซ๐Ÿ”œ โš“๏ธ ๐Ÿ”› ๐Ÿ†Ž ๐Ÿ”ฌ ๐Ÿ”ฌ, ๐Ÿ› ๏ธ &amp; ๐Ÿงพ ๐ŸŽ ๐Ÿ•ฐ. โ†ฉ๏ธ ๐Ÿ‘‰ &amp; ๐Ÿ”ง ๐Ÿšซ, ๐Ÿคš ๐Ÿ”ฌ, ๐Ÿ› ๏ธ &amp; ๐Ÿง ๐Ÿ”— โšก, โšซ๏ธ ๐Ÿ’ช ๐Ÿšฎ ๐Ÿ‘จโ€๐ŸŽจ ๐Ÿ“š ๐Ÿฅ‰. , โšซ๏ธ โ–ถ๏ธ๏ธ ๐Ÿ”.
โšซ๏ธ ๐Ÿ’ช ๐Ÿšซ ๐Ÿต ๐Ÿ” ๐Ÿท ๐Ÿ“ถ ๐Ÿ‘. , ๐Ÿšฅ ๐ŸŽป ๐Ÿ’ช ๐Ÿ“จ ๐ŸŽป ๐ŸŽš ๐Ÿ‘ˆ โœ”๏ธ ๐Ÿ”˜ ๐Ÿ‘ ๐Ÿ‘ˆ ๐Ÿ”„ ๐Ÿฆ ๐ŸŽป ๐ŸŽš, โšซ๏ธ ๐Ÿšซ๐Ÿ”œ โ˜‘ ๐Ÿ“„ &amp; โœ”.
!!! check "๐Ÿ˜ฎ **FastAPI** "
โš™๏ธ ๐Ÿ ๐Ÿ†Ž โœ”๏ธ ๐Ÿ‘‘ ๐Ÿ‘จโ€๐ŸŽจ ๐Ÿ•โ€๐Ÿฆบ.
โœ”๏ธ ๐Ÿ‹๏ธ ๐Ÿ”— ๐Ÿ’‰ โš™๏ธ. ๐Ÿ”Ž ๐ŸŒŒ ๐Ÿ“‰ ๐Ÿ“Ÿ ๐Ÿ”.
### <a href="https://sanic.readthedocs.io/en/latest/" class="external-link" target="_blank">๐Ÿคฃ</a>
โšซ๏ธ ๐Ÿ• ๐Ÿฅ‡ ๐Ÿ“ถ โฉ ๐Ÿ ๐Ÿ› ๏ธ โš“๏ธ ๐Ÿ”› `asyncio`. โšซ๏ธ โš’ ๐Ÿ“ถ ๐ŸŽ ๐Ÿบ.
!!! note "๐Ÿ“ก โ„น"
โšซ๏ธ โš™๏ธ <a href="https://github.com/MagicStack/uvloop" class="external-link" target="_blank">`uvloop`</a> โ†ฉ๏ธ ๐Ÿ”ข ๐Ÿ `asyncio` โžฐ. ๐Ÿ‘ˆ โšซ๏ธโ” โš’ โšซ๏ธ โฉ.
โšซ๏ธ ๐ŸŽฏ ๐Ÿ˜ฎ Uvicorn &amp; ๐Ÿ’ƒ, ๐Ÿ‘ˆ โณ โฉ ๐ŸŒ˜ ๐Ÿคฃ ๐Ÿ“‚ ๐Ÿ“‡.
!!! check "๐Ÿ˜ฎ **FastAPI** "
๐Ÿ”Ž ๐ŸŒŒ โœ”๏ธ ๐Ÿ˜œ ๐ŸŽญ.
๐Ÿ‘ˆ โšซ๏ธโ” **FastAPI** โš“๏ธ ๐Ÿ”› ๐Ÿ’ƒ, โšซ๏ธ โฉ ๐Ÿ› ๏ธ ๐Ÿ’ช (๐Ÿ’ฏ ๐Ÿฅ‰-๐Ÿฅณ ๐Ÿ“‡).
### <a href="https://falconframework.org/" class="external-link" target="_blank">๐Ÿฆ…</a>
๐Ÿฆ… โž•1๏ธโƒฃ โ†• ๐ŸŽญ ๐Ÿ ๐Ÿ› ๏ธ, โšซ๏ธ ๐Ÿ”ง โญ, &amp; ๐Ÿ‘ท ๐Ÿ› ๐ŸŽ ๐Ÿ› ๏ธ ๐Ÿ’– ๐Ÿค—.
โšซ๏ธ ๐Ÿ— โœ”๏ธ ๐Ÿ”ข ๐Ÿ‘ˆ ๐Ÿ“จ 2๏ธโƒฃ ๐Ÿ”ข, 1๏ธโƒฃ "๐Ÿ“จ" &amp; 1๏ธโƒฃ "๐Ÿ“จ". โคด๏ธ ๐Ÿ‘† "โœ" ๐Ÿ• โšช๏ธโžก๏ธ ๐Ÿ“จ, &amp; "โœ" ๐Ÿ• ๐Ÿ“จ. โ†ฉ๏ธ ๐Ÿ‘‰ ๐Ÿ”ง, โšซ๏ธ ๐Ÿšซ ๐Ÿ’ช ๐Ÿ“ฃ ๐Ÿ“จ ๐Ÿ”ข &amp; ๐Ÿ’ช โฎ๏ธ ๐Ÿฉ ๐Ÿ ๐Ÿ†Ž ๐Ÿ”‘ ๐Ÿ”ข ๐Ÿ”ข.
, ๐Ÿ’ฝ ๐Ÿ”ฌ, ๐Ÿ› ๏ธ, &amp; ๐Ÿงพ, โœ”๏ธ โŒ› ๐Ÿ“Ÿ, ๐Ÿšซ ๐Ÿ”. โš–๏ธ ๐Ÿ‘ซ โœ”๏ธ ๐Ÿ› ๏ธ ๐Ÿ› ๏ธ ๐Ÿ”› ๐Ÿ” ๐Ÿฆ…, ๐Ÿ’– ๐Ÿค—. ๐Ÿ‘‰ ๐ŸŽ ๐Ÿ”บ ๐Ÿ”จ ๐ŸŽ ๐Ÿ› ๏ธ ๐Ÿ‘ˆ ๐Ÿ˜ฎ ๐Ÿฆ… ๐Ÿ”ง, โœ”๏ธ 1๏ธโƒฃ ๐Ÿ“จ ๐ŸŽš &amp; 1๏ธโƒฃ ๐Ÿ“จ ๐ŸŽš ๐Ÿ”ข.
!!! check "๐Ÿ˜ฎ **FastAPI** "
๐Ÿ”Ž ๐ŸŒŒ ๐Ÿคš ๐Ÿ‘‘ ๐ŸŽญ.
โคด๏ธ โฎ๏ธ ๐Ÿค— (๐Ÿค— โš“๏ธ ๐Ÿ”› ๐Ÿฆ…) ๐Ÿ˜ฎ **FastAPI** ๐Ÿ“ฃ `response` ๐Ÿ”ข ๐Ÿ”ข.
๐Ÿ‘ FastAPI โšซ๏ธ ๐Ÿ“ฆ, &amp; โš™๏ธ โœด๏ธ โš’ ๐ŸŽš, ๐Ÿช, &amp; ๐ŸŽ› ๐Ÿ‘” ๐Ÿ“Ÿ.
### <a href="https://moltenframework.com/" class="external-link" target="_blank">โ™จ</a>
๐Ÿ‘ค ๐Ÿ”Ž โ™จ ๐Ÿฅ‡ โ–ถ๏ธ ๐Ÿ— **FastAPI**. &amp; โšซ๏ธ โœ”๏ธ ๐ŸŽ ๐Ÿ’ญ:
* โš“๏ธ ๐Ÿ”› ๐Ÿ ๐Ÿ†Ž ๐Ÿ”‘.
* ๐Ÿ”ฌ &amp; ๐Ÿงพ โšช๏ธโžก๏ธ ๐Ÿ‘ซ ๐Ÿ†Ž.
* ๐Ÿ”— ๐Ÿ’‰ โš™๏ธ.
โšซ๏ธ ๐Ÿšซ โš™๏ธ ๐Ÿ’ฝ ๐Ÿ”ฌ, ๐Ÿ› ๏ธ &amp; ๐Ÿงพ ๐Ÿฅ‰-๐Ÿฅณ ๐Ÿ—ƒ ๐Ÿ’– Pydantic, โšซ๏ธ โœ”๏ธ ๐Ÿšฎ ๐Ÿ‘. , ๐Ÿ‘ซ ๐Ÿ’ฝ ๐Ÿ†Ž ๐Ÿ”‘ ๐Ÿ”œ ๐Ÿšซ โ™ป ๐Ÿ’ช.
โšซ๏ธ ๐Ÿšš ๐Ÿฅ ๐Ÿ– ๐ŸŒ… ๐Ÿ” ๐Ÿ“ณ. &amp; โšซ๏ธ โš“๏ธ ๐Ÿ”› ๐Ÿ‡จ๐Ÿ‡ป (โ†ฉ๏ธ ๐Ÿ”ซ), โšซ๏ธ ๐Ÿšซ ๐Ÿ”ง โœŠ ๐Ÿ“ˆ โ†•-๐ŸŽญ ๐Ÿšš ๐Ÿงฐ ๐Ÿ’– Uvicorn, ๐Ÿ’ƒ &amp; ๐Ÿคฃ.
๐Ÿ”— ๐Ÿ’‰ โš™๏ธ ๐Ÿšš ๐Ÿค-ยฎ ๐Ÿ”— &amp; ๐Ÿ”— โŽ ๐Ÿงข ๐Ÿ”› ๐Ÿ“ฃ ๐Ÿ†Ž. , โšซ๏ธ ๐Ÿšซ ๐Ÿ’ช ๐Ÿ“ฃ ๐ŸŒ… ๐ŸŒ˜ 1๏ธโƒฃ "๐Ÿฆฒ" ๐Ÿ‘ˆ ๐Ÿšš ๐ŸŽฏ ๐Ÿ†Ž.
๐Ÿ›ฃ ๐Ÿ“ฃ ๐Ÿ‘ ๐Ÿฅ‰, โš™๏ธ ๐Ÿ”ข ๐Ÿ“ฃ ๐ŸŽ ๐Ÿฅ‰ (โ†ฉ๏ธ โš™๏ธ ๐Ÿ‘จโ€๐ŸŽจ ๐Ÿ‘ˆ ๐Ÿ’ช ๐Ÿฅ‰ โ–ถ๏ธ๏ธ ๐Ÿ”› ๐Ÿ” ๐Ÿ”ข ๐Ÿ‘ˆ ๐Ÿต ๐Ÿ”—). ๐Ÿ‘‰ ๐Ÿ” โ” โœณ ๐Ÿ”จ โšซ๏ธ ๐ŸŒ˜ โ” ๐Ÿบ (&amp; ๐Ÿ’ƒ) ๐Ÿ”จ โšซ๏ธ. โšซ๏ธ ๐ŸŽ ๐Ÿ“Ÿ ๐Ÿ‘œ ๐Ÿ‘ˆ ๐Ÿ“ถ ๐Ÿ˜† ๐Ÿ”—.
!!! check "๐Ÿ˜ฎ **FastAPI** "
๐Ÿ”ฌ โž• ๐Ÿ”ฌ ๐Ÿ’ฝ ๐Ÿ†Ž โš™๏ธ "๐Ÿ”ข" ๐Ÿ’ฒ ๐Ÿท ๐Ÿ”ข. ๐Ÿ‘‰ ๐Ÿ“‰ ๐Ÿ‘จโ€๐ŸŽจ ๐Ÿ•โ€๐Ÿฆบ, &amp; โšซ๏ธ ๐Ÿšซ ๐Ÿ’ช Pydantic โญ.
๐Ÿ‘‰ ๐Ÿค™ ๐Ÿ˜ฎ ๐Ÿ› ๏ธ ๐Ÿ• Pydantic, ๐Ÿ•โ€๐Ÿฆบ ๐ŸŽ ๐Ÿ”ฌ ๐Ÿ“„ ๐Ÿ‘— (๐ŸŒ ๐Ÿ‘‰ ๐Ÿ› ๏ธ ๐Ÿ”œ โช ๐Ÿ’ช Pydantic).
### <a href="https://www.hug.rest/" class="external-link" target="_blank">๐Ÿค—</a>
๐Ÿค— ๐Ÿ• ๐Ÿฅ‡ ๐Ÿ› ๏ธ ๐Ÿ› ๏ธ ๐Ÿ“„ ๐Ÿ› ๏ธ ๐Ÿ”ข ๐Ÿ†Ž โš™๏ธ ๐Ÿ ๐Ÿ†Ž ๐Ÿ”‘. ๐Ÿ‘‰ ๐Ÿ‘‘ ๐Ÿ’ญ ๐Ÿ‘ˆ ๐Ÿ˜ฎ ๐ŸŽ ๐Ÿงฐ ๐ŸŽ.
โšซ๏ธ โš™๏ธ ๐Ÿ›ƒ ๐Ÿ†Ž ๐Ÿšฎ ๐Ÿ“„ โ†ฉ๏ธ ๐Ÿฉ ๐Ÿ ๐Ÿ†Ž, โœ‹๏ธ โšซ๏ธ ๐Ÿฆ ๐Ÿ” โฉ.
โšซ๏ธ ๐Ÿ• ๐Ÿฅ‡ ๐Ÿ› ๏ธ ๐Ÿ— ๐Ÿ›ƒ ๐Ÿ”— ๐Ÿ“ฃ ๐ŸŽ‚ ๐Ÿ› ๏ธ ๐ŸŽป.
โšซ๏ธ ๐Ÿšซ โš“๏ธ ๐Ÿ”› ๐Ÿฉ ๐Ÿ’– ๐Ÿ—„ &amp; ๐ŸŽป ๐Ÿ”—. โšซ๏ธ ๐Ÿšซ๐Ÿ”œ ๐ŸŽฏ ๐Ÿ› ๏ธ โšซ๏ธ โฎ๏ธ ๐ŸŽ ๐Ÿงฐ, ๐Ÿ’– ๐Ÿฆ ๐ŸŽš. โœ‹๏ธ ๐Ÿ”„, โšซ๏ธ ๐Ÿ“ถ ๐Ÿ’ก ๐Ÿ’ญ.
โšซ๏ธ โœ”๏ธ ๐Ÿ˜Œ, โญ โš’: โš™๏ธ ๐ŸŽ ๐Ÿ› ๏ธ, โšซ๏ธ ๐Ÿ’ช โœ ๐Ÿ”— &amp; ๐Ÿ‡ณ๐Ÿ‡จ.
โšซ๏ธ โš“๏ธ ๐Ÿ”› โฎ๏ธ ๐Ÿฉ ๐Ÿ” ๐Ÿ ๐Ÿ•ธ ๐Ÿ› ๏ธ (๐Ÿ‡จ๐Ÿ‡ป), โšซ๏ธ ๐Ÿ’ช ๐Ÿšซ ๐Ÿต *๏ธโƒฃ &amp; ๐ŸŽ ๐Ÿ‘œ, ๐Ÿ‘ โšซ๏ธ โœ”๏ธ โ†• ๐ŸŽญ ๐Ÿ’โ€โ™‚๏ธ.
!!! info
๐Ÿค— โœ โœก ๐Ÿ—„, ๐ŸŽ ๐Ÿ‘ผ <a href="https://github.com/timothycrosley/isort" class="external-link" target="_blank">`isort`</a>, ๐Ÿ‘‘ ๐Ÿงฐ ๐Ÿ” ๐Ÿ˜‡ ๐Ÿ—„ ๐Ÿ ๐Ÿ“.
!!! check "๐Ÿ’ญ ๐Ÿ˜ฎ **FastAPI**"
๐Ÿค— ๐Ÿ˜ฎ ๐Ÿ• APIStar, &amp; 1๏ธโƒฃ ๐Ÿงฐ ๐Ÿ‘ค ๐Ÿ”Ž ๐Ÿ† ๐Ÿ‘, ๐ŸŒŸ APIStar.
๐Ÿค— โ„น ๐Ÿ˜ **FastAPI** โš™๏ธ ๐Ÿ ๐Ÿ†Ž ๐Ÿ”‘ ๐Ÿ“ฃ ๐Ÿ”ข, &amp; ๐Ÿ— ๐Ÿ”— โš– ๐Ÿ› ๏ธ ๐Ÿ”.
๐Ÿค— ๐Ÿ˜ฎ **FastAPI** ๐Ÿ“ฃ `response` ๐Ÿ”ข ๐Ÿ”ข โš’ ๐ŸŽš &amp; ๐Ÿช.
### <a href="https://github.com/encode/apistar" class="external-link" target="_blank">APIStar</a> (&lt;= 0๏ธโƒฃ.5๏ธโƒฃ)
โ–ถ๏ธ๏ธ โญ ๐Ÿค” ๐Ÿ— **FastAPI** ๐Ÿ‘ค ๐Ÿ”Ž **APIStar** ๐Ÿ’ฝ. โšซ๏ธ โœ”๏ธ ๐ŸŒ– ๐ŸŒ ๐Ÿ‘ค ๐Ÿ‘€ &amp; โœ”๏ธ ๐Ÿ‘‘ ๐Ÿ”ง.
โšซ๏ธ ๐Ÿ• ๐Ÿฅ‡ ๐Ÿ› ๏ธ ๐Ÿ› ๏ธ โš™๏ธ ๐Ÿ ๐Ÿ†Ž ๐Ÿ”‘ ๐Ÿ“ฃ ๐Ÿ”ข &amp; ๐Ÿ“จ ๐Ÿ‘ˆ ๐Ÿ‘ค โฑ ๐Ÿ‘€ (โญ NestJS &amp; โ™จ). ๐Ÿ‘ค ๐Ÿ”Ž โšซ๏ธ ๐ŸŒ… โš–๏ธ ๐ŸŒ˜ ๐ŸŽ ๐Ÿ•ฐ ๐Ÿค—. โœ‹๏ธ APIStar โš™๏ธ ๐Ÿ—„ ๐Ÿฉ.
โšซ๏ธ โœ”๏ธ ๐Ÿง ๐Ÿ’ฝ ๐Ÿ”ฌ, ๐Ÿ’ฝ ๐Ÿ› ๏ธ &amp; ๐Ÿ—„ ๐Ÿ”— โšก โš“๏ธ ๐Ÿ”› ๐ŸŽ ๐Ÿ†Ž ๐Ÿ”‘ ๐Ÿ“š ๐Ÿฅ‰.
๐Ÿ’ช ๐Ÿ”— ๐Ÿ”‘ ๐Ÿšซ โš™๏ธ ๐ŸŽ ๐Ÿ ๐Ÿ†Ž ๐Ÿ”‘ ๐Ÿ’– Pydantic, โšซ๏ธ ๐Ÿ– ๐ŸŒ… ๐ŸŽ ๐Ÿญ,, ๐Ÿ‘จโ€๐ŸŽจ ๐Ÿ•โ€๐Ÿฆบ ๐Ÿšซ๐Ÿ”œ ๐Ÿ‘, โœ‹๏ธ, APIStar ๐Ÿ† ๐Ÿ’ช ๐ŸŽ›.
โšซ๏ธ โœ”๏ธ ๐Ÿ† ๐ŸŽญ ๐Ÿ“‡ ๐Ÿ•ฐ (๐Ÿ•ด ๐Ÿ’ฅ ๐Ÿ’ƒ).
๐Ÿฅ‡, โšซ๏ธ ๐Ÿšซ โœ”๏ธ ๐Ÿง ๐Ÿ› ๏ธ ๐Ÿงพ ๐Ÿ•ธ ๐ŸŽš, โœ‹๏ธ ๐Ÿ‘ค ๐Ÿ’ญ ๐Ÿ‘ค ๐Ÿ’ช ๐Ÿšฎ ๐Ÿฆ ๐ŸŽš โšซ๏ธ.
โšซ๏ธ โœ”๏ธ ๐Ÿ”— ๐Ÿ’‰ โš™๏ธ. โšซ๏ธ โœ” ๐Ÿค-ยฎ ๐Ÿฆฒ, ๐ŸŽ ๐Ÿงฐ ๐Ÿ”ฌ ๐Ÿ”›. โœ‹๏ธ, โšซ๏ธ ๐Ÿ‘‘ โš’.
๐Ÿ‘ค ๐Ÿ™… ๐Ÿ’ช โš™๏ธ โšซ๏ธ ๐ŸŒ• ๐Ÿ—, โšซ๏ธ ๐Ÿšซ โœ”๏ธ ๐Ÿ’‚โ€โ™‚ ๐Ÿ› ๏ธ,, ๐Ÿ‘ค ๐Ÿšซ ๐Ÿšซ โŽ ๐ŸŒ โš’ ๐Ÿ‘ค โœ”๏ธ โฎ๏ธ ๐ŸŒ•-๐Ÿ“š ๐Ÿš‚ โš“๏ธ ๐Ÿ”› ๐Ÿบ-Apispec. ๐Ÿ‘ค โœ”๏ธ ๐Ÿ‘‡ ๐Ÿ“ˆ ๐Ÿ— โœ ๐Ÿšฒ ๐Ÿ“จ โŽ ๐Ÿ‘ˆ ๐Ÿ› ๏ธ.
โœ‹๏ธ โคด๏ธ, ๐Ÿ— ๐ŸŽฏ ๐Ÿ”€.
โšซ๏ธ ๐Ÿ™…โ€โ™‚ ๐Ÿ“ ๐Ÿ› ๏ธ ๐Ÿ•ธ ๐Ÿ› ๏ธ, ๐Ÿ‘ผ ๐Ÿ’ช ๐ŸŽฏ ๐Ÿ”› ๐Ÿ’ƒ.
๐Ÿ”œ APIStar โš’ ๐Ÿงฐ โœ” ๐Ÿ—„ ๐Ÿ”ง, ๐Ÿšซ ๐Ÿ•ธ ๐Ÿ› ๏ธ.
!!! info
APIStar โœ โœก ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ›. ๐ŸŽ ๐Ÿ‘จ ๐Ÿ‘ˆ โœ:
* โœณ ๐ŸŽ‚ ๐Ÿ› ๏ธ
* ๐Ÿ’ƒ (โ” **FastAPI** โš“๏ธ)
* Uvicorn (โš™๏ธ ๐Ÿ’ƒ &amp; **FastAPI**)
!!! check "๐Ÿ˜ฎ **FastAPI** "
๐Ÿ”€.
๐Ÿ’ญ ๐Ÿ“ฃ ๐Ÿ’— ๐Ÿ‘œ (๐Ÿ’ฝ ๐Ÿ”ฌ, ๐Ÿ› ๏ธ &amp; ๐Ÿงพ) โฎ๏ธ ๐ŸŽ ๐Ÿ ๐Ÿ†Ž, ๐Ÿ‘ˆ ๐ŸŽ ๐Ÿ•ฐ ๐Ÿšš ๐Ÿ‘‘ ๐Ÿ‘จโ€๐ŸŽจ ๐Ÿ•โ€๐Ÿฆบ, ๐Ÿ•ณ ๐Ÿ‘ค ๐Ÿค” ๐Ÿ’Ž ๐Ÿ’ญ.
&amp; โฎ๏ธ ๐Ÿ”Ž ๐Ÿ“ ๐Ÿ•ฐ ๐ŸŽ ๐Ÿ› ๏ธ &amp; ๐Ÿ”ฌ ๐Ÿ“š ๐ŸŽ ๐ŸŽ›, APIStar ๐Ÿ† ๐ŸŽ› ๐Ÿ’ช.
โคด๏ธ APIStar โ›”๏ธ ๐Ÿ”€ ๐Ÿ’ฝ &amp; ๐Ÿ’ƒ โœ, &amp; ๐Ÿ†• ๐Ÿ‘ป ๐Ÿ› โœ… โš™๏ธ. ๐Ÿ‘ˆ ๐Ÿ ๐ŸŒˆ ๐Ÿ— **FastAPI**.
๐Ÿ‘ค ๐Ÿค” **FastAPI** "๐Ÿ› ๐Ÿ‘จโ€๐Ÿ’ผ" APIStar, โช ๐Ÿ“‰ &amp; ๐Ÿ“ˆ โš’, โŒจ โš™๏ธ, &amp; ๐ŸŽ ๐Ÿ•, โš“๏ธ ๐Ÿ”› ๐Ÿซ โšช๏ธโžก๏ธ ๐ŸŒ ๐Ÿ‘‰ โฎ๏ธ ๐Ÿงฐ.
## โš™๏ธ **FastAPI**
### <a href="https://pydantic-docs.helpmanual.io/" class="external-link" target="_blank">Pydantic</a>
Pydantic ๐Ÿ—ƒ ๐Ÿ”ฌ ๐Ÿ’ฝ ๐Ÿ”ฌ, ๐Ÿ› ๏ธ &amp; ๐Ÿงพ (โš™๏ธ ๐ŸŽป ๐Ÿ”—) โš“๏ธ ๐Ÿ”› ๐Ÿ ๐Ÿ†Ž ๐Ÿ”‘.
๐Ÿ‘ˆ โš’ โšซ๏ธ ๐Ÿ“ถ ๐Ÿ‹๏ธ.
โšซ๏ธ โญ ๐Ÿญ. ๐Ÿ‘ โšซ๏ธ โฉ ๐ŸŒ˜ ๐Ÿญ ๐Ÿ“‡. &amp; โšซ๏ธ โš“๏ธ ๐Ÿ”› ๐ŸŽ ๐Ÿ ๐Ÿ†Ž ๐Ÿ”‘, ๐Ÿ‘จโ€๐ŸŽจ ๐Ÿ•โ€๐Ÿฆบ ๐Ÿ‘‘.
!!! check "**FastAPI** โš™๏ธ โšซ๏ธ"
๐Ÿต ๐ŸŒ ๐Ÿ’ฝ ๐Ÿ”ฌ, ๐Ÿ’ฝ ๐Ÿ› ๏ธ &amp; ๐Ÿง ๐Ÿท ๐Ÿงพ (โš“๏ธ ๐Ÿ”› ๐ŸŽป ๐Ÿ”—).
**FastAPI** โคด๏ธ โœŠ ๐Ÿ‘ˆ ๐ŸŽป ๐Ÿ”— ๐Ÿ’ฝ &amp; ๐Ÿšฎ โšซ๏ธ ๐Ÿ—„, โ†–๏ธ โšช๏ธโžก๏ธ ๐ŸŒ ๐ŸŽ ๐Ÿ‘œ โšซ๏ธ ๐Ÿ”จ.
### <a href="https://www.starlette.io/" class="external-link" target="_blank">๐Ÿ’ƒ</a>
๐Ÿ’ƒ ๐Ÿ’ฟ <abbr title="The new standard for building asynchronous Python web">๐Ÿ”ซ</abbr> ๐Ÿ› ๏ธ/๐Ÿงฐ, โ” ๐Ÿ’ฏ ๐Ÿ— โ†•-๐ŸŽญ โœณ ๐Ÿ•โ€๐Ÿฆบ.
โšซ๏ธ ๐Ÿ“ถ ๐Ÿ™… &amp; ๐Ÿ‹๏ธ. โšซ๏ธ ๐Ÿ”ง ๐Ÿ’ช ๐Ÿง, &amp; โœ”๏ธ ๐Ÿ”ง ๐Ÿฆฒ.
โšซ๏ธ โœ”๏ธ:
* ๐Ÿค™ ๐ŸŽ† ๐ŸŽญ.
* *๏ธโƒฃ ๐Ÿ•โ€๐Ÿฆบ.
* -๐Ÿ› ๏ธ ๐Ÿ–ฅ ๐Ÿ“‹.
* ๐Ÿ•ด &amp; ๐Ÿคซ ๐ŸŽ‰.
* ๐Ÿ’ฏ ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ— ๐Ÿ”› ๐Ÿ‡ธ๐Ÿ‡ฒ.
* โšœ, ๐Ÿ—œ, ๐ŸŽป ๐Ÿ“, ๐ŸŽ ๐Ÿ“จ.
* ๐ŸŽ‰ &amp; ๐Ÿช ๐Ÿ•โ€๐Ÿฆบ.
* 1๏ธโƒฃ0๏ธโƒฃ0๏ธโƒฃ ๐Ÿ’ฏ ๐Ÿ’ฏ ๐Ÿ’ฐ.
* 1๏ธโƒฃ0๏ธโƒฃ0๏ธโƒฃ ๐Ÿ’ฏ ๐Ÿ†Ž โœ โœ.
* ๐Ÿ‘ฉโ€โคโ€๐Ÿ‘จ ๐Ÿ‹๏ธ ๐Ÿ”—.
๐Ÿ’ƒ โณ โฉ ๐Ÿ ๐Ÿ› ๏ธ ๐Ÿ’ฏ. ๐Ÿ•ด ๐Ÿ’ฅ Uvicorn, โ” ๐Ÿšซ ๐Ÿ› ๏ธ, โœ‹๏ธ ๐Ÿ’ฝ.
๐Ÿ’ƒ ๐Ÿšš ๐ŸŒ ๐Ÿ”ฐ ๐Ÿ•ธ ๐Ÿ•ธ ๐Ÿ› ๏ธ.
โœ‹๏ธ โšซ๏ธ ๐Ÿšซ ๐Ÿšš ๐Ÿง ๐Ÿ’ฝ ๐Ÿ”ฌ, ๐Ÿ› ๏ธ โš–๏ธ ๐Ÿงพ.
๐Ÿ‘ˆ 1๏ธโƒฃ ๐Ÿ‘‘ ๐Ÿ‘œ ๐Ÿ‘ˆ **FastAPI** ๐Ÿšฎ ๐Ÿ”› ๐Ÿ”, ๐ŸŒ โš“๏ธ ๐Ÿ”› ๐Ÿ ๐Ÿ†Ž ๐Ÿ”‘ (โš™๏ธ Pydantic). ๐Ÿ‘ˆ, โž• ๐Ÿ”— ๐Ÿ’‰ โš™๏ธ, ๐Ÿ’‚โ€โ™‚ ๐Ÿš™, ๐Ÿ—„ ๐Ÿ”— โšก, โ™’๏ธ.
!!! note "๐Ÿ“ก โ„น"
๐Ÿ”ซ ๐Ÿ†• "๐Ÿฉ" โž– ๐Ÿ› ๏ธ โœณ ๐Ÿš ๐Ÿ‰ ๐Ÿ‘จโ€๐ŸŽ“. โšซ๏ธ ๐Ÿšซ "๐Ÿ ๐Ÿฉ" (๐Ÿ‡ฉ๐Ÿ‡ฌ), ๐Ÿ‘ ๐Ÿ‘ซ ๐Ÿ› ๏ธ ๐Ÿ”จ ๐Ÿ‘ˆ.
๐Ÿ‘, โšซ๏ธ โช โž– โš™๏ธ "๐Ÿฉ" ๐Ÿ“š ๐Ÿงฐ. ๐Ÿ‘‰ ๐Ÿ“‰ ๐Ÿ“‰ ๐Ÿ› ๏ธ, ๐Ÿ‘† ๐Ÿ’ช ๐ŸŽ› Uvicorn ๐Ÿ™† ๐ŸŽ ๐Ÿ”ซ ๐Ÿ’ฝ (๐Ÿ’– ๐Ÿ‘ธ โš–๏ธ Hypercorn), โš–๏ธ ๐Ÿ‘† ๐Ÿ’ช ๐Ÿšฎ ๐Ÿ”ซ ๐Ÿ”— ๐Ÿงฐ, ๐Ÿ’– `python-socketio`.
!!! check "**FastAPI** โš™๏ธ โšซ๏ธ"
๐Ÿต ๐ŸŒ ๐Ÿš ๐Ÿ•ธ ๐Ÿ•. โŽ โš’ ๐Ÿ”› ๐Ÿ”.
๐ŸŽ“ `FastAPI` โšซ๏ธ ๐Ÿ˜– ๐Ÿ”— โšช๏ธโžก๏ธ ๐ŸŽ“ `Starlette`.
, ๐Ÿ•ณ ๐Ÿ‘ˆ ๐Ÿ‘† ๐Ÿ’ช โฎ๏ธ ๐Ÿ’ƒ, ๐Ÿ‘† ๐Ÿ’ช โšซ๏ธ ๐Ÿ”— โฎ๏ธ **FastAPI**, โšซ๏ธ ๐ŸŒ– ๐Ÿ’ƒ ๐Ÿ”› ๐Ÿ’Š.
### <a href="https://www.uvicorn.org/" class="external-link" target="_blank">Uvicorn</a>
Uvicorn ๐ŸŒฉ-โฉ ๐Ÿ”ซ ๐Ÿ’ฝ, ๐Ÿ— ๐Ÿ”› uvloop &amp; httptool.
โšซ๏ธ ๐Ÿšซ ๐Ÿ•ธ ๐Ÿ› ๏ธ, โœ‹๏ธ ๐Ÿ’ฝ. ๐Ÿ–ผ, โšซ๏ธ ๐Ÿšซ ๐Ÿšš ๐Ÿงฐ ๐Ÿ•น โžก. ๐Ÿ‘ˆ ๐Ÿ•ณ ๐Ÿ‘ˆ ๐Ÿ› ๏ธ ๐Ÿ’– ๐Ÿ’ƒ (โš–๏ธ **FastAPI**) ๐Ÿ”œ ๐Ÿšš ๐Ÿ”› ๐Ÿ”.
โšซ๏ธ ๐Ÿ‘ ๐Ÿ’ฝ ๐Ÿ’ƒ &amp; **FastAPI**.
!!! check "**FastAPI** ๐Ÿ‘ โšซ๏ธ"
๐Ÿ‘‘ ๐Ÿ•ธ ๐Ÿ’ฝ ๐Ÿƒ **FastAPI** ๐Ÿˆธ.
๐Ÿ‘† ๐Ÿ’ช ๐ŸŒ€ โšซ๏ธ โฎ๏ธ ๐Ÿ, โœ”๏ธ ๐Ÿ” ๐Ÿ‘-๐Ÿ› ๏ธ ๐Ÿ’ฝ.
โœ… ๐ŸŒ… โ„น [๐Ÿ› ๏ธ](deployment/index.md){.internal-link target=_blank} ๐Ÿ“„.
## ๐Ÿ“‡ &amp; ๐Ÿš…
๐Ÿค”, ๐Ÿ”ฌ, &amp; ๐Ÿ‘€ ๐Ÿ”บ ๐Ÿ–– Uvicorn, ๐Ÿ’ƒ &amp; FastAPI, โœ… ๐Ÿ“„ ๐Ÿ”ƒ [๐Ÿ“‡](benchmarks.md){.internal-link target=_blank}.

430
docs/em/docs/async.md

@ -0,0 +1,430 @@
# ๐Ÿ› ๏ธ &amp; ๐Ÿ” / โŒ›
โ„น ๐Ÿ”ƒ `async def` โ• *โžก ๐Ÿ› ๏ธ ๐Ÿ”ข* &amp; ๐Ÿ–ฅ ๐Ÿ”ƒ ๐Ÿ” ๐Ÿ“Ÿ, ๐Ÿ› ๏ธ, &amp; ๐Ÿ”.
## ๐Ÿƒ โ“
<abbr title="too long; didn't read"><strong>๐Ÿ†‘;๐Ÿ‘ฉโ€โš•๏ธ:</strong></abbr>
๐Ÿšฅ ๐Ÿ‘† โš™๏ธ ๐Ÿฅ‰ ๐Ÿฅณ ๐Ÿ—ƒ ๐Ÿ‘ˆ ๐Ÿ’ฌ ๐Ÿ‘† ๐Ÿค™ ๐Ÿ‘ซ โฎ๏ธ `await`, ๐Ÿ’–:
```Python
results = await some_library()
```
โคด๏ธ, ๐Ÿ“ฃ ๐Ÿ‘† *โžก ๐Ÿ› ๏ธ ๐Ÿ”ข* โฎ๏ธ `async def` ๐Ÿ’–:
```Python hl_lines="2"
@app.get('/')
async def read_results():
results = await some_library()
return results
```
!!! note
๐Ÿ‘† ๐Ÿ’ช ๐Ÿ•ด โš™๏ธ `await` ๐Ÿ”˜ ๐Ÿ”ข โœ โฎ๏ธ `async def`.
---
๐Ÿšฅ ๐Ÿ‘† โš™๏ธ ๐Ÿฅ‰ ๐Ÿฅณ ๐Ÿ—ƒ ๐Ÿ‘ˆ ๐Ÿ”— โฎ๏ธ ๐Ÿ•ณ (๐Ÿ’ฝ, ๐Ÿ› ๏ธ, ๐Ÿ“ โš™๏ธ, โ™’๏ธ.) &amp; ๐Ÿšซ โœ”๏ธ ๐Ÿ•โ€๐Ÿฆบ โš™๏ธ `await`, (๐Ÿ‘‰ โณ ๐Ÿ’ผ ๐ŸŒ… ๐Ÿ’ฝ ๐Ÿ—ƒ), โคด๏ธ ๐Ÿ“ฃ ๐Ÿ‘† *โžก ๐Ÿ› ๏ธ ๐Ÿ”ข* ๐Ÿ›Ž, โฎ๏ธ `def`, ๐Ÿ’–:
```Python hl_lines="2"
@app.get('/')
def results():
results = some_library()
return results
```
---
๐Ÿšฅ ๐Ÿ‘† ๐Ÿˆธ (๐Ÿ˜ซ) ๐Ÿšซ โœ”๏ธ ๐Ÿ”— โฎ๏ธ ๐Ÿ•ณ ๐Ÿ™† &amp; โŒ› โšซ๏ธ ๐Ÿ“จ, โš™๏ธ `async def`.
---
๐Ÿšฅ ๐Ÿ‘† ๐Ÿšซ ๐Ÿ’ญ, โš™๏ธ ๐Ÿ˜ `def`.
---
**๐Ÿ—’**: ๐Ÿ‘† ๐Ÿ’ช ๐ŸŒ€ `def` &amp; `async def` ๐Ÿ‘† *โžก ๐Ÿ› ๏ธ ๐Ÿ”ข* ๐ŸŒ… ๐Ÿ‘† ๐Ÿ’ช &amp; ๐Ÿ”ฌ ๐Ÿ”  1๏ธโƒฃ โš™๏ธ ๐Ÿ† ๐ŸŽ› ๐Ÿ‘†. FastAPI ๐Ÿ”œ โ–ถ๏ธ๏ธ ๐Ÿ‘œ โฎ๏ธ ๐Ÿ‘ซ.
๐Ÿ˜†, ๐Ÿ™† ๐Ÿ’ผ ๐Ÿ”›, FastAPI ๐Ÿ”œ ๐Ÿ‘ท ๐Ÿ” &amp; ๐Ÿ“ถ โฉ.
โœ‹๏ธ ๐Ÿ“„ ๐Ÿ“ถ ๐Ÿ”›, โšซ๏ธ ๐Ÿ”œ ๐Ÿ’ช ๐ŸŽญ ๐Ÿ› ๏ธ.
## ๐Ÿ“ก โ„น
๐Ÿ› โฌ ๐Ÿ โœ”๏ธ ๐Ÿ•โ€๐Ÿฆบ **"๐Ÿ” ๐Ÿ“Ÿ"** โš™๏ธ ๐Ÿ•ณ ๐Ÿค™ **"๐Ÿ”"**, โฎ๏ธ **`async` &amp; `await`** โ•.
โžก๏ธ ๐Ÿ‘€ ๐Ÿ‘ˆ ๐Ÿ”ค ๐Ÿ• ๐Ÿ“„ ๐Ÿ”›:
* **๐Ÿ” ๐Ÿ“Ÿ**
* **`async` &amp; `await`**
* **๐Ÿ”**
## ๐Ÿ” ๐Ÿ“Ÿ
๐Ÿ” ๐Ÿ“Ÿ โ›“ ๐Ÿ‘ˆ ๐Ÿ‡ช๐Ÿ‡ธ ๐Ÿ‘ถ โœ”๏ธ ๐ŸŒŒ ๐Ÿ’ฌ ๐Ÿ’ป / ๐Ÿ“‹ ๐Ÿ‘ถ ๐Ÿ‘ˆ โ˜ ๐Ÿ“Ÿ, โšซ๏ธ ๐Ÿ‘ถ ๐Ÿ”œ โœ”๏ธ โŒ› *๐Ÿ•ณ ๐Ÿ™†* ๐Ÿ ๐Ÿ‘ฑ ๐Ÿ™†. โžก๏ธ ๐Ÿ’ฌ ๐Ÿ‘ˆ *๐Ÿ•ณ ๐Ÿ™†* ๐Ÿค™ "๐ŸŒ-๐Ÿ“" ๐Ÿ‘ถ.
, โฎ๏ธ ๐Ÿ‘ˆ ๐Ÿ•ฐ, ๐Ÿ’ป ๐Ÿ’ช ๐Ÿšถ &amp; ๐ŸŽ ๐Ÿ‘ท, โช "๐ŸŒ-๐Ÿ“" ๐Ÿ‘ถ ๐Ÿ.
โคด๏ธ ๐Ÿ’ป / ๐Ÿ“‹ ๐Ÿ‘ถ ๐Ÿ”œ ๐Ÿ‘Ÿ ๐Ÿ”™ ๐Ÿ”  ๐Ÿ•ฐ โšซ๏ธ โœ”๏ธ ๐Ÿคž โ†ฉ๏ธ โšซ๏ธ โŒ› ๐Ÿ”„, โš–๏ธ ๐Ÿ•โ” โšซ๏ธ ๐Ÿ‘ถ ๐Ÿ ๐ŸŒ ๐Ÿ‘ท โšซ๏ธ โœ”๏ธ ๐Ÿ‘ˆ โ˜. &amp; โšซ๏ธ ๐Ÿ‘ถ ๐Ÿ”œ ๐Ÿ‘€ ๐Ÿšฅ ๐Ÿ™† ๐Ÿ“‹ โšซ๏ธ โŒ› โœ”๏ธ โช ๐Ÿ, ๐Ÿคธ โšซ๏ธโ” โšซ๏ธ โœ”๏ธ.
โญ, โšซ๏ธ ๐Ÿ‘ถ โœŠ ๐Ÿฅ‡ ๐Ÿ“‹ ๐Ÿ (โžก๏ธ ๐Ÿ’ฌ, ๐Ÿ‘† "๐ŸŒ-๐Ÿ“" ๐Ÿ‘ถ) &amp; ๐Ÿ˜ฃ โšซ๏ธโ” โšซ๏ธ โœ”๏ธ โฎ๏ธ โšซ๏ธ.
๐Ÿ‘ˆ "โŒ› ๐Ÿ•ณ ๐Ÿ™†" ๐Ÿ›Ž ๐Ÿ”— <abbr title="Input and Output">๐Ÿ‘ค/๐Ÿ…พ</abbr> ๐Ÿ› ๏ธ ๐Ÿ‘ˆ ๐Ÿ“ถ "๐ŸŒ" (๐Ÿ”ฌ ๐Ÿš… ๐Ÿ•น &amp; ๐Ÿ’พ ๐Ÿ’พ), ๐Ÿ’– โŒ›:
* ๐Ÿ“Š โšช๏ธโžก๏ธ ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ“จ ๐Ÿ”˜ ๐Ÿ•ธ
* ๐Ÿ“Š ๐Ÿ“จ ๐Ÿ‘† ๐Ÿ“‹ ๐Ÿ“จ ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ”˜ ๐Ÿ•ธ
* ๐ŸŽš ๐Ÿ“ ๐Ÿ’พ โœ โš™๏ธ &amp; ๐Ÿค ๐Ÿ‘† ๐Ÿ“‹
* ๐ŸŽš ๐Ÿ‘† ๐Ÿ“‹ ๐Ÿค โš™๏ธ โœ ๐Ÿ’พ
* ๐Ÿ›ฐ ๐Ÿ› ๏ธ ๐Ÿ› ๏ธ
* ๐Ÿ’ฝ ๐Ÿ› ๏ธ ๐Ÿ
* ๐Ÿ’ฝ ๐Ÿ”ข ๐Ÿ“จ ๐Ÿ
* โ™’๏ธ.
๐Ÿ› ๏ธ ๐Ÿ•ฐ ๐Ÿด โœด๏ธ โŒ› <abbr title="Input and Output">๐Ÿ‘ค/๐Ÿ…พ</abbr> ๐Ÿ› ๏ธ, ๐Ÿ‘ซ ๐Ÿค™ ๐Ÿ‘ซ "๐Ÿ‘ค/๐Ÿ…พ ๐Ÿ”—" ๐Ÿ› ๏ธ.
โšซ๏ธ ๐Ÿค™ "๐Ÿ”" โ†ฉ๏ธ ๐Ÿ’ป / ๐Ÿ“‹ ๐Ÿšซ โœ”๏ธ "๐Ÿ”" โฎ๏ธ ๐ŸŒ ๐Ÿ“‹, โŒ› โ˜‘ ๐Ÿ™ ๐Ÿ‘ˆ ๐Ÿ“‹ ๐Ÿ, โช ๐Ÿ”จ ๐Ÿ•ณ, ๐Ÿ’ช โœŠ ๐Ÿ“‹ ๐Ÿ &amp; ๐Ÿ˜ฃ ๐Ÿ‘ท.
โ†ฉ๏ธ ๐Ÿ‘ˆ, ๐Ÿ’†โ€โ™‚ "๐Ÿ”" โš™๏ธ, ๐Ÿ• ๐Ÿ, ๐Ÿ“‹ ๐Ÿ’ช โŒ› โธ ๐Ÿฅ ๐Ÿ‘„ (โฒ) ๐Ÿ’ป / ๐Ÿ“‹ ๐Ÿ โšซ๏ธโ” โšซ๏ธ ๐Ÿšถ, &amp; โคด๏ธ ๐Ÿ‘Ÿ ๐Ÿ”™ โœŠ ๐Ÿ &amp; ๐Ÿ˜ฃ ๐Ÿ‘ท โฎ๏ธ ๐Ÿ‘ซ.
"๐Ÿ”" (๐Ÿ‘ฝ "๐Ÿ”") ๐Ÿ‘ซ ๐Ÿ›Ž โš™๏ธ โš– "๐Ÿ”", โ†ฉ๏ธ ๐Ÿ’ป / ๐Ÿ“‹ โฉ ๐ŸŒ ๐Ÿ“ถ ๐Ÿ” โญ ๐Ÿ”€ ๐ŸŽ ๐Ÿ“‹, ๐Ÿšฅ ๐Ÿ‘ˆ ๐Ÿ” ๐Ÿ”Œ โŒ›.
### ๐Ÿ› ๏ธ &amp; ๐Ÿ”
๐Ÿ‘‰ ๐Ÿ’ญ **๐Ÿ”** ๐Ÿ“Ÿ ๐Ÿ”ฌ ๐Ÿ”› ๐Ÿ•ฃ ๐Ÿค™ **"๐Ÿ› ๏ธ"**. โšซ๏ธ ๐ŸŽ โšช๏ธโžก๏ธ **"๐Ÿ”"**.
**๐Ÿ› ๏ธ** &amp; **๐Ÿ”** ๐Ÿ‘ฏโ€โ™‚๏ธ ๐Ÿ”— "๐ŸŽ ๐Ÿ‘œ ๐Ÿ˜ฅ ๐ŸŒ… โš–๏ธ ๐ŸŒ˜ ๐ŸŽ ๐Ÿ•ฐ".
โœ‹๏ธ โ„น ๐Ÿ–– *๐Ÿ› ๏ธ* &amp; *๐Ÿ”* ๐ŸŽ.
๐Ÿ‘€ ๐Ÿ”บ, ๐ŸŒˆ ๐Ÿ“„ ๐Ÿ“– ๐Ÿ”ƒ ๐Ÿ”:
### ๐Ÿ› ๏ธ ๐Ÿ”
๐Ÿ‘† ๐Ÿšถ โฎ๏ธ ๐Ÿ‘† ๐Ÿฅฐ ๐Ÿคš โฉ ๐Ÿฅ•, ๐Ÿ‘† ๐Ÿง โธ โช ๐Ÿง โœŠ โœ” โšช๏ธโžก๏ธ ๐Ÿ‘ซ๐Ÿ‘ซ ๐Ÿšช ๐Ÿ‘†. ๐Ÿ‘ถ
<img src="/img/async/concurrent-burgers/concurrent-burgers-01.png" class="illustration">
โคด๏ธ โšซ๏ธ ๐Ÿ‘† ๐Ÿ”„, ๐Ÿ‘† ๐Ÿฅ‰ ๐Ÿ‘† โœ” 2๏ธโƒฃ ๐Ÿ“ถ ๐ŸŽ€ ๐Ÿ” ๐Ÿ‘† ๐Ÿฅฐ &amp; ๐Ÿ‘†. ๐Ÿ‘ถ ๐Ÿ‘ถ
<img src="/img/async/concurrent-burgers/concurrent-burgers-02.png" class="illustration">
๐Ÿง ๐Ÿ’ฌ ๐Ÿ•ณ ๐Ÿณ ๐Ÿ‘จโ€๐Ÿณ ๐Ÿ‘ซ ๐Ÿ’ญ ๐Ÿ‘ซ โœ”๏ธ ๐Ÿ— ๐Ÿ‘† ๐Ÿ” (โœ‹๏ธ ๐Ÿ‘ซ โณ ๐Ÿ— ๐Ÿ• โฎ๏ธ ๐Ÿ‘ฉโ€๐Ÿ’ป).
<img src="/img/async/concurrent-burgers/concurrent-burgers-03.png" class="illustration">
๐Ÿ‘† ๐Ÿ’ธ. ๐Ÿ‘ถ
๐Ÿง ๐Ÿค ๐Ÿ‘† ๐Ÿ”ข ๐Ÿ‘† ๐Ÿ”„.
<img src="/img/async/concurrent-burgers/concurrent-burgers-04.png" class="illustration">
โช ๐Ÿ‘† โŒ›, ๐Ÿ‘† ๐Ÿšถ โฎ๏ธ ๐Ÿ‘† ๐Ÿฅฐ &amp; โš’ ๐Ÿ“, ๐Ÿ‘† ๐ŸงŽ &amp; ๐Ÿ’ฌ โฎ๏ธ ๐Ÿ‘† ๐Ÿฅฐ ๐Ÿ“ ๐Ÿ•ฐ (๐Ÿ‘† ๐Ÿ” ๐Ÿ“ถ ๐ŸŽ€ &amp; โœŠ ๐Ÿ•ฐ ๐Ÿ—).
๐Ÿ‘† ๐Ÿ– ๐Ÿ“ โฎ๏ธ ๐Ÿ‘† ๐Ÿฅฐ, โช ๐Ÿ‘† โŒ› ๐Ÿ”, ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ’ธ ๐Ÿ‘ˆ ๐Ÿ•ฐ ๐Ÿ˜ฎ โ” ๐Ÿ‘Œ, ๐Ÿจ &amp; ๐Ÿ™ƒ ๐Ÿ‘† ๐Ÿฅฐ ๐Ÿ‘ถ ๐Ÿ‘ถ ๐Ÿ‘ถ.
<img src="/img/async/concurrent-burgers/concurrent-burgers-05.png" class="illustration">
โช โŒ› &amp; ๐Ÿ’ฌ ๐Ÿ‘† ๐Ÿฅฐ, โšช๏ธโžก๏ธ ๐Ÿ•ฐ ๐Ÿ•ฐ, ๐Ÿ‘† โœ… ๐Ÿ”ข ๐Ÿ–ฅ ๐Ÿ”› โฒ ๐Ÿ‘€ ๐Ÿšฅ โšซ๏ธ ๐Ÿ‘† ๐Ÿ”„ โช.
โคด๏ธ โ˜, โšซ๏ธ ๐Ÿ˜’ ๐Ÿ‘† ๐Ÿ”„. ๐Ÿ‘† ๐Ÿšถ โฒ, ๐Ÿคš ๐Ÿ‘† ๐Ÿ” &amp; ๐Ÿ‘Ÿ ๐Ÿ”™ ๐Ÿ“.
<img src="/img/async/concurrent-burgers/concurrent-burgers-06.png" class="illustration">
๐Ÿ‘† &amp; ๐Ÿ‘† ๐Ÿฅฐ ๐Ÿด ๐Ÿ” &amp; โœ”๏ธ ๐Ÿ‘Œ ๐Ÿ•ฐ. ๐Ÿ‘ถ
<img src="/img/async/concurrent-burgers/concurrent-burgers-07.png" class="illustration">
!!! info
๐ŸŒน ๐Ÿ–ผ <a href="https://www.instagram.com/ketrinadrawsalot" class="external-link" target="_blank">๐Ÿ‘ฏ ๐Ÿ</a>. ๐Ÿ‘ถ
---
๐ŸŒˆ ๐Ÿ‘† ๐Ÿ’ป / ๐Ÿ“‹ ๐Ÿ‘ถ ๐Ÿ‘ˆ ๐Ÿ“–.
โช ๐Ÿ‘† โธ, ๐Ÿ‘† โ›ฝ ๐Ÿ‘ถ, โŒ› ๐Ÿ‘† ๐Ÿ”„, ๐Ÿšซ ๐Ÿ”จ ๐Ÿ•ณ ๐Ÿ“ถ "๐Ÿ˜Œ". โœ‹๏ธ โธ โฉ โ†ฉ๏ธ ๐Ÿง ๐Ÿ•ด โœŠ โœ” (๐Ÿšซ ๐Ÿ— ๐Ÿ‘ซ), ๐Ÿ‘ˆ ๐Ÿ‘Œ.
โคด๏ธ, ๐Ÿ•โ” โšซ๏ธ ๐Ÿ‘† ๐Ÿ”„, ๐Ÿ‘† โ˜‘ "๐Ÿ˜Œ" ๐Ÿ‘ท, ๐Ÿ‘† ๐Ÿ› ๏ธ ๐Ÿฃ, ๐Ÿ’ญ โšซ๏ธโ” ๐Ÿ‘† ๐Ÿ’š, ๐Ÿคš ๐Ÿ‘† ๐Ÿฅฐ โš’, ๐Ÿ’ธ, โœ… ๐Ÿ‘ˆ ๐Ÿ‘† ๐Ÿค โ˜‘ ๐Ÿ’ต โš–๏ธ ๐Ÿ’ณ, โœ… ๐Ÿ‘ˆ ๐Ÿ‘† ๐Ÿˆš โ˜‘, โœ… ๐Ÿ‘ˆ โœ” โœ”๏ธ โ˜‘ ๐Ÿฌ, โ™’๏ธ.
โœ‹๏ธ โคด๏ธ, โœ‹๏ธ ๐Ÿ‘† ๐Ÿšซ โœ”๏ธ ๐Ÿ‘† ๐Ÿ”, ๐Ÿ‘† ๐Ÿ‘ท โฎ๏ธ ๐Ÿง "๐Ÿ”› โธ" โธ, โ†ฉ๏ธ ๐Ÿ‘† โœ”๏ธ โŒ› ๐Ÿ‘ถ ๐Ÿ‘† ๐Ÿ” ๐Ÿ”œ.
โœ‹๏ธ ๐Ÿ‘† ๐Ÿšถ โ†–๏ธ โšช๏ธโžก๏ธ โฒ &amp; ๐ŸงŽ ๐Ÿ“ โฎ๏ธ ๐Ÿ”ข ๐Ÿ‘† ๐Ÿ”„, ๐Ÿ‘† ๐Ÿ’ช ๐ŸŽ› ๐Ÿ‘ถ ๐Ÿ‘† ๐Ÿ™‹ ๐Ÿ‘† ๐Ÿฅฐ, &amp; "๐Ÿ‘ท" ๐Ÿ‘ถ ๐Ÿ‘ถ ๐Ÿ”› ๐Ÿ‘ˆ. โคด๏ธ ๐Ÿ‘† ๐Ÿ”„ ๐Ÿ”จ ๐Ÿ•ณ ๐Ÿ“ถ "๐Ÿ˜Œ" ๐Ÿ˜ โฎ๏ธ ๐Ÿ‘† ๐Ÿฅฐ ๐Ÿ‘ถ.
โคด๏ธ ๐Ÿง ๐Ÿ‘ถ ๐Ÿ’ฌ "๐Ÿ‘ค ๐Ÿ โฎ๏ธ ๐Ÿ”จ ๐Ÿ”" ๐Ÿšฎ ๐Ÿ‘† ๐Ÿ”ข ๐Ÿ”› โฒ ๐Ÿ–ฅ, โœ‹๏ธ ๐Ÿ‘† ๐Ÿšซ ๐Ÿฆ˜ ๐Ÿ’– ๐Ÿ˜œ โช ๐Ÿ•โ” ๐Ÿ–ฅ ๐Ÿ”ข ๐Ÿ”€ ๐Ÿ‘† ๐Ÿ”„ ๐Ÿ”ข. ๐Ÿ‘† ๐Ÿ’ญ ๐Ÿ™…โ€โ™‚ 1๏ธโƒฃ ๐Ÿ”œ ๐Ÿ“Ž ๐Ÿ‘† ๐Ÿ” โ†ฉ๏ธ ๐Ÿ‘† โœ”๏ธ ๐Ÿ”ข ๐Ÿ‘† ๐Ÿ”„, &amp; ๐Ÿ‘ซ โœ”๏ธ ๐Ÿ‘ซ.
๐Ÿ‘† โŒ› ๐Ÿ‘† ๐Ÿฅฐ ๐Ÿ ๐Ÿ“– (๐Ÿ โฎ๏ธ ๐Ÿ‘ท ๐Ÿ‘ถ / ๐Ÿ“‹ โž– ๐Ÿ› ๏ธ ๐Ÿ‘ถ), ๐Ÿ˜€ ๐Ÿ– &amp; ๐Ÿ’ฌ ๐Ÿ‘ˆ ๐Ÿ‘† ๐Ÿ”œ ๐Ÿ” โธ.
โคด๏ธ ๐Ÿ‘† ๐Ÿšถ โฒ ๐Ÿ‘ถ, โ–ถ๏ธ ๐Ÿ“‹ ๐Ÿ‘ˆ ๐Ÿ”œ ๐Ÿ ๐Ÿ‘ถ, โš’ ๐Ÿ”, ๐Ÿ’ฌ ๐Ÿ‘ &amp; โœŠ ๐Ÿ‘ซ ๐Ÿ“. ๐Ÿ‘ˆ ๐Ÿ ๐Ÿ‘ˆ ๐Ÿ” / ๐Ÿ“‹ ๐Ÿ”— โฎ๏ธ โฒ โน. ๐Ÿ‘ˆ ๐Ÿ”„, โœ ๐Ÿ†• ๐Ÿ“‹, "๐Ÿด ๐Ÿ”" ๐Ÿ‘ถ ๐Ÿ‘ถ, โœ‹๏ธ โฎ๏ธ 1๏ธโƒฃ "๐Ÿคš ๐Ÿ”" ๐Ÿ โน.
### ๐Ÿ”— ๐Ÿ”
๐Ÿ”œ โžก๏ธ ๐ŸŒˆ ๐Ÿ‘ซ โž–๐Ÿšซ ๐Ÿšซ "๐Ÿ› ๏ธ ๐Ÿ”", โœ‹๏ธ "๐Ÿ”— ๐Ÿ”".
๐Ÿ‘† ๐Ÿšถ โฎ๏ธ ๐Ÿ‘† ๐Ÿฅฐ ๐Ÿคš ๐Ÿ”— โฉ ๐Ÿฅ•.
๐Ÿ‘† ๐Ÿง โธ โช ๐Ÿ“š (โžก๏ธ ๐Ÿ’ฌ 8๏ธโƒฃ) ๐Ÿง ๐Ÿ‘ˆ ๐ŸŽ ๐Ÿ•ฐ ๐Ÿณ โœŠ โœ” โšช๏ธโžก๏ธ ๐Ÿ‘ซ๐Ÿ‘ซ ๐Ÿšช ๐Ÿ‘†.
๐Ÿ‘ฑ โญ ๐Ÿ‘† โŒ› ๐Ÿ‘ซ ๐Ÿ” ๐Ÿ”œ โญ ๐Ÿ‚ โฒ โ†ฉ๏ธ ๐Ÿ”  8๏ธโƒฃ ๐Ÿง ๐Ÿšถ &amp; ๐Ÿ— ๐Ÿ” โ–ถ๏ธ๏ธ โ†–๏ธ โญ ๐Ÿ’†โ€โ™‚ โญ โœ”.
<img src="/img/async/parallel-burgers/parallel-burgers-01.png" class="illustration">
โคด๏ธ โšซ๏ธ ๐Ÿ˜’ ๐Ÿ‘† ๐Ÿ”„, ๐Ÿ‘† ๐Ÿฅ‰ ๐Ÿ‘† โœ” 2๏ธโƒฃ ๐Ÿ“ถ ๐ŸŽ€ ๐Ÿ” ๐Ÿ‘† ๐Ÿฅฐ &amp; ๐Ÿ‘†.
๐Ÿ‘† ๐Ÿ’ธ ๐Ÿ‘ถ.
<img src="/img/async/parallel-burgers/parallel-burgers-02.png" class="illustration">
๐Ÿง ๐Ÿšถ ๐Ÿ‘จโ€๐Ÿณ.
๐Ÿ‘† โŒ›, ๐Ÿง ๐Ÿšช โฒ ๐Ÿ‘ถ, ๐Ÿ‘ˆ ๐Ÿ™…โ€โ™‚ 1๏ธโƒฃ ๐Ÿ™† โœŠ ๐Ÿ‘† ๐Ÿ” โญ ๐Ÿ‘†, ๐Ÿ“ค ๐Ÿ™…โ€โ™‚ ๐Ÿ”ข ๐Ÿ”„.
<img src="/img/async/parallel-burgers/parallel-burgers-03.png" class="illustration">
๐Ÿ‘† &amp; ๐Ÿ‘† ๐Ÿฅฐ ๐Ÿ˜ฉ ๐Ÿšซ โžก๏ธ ๐Ÿ™† ๐Ÿคš ๐Ÿšช ๐Ÿ‘† &amp; โœŠ ๐Ÿ‘† ๐Ÿ” ๐Ÿ•โ” ๐Ÿ‘ซ ๐Ÿ›ฌ, ๐Ÿ‘† ๐Ÿšซ๐Ÿ”œ ๐Ÿ’ธ ๐Ÿ™‹ ๐Ÿ‘† ๐Ÿฅฐ. ๐Ÿ‘ถ
๐Ÿ‘‰ "๐Ÿ”" ๐Ÿ‘ท, ๐Ÿ‘† "๐Ÿ”" โฎ๏ธ ๐Ÿง/๐Ÿณ ๐Ÿ‘ถ ๐Ÿ‘ถ. ๐Ÿ‘† โœ”๏ธ โŒ› ๐Ÿ‘ถ &amp; ๐Ÿ“ค โ˜‘ ๐Ÿ™ ๐Ÿ‘ˆ ๐Ÿง/๐Ÿณ ๐Ÿ‘ถ ๐Ÿ‘ถ ๐Ÿ ๐Ÿ” &amp; ๐Ÿค ๐Ÿ‘ซ ๐Ÿ‘†, โš–๏ธ โช, ๐Ÿ‘ฑ ๐Ÿ™† ๐Ÿ’ช โœŠ ๐Ÿ‘ซ.
<img src="/img/async/parallel-burgers/parallel-burgers-04.png" class="illustration">
โคด๏ธ ๐Ÿ‘† ๐Ÿง/๐Ÿณ ๐Ÿ‘ถ ๐Ÿ‘ถ ๐Ÿ˜’ ๐Ÿ‘Ÿ ๐Ÿ”™ โฎ๏ธ ๐Ÿ‘† ๐Ÿ”, โฎ๏ธ ๐Ÿ“ ๐Ÿ•ฐ โŒ› ๐Ÿ‘ถ ๐Ÿ“ค ๐Ÿšช โฒ.
<img src="/img/async/parallel-burgers/parallel-burgers-05.png" class="illustration">
๐Ÿ‘† โœŠ ๐Ÿ‘† ๐Ÿ” &amp; ๐Ÿšถ ๐Ÿ“ โฎ๏ธ ๐Ÿ‘† ๐Ÿฅฐ.
๐Ÿ‘† ๐Ÿด ๐Ÿ‘ซ, &amp; ๐Ÿ‘† ๐Ÿ”จ. โน
<img src="/img/async/parallel-burgers/parallel-burgers-06.png" class="illustration">
๐Ÿ“ค ๐Ÿšซ ๐ŸŒ… ๐Ÿ’ฌ โš–๏ธ ๐Ÿ˜ ๐ŸŒ… ๐Ÿ•ฐ ๐Ÿ’ธ โŒ› ๐Ÿ‘ถ ๐Ÿšช โฒ. ๐Ÿ‘ถ
!!! info
๐ŸŒน ๐Ÿ–ผ <a href="https://www.instagram.com/ketrinadrawsalot" class="external-link" target="_blank">๐Ÿ‘ฏ ๐Ÿ</a>. ๐Ÿ‘ถ
---
๐Ÿ‘‰ ๐Ÿ˜ ๐Ÿ”— ๐Ÿ”, ๐Ÿ‘† ๐Ÿ’ป / ๐Ÿ“‹ ๐Ÿ‘ถ โฎ๏ธ 2๏ธโƒฃ ๐Ÿ•น (๐Ÿ‘† &amp; ๐Ÿ‘† ๐Ÿฅฐ), ๐Ÿ‘ฏโ€โ™‚๏ธ โŒ› ๐Ÿ‘ถ &amp; ๐Ÿ’ก ๐Ÿ‘ซ ๐Ÿ™‹ ๐Ÿ‘ถ "โŒ› ๐Ÿ”› โฒ" ๐Ÿ‘ถ ๐Ÿ“ ๐Ÿ•ฐ.
โฉ ๐Ÿฅ• ๐Ÿช โœ”๏ธ 8๏ธโƒฃ ๐Ÿ•น (๐Ÿง/๐Ÿณ). โช ๐Ÿ› ๏ธ ๐Ÿ” ๐Ÿช ๐Ÿ’ช โœ”๏ธ โœ”๏ธ ๐Ÿ•ด 2๏ธโƒฃ (1๏ธโƒฃ ๐Ÿง &amp; 1๏ธโƒฃ ๐Ÿณ).
โœ‹๏ธ, ๐Ÿ ๐Ÿ’ก ๐Ÿšซ ๐Ÿ†. ๐Ÿ‘ถ
---
๐Ÿ‘‰ ๐Ÿ”œ ๐Ÿ”— ๐ŸŒ“ ๐Ÿ“– ๐Ÿ”. ๐Ÿ‘ถ
๐ŸŒ… "๐ŸŽฐ ๐Ÿ‘จโ€โคโ€๐Ÿ‘จ" ๐Ÿ–ผ ๐Ÿ‘‰, ๐ŸŒˆ ๐Ÿฆ.
๐Ÿ†™ โณ, ๐Ÿ† ๐Ÿฆ โœ”๏ธ ๐Ÿ’— ๐Ÿง ๐Ÿ‘ถ ๐Ÿ‘ถ ๐Ÿ‘ถ ๐Ÿ‘ถ ๐Ÿ‘ถ ๐Ÿ‘ถ ๐Ÿ‘ถ ๐Ÿ‘ถ &amp; ๐Ÿฆ โธ ๐Ÿ‘ถ ๐Ÿ‘ถ ๐Ÿ‘ถ ๐Ÿ‘ถ ๐Ÿ‘ถ ๐Ÿ‘ถ ๐Ÿ‘ถ ๐Ÿ‘ถ.
๐ŸŒ ๐Ÿง ๐Ÿ”จ ๐ŸŒ ๐Ÿ‘ท โฎ๏ธ 1๏ธโƒฃ ๐Ÿ‘ฉโ€๐Ÿ’ป โฎ๏ธ ๐ŸŽ ๐Ÿ‘ถ ๐Ÿ‘ถ ๐Ÿ‘ถ.
&amp; ๐Ÿ‘† โœ”๏ธ โŒ› ๐Ÿ‘ถ โธ ๐Ÿ“ ๐Ÿ•ฐ โš–๏ธ ๐Ÿ‘† ๐Ÿ’ธ ๐Ÿ‘† ๐Ÿ”„.
๐Ÿ‘† ๐ŸŽฒ ๐Ÿšซ๐Ÿ”œ ๐Ÿ’š โœŠ ๐Ÿ‘† ๐Ÿฅฐ ๐Ÿ‘ถ โฎ๏ธ ๐Ÿ‘† ๐Ÿ‘ท ๐Ÿฆ ๐Ÿ‘ถ.
### ๐Ÿ” ๐Ÿ
๐Ÿ‘‰ ๐Ÿ˜ "โฉ ๐Ÿฅ• ๐Ÿ” โฎ๏ธ ๐Ÿ‘† ๐Ÿฅฐ", ๐Ÿ“ค ๐Ÿ“š โŒ› ๐Ÿ‘ถ, โšซ๏ธ โš’ ๐Ÿ“š ๐ŸŒ… ๐Ÿ”‘ โœ”๏ธ ๐Ÿ› ๏ธ โš™๏ธ โธ ๐Ÿ‘ถ ๐Ÿ‘ถ.
๐Ÿ‘‰ ๐Ÿ’ผ ๐ŸŒ… ๐Ÿ•ธ ๐Ÿˆธ.
๐Ÿ“š, ๐Ÿ“š ๐Ÿ‘ฉโ€๐Ÿ’ป, โœ‹๏ธ ๐Ÿ‘† ๐Ÿ’ฝ โŒ› ๐Ÿ‘ถ ๐Ÿ‘ซ ๐Ÿšซ--๐Ÿ‘ ๐Ÿ”— ๐Ÿ“จ ๐Ÿ‘ซ ๐Ÿ“จ.
&amp; โคด๏ธ โŒ› ๐Ÿ‘ถ ๐Ÿ”„ ๐Ÿ“จ ๐Ÿ‘Ÿ ๐Ÿ”™.
๐Ÿ‘‰ "โŒ›" ๐Ÿ‘ถ โš– โฒ, โœ‹๏ธ, โš– โšซ๏ธ ๐ŸŒ, โšซ๏ธ ๐Ÿ“š โŒ› ๐Ÿ”š.
๐Ÿ‘ˆ โšซ๏ธโ” โšซ๏ธ โš’ ๐Ÿ“š ๐Ÿ”‘ โš™๏ธ ๐Ÿ” โธ ๐Ÿ‘ถ ๐Ÿ‘ถ ๐Ÿ“Ÿ ๐Ÿ•ธ ๐Ÿ”—.
๐Ÿ‘‰ ๐Ÿ˜‡ ๐Ÿ”€ โšซ๏ธโ” โš’ โœณ ๐ŸŒŸ (โœ‹๏ธ โœณ ๐Ÿšซ ๐Ÿ”—) &amp; ๐Ÿ‘ˆ ๐Ÿ’ช ๐Ÿšถ ๐Ÿ› ๏ธ ๐Ÿ‡ช๐Ÿ‡ธ.
&amp; ๐Ÿ‘ˆ ๐ŸŽ ๐ŸŽš ๐ŸŽญ ๐Ÿ‘† ๐Ÿคš โฎ๏ธ **FastAPI**.
&amp; ๐Ÿ‘† ๐Ÿ’ช โœ”๏ธ ๐Ÿ” &amp; ๐Ÿ”€ ๐ŸŽ ๐Ÿ•ฐ, ๐Ÿ‘† ๐Ÿคš โ†• ๐ŸŽญ ๐ŸŒ˜ ๐ŸŒ… ๐Ÿ’ฏ โœณ ๐Ÿ› ๏ธ &amp; ๐Ÿ”› ๐Ÿ‡ท๐Ÿ‡ช โฎ๏ธ ๐Ÿšถ, โ” โœ ๐Ÿ‡ช๐Ÿ‡ธ ๐Ÿ” ๐Ÿ…ฑ <a href="https://www.techempower.com/benchmarks/#section=data-r17&hw=ph&test=query&l=zijmkf-1" class="external-link" target="_blank">(๐ŸŒ ๐Ÿ‘ ๐Ÿ’ƒ)</a>.
### ๐Ÿ› ๏ธ ๐Ÿ‘ ๐ŸŒ˜ ๐Ÿ” โ“
๐Ÿ˜† โ— ๐Ÿ‘ˆ ๐Ÿšซ ๐Ÿ› ๐Ÿ“–.
๐Ÿ› ๏ธ ๐ŸŽ ๐ŸŒ˜ ๐Ÿ”. &amp; โšซ๏ธ ๐Ÿ‘ป ๐Ÿ”› **๐ŸŽฏ** ๐Ÿ˜ ๐Ÿ‘ˆ ๐Ÿ”Œ ๐Ÿ“š โŒ›. โ†ฉ๏ธ ๐Ÿ‘ˆ, โšซ๏ธ ๐Ÿ›Ž ๐Ÿ“š ๐Ÿ‘ ๐ŸŒ˜ ๐Ÿ” ๐Ÿ•ธ ๐Ÿˆธ ๐Ÿ› ๏ธ. โœ‹๏ธ ๐Ÿšซ ๐ŸŒ.
, โš– ๐Ÿ‘ˆ ๐Ÿ‘…, ๐ŸŒˆ ๐Ÿ“„ ๐Ÿ“ ๐Ÿ“–:
&gt; ๐Ÿ‘† โœ”๏ธ ๐Ÿงน ๐Ÿฆ, ๐Ÿ’ฉ ๐Ÿ .
*๐Ÿ˜†, ๐Ÿ‘ˆ ๐ŸŽ‚ ๐Ÿ“–*.
---
๐Ÿ“ค ๐Ÿ™…โ€โ™‚ โŒ› ๐Ÿ‘ถ ๐Ÿ™†, ๐Ÿ“š ๐Ÿ‘ท ๐Ÿ”จ, ๐Ÿ”› ๐Ÿ’— ๐Ÿฅ‰ ๐Ÿ .
๐Ÿ‘† ๐Ÿ’ช โœ”๏ธ ๐Ÿ”„ ๐Ÿ” ๐Ÿ–ผ, ๐Ÿฅ‡ ๐Ÿ  ๐Ÿง–โ€โ™‚, โคด๏ธ ๐Ÿ‘จโ€๐Ÿณ, โœ‹๏ธ ๐Ÿ‘† ๐Ÿšซ โŒ› ๐Ÿ‘ถ ๐Ÿ•ณ, ๐Ÿงน &amp; ๐Ÿงน, ๐Ÿ”„ ๐Ÿšซ๐Ÿ”œ ๐Ÿ“‰ ๐Ÿ•ณ.
โšซ๏ธ ๐Ÿ”œ โœŠ ๐ŸŽ ๐Ÿ’ธ ๐Ÿ•ฐ ๐Ÿ โฎ๏ธ โš–๏ธ ๐Ÿต ๐Ÿ”„ (๐Ÿ› ๏ธ) &amp; ๐Ÿ‘† ๐Ÿ”œ โœ”๏ธ โŒ› ๐ŸŽ ๐Ÿ’ธ ๐Ÿ‘ท.
โœ‹๏ธ ๐Ÿ‘‰ ๐Ÿ’ผ, ๐Ÿšฅ ๐Ÿ‘† ๐Ÿ’ช โœŠ๏ธ 8๏ธโƒฃ ๐Ÿ‘ฐ-๐Ÿง/๐Ÿณ/๐Ÿ”œ-๐Ÿงน, &amp; ๐Ÿ”  1๏ธโƒฃ ๐Ÿ‘ซ (โž• ๐Ÿ‘†) ๐Ÿ’ช โœŠ ๐Ÿ’ ๐Ÿ  ๐Ÿงน โšซ๏ธ, ๐Ÿ‘† ๐Ÿ’ช ๐ŸŒ ๐Ÿ‘ท **๐Ÿ”—**, โฎ๏ธ โž• โ„น, &amp; ๐Ÿ ๐ŸŒ… ๐Ÿ”œ.
๐Ÿ‘‰ ๐Ÿ˜, ๐Ÿ”  1๏ธโƒฃ ๐Ÿงน (๐Ÿ”Œ ๐Ÿ‘†) ๐Ÿ”œ ๐Ÿ•น, ๐Ÿคธ ๐Ÿ‘ซ ๐Ÿ• ๐Ÿ‘จโ€๐Ÿญ.
&amp; ๐Ÿ† ๐Ÿ› ๏ธ ๐Ÿ•ฐ โœŠ โ˜‘ ๐Ÿ‘ท (โ†ฉ๏ธ โŒ›), &amp; ๐Ÿ‘ท ๐Ÿ’ป โŒ› <abbr title="Central Processing Unit">๐Ÿ’ฝ</abbr>, ๐Ÿ‘ซ ๐Ÿค™ ๐Ÿ‘ซ โš  "๐Ÿ’ฝ ๐ŸŽ".
---
โš  ๐Ÿ–ผ ๐Ÿ’ฝ ๐Ÿ”— ๐Ÿ› ๏ธ ๐Ÿ‘œ ๐Ÿ‘ˆ ๐Ÿšš ๐Ÿ— ๐Ÿงช ๐Ÿญ.
๐Ÿ–ผ:
* **๐ŸŽง** โš–๏ธ **๐Ÿ–ผ ๐Ÿญ**.
* **๐Ÿ’ป ๐Ÿ‘“**: ๐Ÿ–ผ โœ ๐Ÿ’ฏ ๐Ÿ”…, ๐Ÿ”  ๐Ÿ”… โœ”๏ธ 3๏ธโƒฃ ๐Ÿ’ฒ / ๐ŸŽจ, ๐Ÿญ ๐Ÿ‘ˆ ๐Ÿ›Ž ๐Ÿšš ๐Ÿ’ป ๐Ÿ•ณ ๐Ÿ”› ๐Ÿ“š ๐Ÿ”…, ๐ŸŒ ๐ŸŽ ๐Ÿ•ฐ.
* **๐ŸŽฐ ๐Ÿซ**: โšซ๏ธ ๐Ÿ›Ž ๐Ÿšš ๐Ÿ“š "โœ–" &amp; "๐Ÿ–ผ" โœ–. ๐Ÿ’ญ ๐Ÿฆ ๐Ÿ“‹ โฎ๏ธ ๐Ÿ”ข &amp; โœ– ๐ŸŒ ๐Ÿ‘ซ ๐Ÿ‘ฏโ€โ™‚๏ธ ๐ŸŽ ๐Ÿ•ฐ.
* **โฌ ๐Ÿซ**: ๐Ÿ‘‰ ๐ŸŽง-๐Ÿ‘ ๐ŸŽฐ ๐Ÿซ,, ๐ŸŽ โœ”. โšซ๏ธ ๐Ÿ‘ˆ ๐Ÿ“ค ๐Ÿšซ ๐Ÿ‘ ๐Ÿ“‹ ๐Ÿ”ข โœ–, โœ‹๏ธ ๐Ÿฆ โš’ ๐Ÿ‘ซ, &amp; ๐Ÿ“š ๐Ÿ’ผ, ๐Ÿ‘† โš™๏ธ ๐ŸŽ ๐Ÿ•น ๐Ÿ— &amp; / โš–๏ธ โš™๏ธ ๐Ÿ‘ˆ ๐Ÿท.
### ๐Ÿ› ๏ธ โž• ๐Ÿ”: ๐Ÿ•ธ โž• ๐ŸŽฐ ๐Ÿซ
โฎ๏ธ **FastAPI** ๐Ÿ‘† ๐Ÿ’ช โœŠ ๐Ÿ“ˆ ๐Ÿ› ๏ธ ๐Ÿ‘ˆ ๐Ÿ“ถ โš  ๐Ÿ•ธ ๐Ÿ› ๏ธ (๐ŸŽ ๐Ÿ‘‘ ๐Ÿงฒ โœณ).
โœ‹๏ธ ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ„ ๐Ÿ’ฐ ๐Ÿ” &amp; ๐Ÿ’พ (โœ”๏ธ ๐Ÿ’— ๐Ÿ› ๏ธ ๐Ÿƒโ€โ™‚ ๐Ÿ”—) **๐Ÿ’ฝ ๐ŸŽ** โš– ๐Ÿ’– ๐Ÿ‘ˆ ๐ŸŽฐ ๐Ÿซ โš™๏ธ.
๐Ÿ‘ˆ, โž• ๐Ÿ™… ๐Ÿ‘ ๐Ÿ‘ˆ ๐Ÿ ๐Ÿ‘‘ ๐Ÿ‡ช๐Ÿ‡ธ **๐Ÿ’ฝ ๐Ÿงช**, ๐ŸŽฐ ๐Ÿซ &amp; โœด๏ธ โฌ ๐Ÿซ, โš’ FastAPI ๐Ÿ“ถ ๐Ÿ‘ ๐Ÿ ๐Ÿ’ฝ ๐Ÿงช / ๐ŸŽฐ ๐Ÿซ ๐Ÿ•ธ ๐Ÿ”— &amp; ๐Ÿˆธ (๐Ÿ‘ช ๐Ÿ“š ๐ŸŽ).
๐Ÿ‘€ โ” ๐Ÿ† ๐Ÿ‘‰ ๐Ÿ” ๐Ÿญ ๐Ÿ‘€ ๐Ÿ“„ ๐Ÿ”ƒ [๐Ÿ› ๏ธ](deployment/index.md){.internal-link target=_blank}.
## `async` &amp; `await`
๐Ÿ› โฌ ๐Ÿ โœ”๏ธ ๐Ÿ“ถ ๐Ÿ‹๏ธ ๐ŸŒŒ ๐Ÿ”ฌ ๐Ÿ” ๐Ÿ“Ÿ. ๐Ÿ‘‰ โš’ โšซ๏ธ ๐Ÿ‘€ ๐Ÿ’– ๐Ÿ˜ "๐Ÿ”" ๐Ÿ“Ÿ &amp; "โŒ›" ๐Ÿ‘† โ–ถ๏ธ๏ธ ๐Ÿ™.
๐Ÿ•โ” ๐Ÿ“ค ๐Ÿ› ๏ธ ๐Ÿ‘ˆ ๐Ÿ”œ ๐Ÿšš โŒ› โญ ๐Ÿค ๐Ÿ &amp; โœ”๏ธ ๐Ÿ•โ€๐Ÿฆบ ๐Ÿ‘‰ ๐Ÿ†• ๐Ÿ โš’, ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ“Ÿ โšซ๏ธ ๐Ÿ’–:
```Python
burgers = await get_burgers(2)
```
๐Ÿ”‘ ๐Ÿ“ฅ `await`. โšซ๏ธ ๐Ÿ’ฌ ๐Ÿ ๐Ÿ‘ˆ โšซ๏ธ โœ”๏ธ โŒ› โธ `get_burgers(2)` ๐Ÿ ๐Ÿ”จ ๐Ÿšฎ ๐Ÿ‘œ ๐Ÿ‘ถ โญ โ™ป ๐Ÿ `burgers`. โฎ๏ธ ๐Ÿ‘ˆ, ๐Ÿ ๐Ÿ”œ ๐Ÿ’ญ ๐Ÿ‘ˆ โšซ๏ธ ๐Ÿ’ช ๐Ÿšถ &amp; ๐Ÿ•ณ ๐Ÿ™† ๐Ÿ‘ถ ๐Ÿ‘ถ ๐Ÿ‘ (๐Ÿ’– ๐Ÿ“จ โž•1๏ธโƒฃ ๐Ÿ“จ).
`await` ๐Ÿ‘ท, โšซ๏ธ โœ”๏ธ ๐Ÿ”˜ ๐Ÿ”ข ๐Ÿ‘ˆ ๐Ÿ•โ€๐Ÿฆบ ๐Ÿ‘‰ ๐Ÿ”€. ๐Ÿ‘ˆ, ๐Ÿ‘† ๐Ÿ“ฃ โšซ๏ธ โฎ๏ธ `async def`:
```Python hl_lines="1"
async def get_burgers(number: int):
# Do some asynchronous stuff to create the burgers
return burgers
```
...โ†ฉ๏ธ `def`:
```Python hl_lines="2"
# This is not asynchronous
def get_sequential_burgers(number: int):
# Do some sequential stuff to create the burgers
return burgers
```
โฎ๏ธ `async def`, ๐Ÿ ๐Ÿ’ญ ๐Ÿ‘ˆ, ๐Ÿ”˜ ๐Ÿ‘ˆ ๐Ÿ”ข, โšซ๏ธ โœ”๏ธ ๐Ÿค” `await` ๐Ÿงฌ, &amp; ๐Ÿ‘ˆ โšซ๏ธ ๐Ÿ’ช "โธ" โธ ๐Ÿ› ๏ธ ๐Ÿ‘ˆ ๐Ÿ”ข &amp; ๐Ÿšถ ๐Ÿ•ณ ๐Ÿ™† ๐Ÿ‘ถ โญ ๐Ÿ‘Ÿ ๐Ÿ”™.
๐Ÿ•โ” ๐Ÿ‘† ๐Ÿ’š ๐Ÿค™ `async def` ๐Ÿ”ข, ๐Ÿ‘† โœ”๏ธ "โŒ›" โšซ๏ธ. , ๐Ÿ‘‰ ๐Ÿ† ๐Ÿšซ ๐Ÿ‘ท:
```Python
# This won't work, because get_burgers was defined with: async def
burgers = get_burgers(2)
```
---
, ๐Ÿšฅ ๐Ÿ‘† โš™๏ธ ๐Ÿ—ƒ ๐Ÿ‘ˆ ๐Ÿ’ฌ ๐Ÿ‘† ๐Ÿ‘ˆ ๐Ÿ‘† ๐Ÿ’ช ๐Ÿค™ โšซ๏ธ โฎ๏ธ `await`, ๐Ÿ‘† ๐Ÿ’ช โœ *โžก ๐Ÿ› ๏ธ ๐Ÿ”ข* ๐Ÿ‘ˆ โš™๏ธ โšซ๏ธ โฎ๏ธ `async def`, ๐Ÿ’–:
```Python hl_lines="2-3"
@app.get('/burgers')
async def read_burgers():
burgers = await get_burgers(2)
return burgers
```
### ๐ŸŒ… ๐Ÿ“ก โ„น
๐Ÿ‘† ๐Ÿ’ช โœ”๏ธ ๐Ÿ‘€ ๐Ÿ‘ˆ `await` ๐Ÿ’ช ๐Ÿ•ด โš™๏ธ ๐Ÿ”˜ ๐Ÿ”ข ๐Ÿ”ฌ โฎ๏ธ `async def`.
โœ‹๏ธ ๐ŸŽ ๐Ÿ•ฐ, ๐Ÿ”ข ๐Ÿ”ฌ โฎ๏ธ `async def` โœ”๏ธ "โŒ›". , ๐Ÿ”ข โฎ๏ธ `async def` ๐Ÿ’ช ๐Ÿ•ด ๐Ÿค™ ๐Ÿ”˜ ๐Ÿ”ข ๐Ÿ”ฌ โฎ๏ธ `async def` ๐Ÿ’โ€โ™‚๏ธ.
, ๐Ÿ”ƒ ๐Ÿฅš &amp; ๐Ÿ”, โ” ๐Ÿ‘† ๐Ÿค™ ๐Ÿฅ‡ `async` ๐Ÿ”ข โ“
๐Ÿšฅ ๐Ÿ‘† ๐Ÿ‘ท โฎ๏ธ **FastAPI** ๐Ÿ‘† ๐Ÿšซ โœ”๏ธ ๐Ÿ˜Ÿ ๐Ÿ”ƒ ๐Ÿ‘ˆ, โ†ฉ๏ธ ๐Ÿ‘ˆ "๐Ÿฅ‡" ๐Ÿ”ข ๐Ÿ”œ ๐Ÿ‘† *โžก ๐Ÿ› ๏ธ ๐Ÿ”ข*, &amp; FastAPI ๐Ÿ”œ ๐Ÿ’ญ โ” โ–ถ๏ธ๏ธ ๐Ÿ‘œ.
โœ‹๏ธ ๐Ÿšฅ ๐Ÿ‘† ๐Ÿ’š โš™๏ธ `async` / `await` ๐Ÿต FastAPI, ๐Ÿ‘† ๐Ÿ’ช โšซ๏ธ ๐Ÿ‘.
### โœ ๐Ÿ‘† ๐Ÿ‘ ๐Ÿ” ๐Ÿ“Ÿ
๐Ÿ’ƒ (&amp; **FastAPI**) โš“๏ธ ๐Ÿ”› <a href="https://anyio.readthedocs.io/en/stable/" class="external-link" target="_blank">AnyIO</a>, โ” โš’ โšซ๏ธ ๐Ÿ”— โฎ๏ธ ๐Ÿ‘ฏโ€โ™‚๏ธ ๐Ÿ ๐Ÿฉ ๐Ÿ—ƒ <a href="https://docs.python.org/3/library/asyncio-task.html" class="external-link" target="_blank">โœณ</a> &amp; <a href="https://trio.readthedocs.io/en/stable/" class="external-link" target="_blank">๐ŸŽป</a>.
๐ŸŽฏ, ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ”— โš™๏ธ <a href="https://anyio.readthedocs.io/en/stable/" class="external-link" target="_blank">AnyIO</a> ๐Ÿ‘† ๐Ÿง ๐Ÿ› ๏ธ โš™๏ธ ๐Ÿ’ผ ๐Ÿ‘ˆ ๐Ÿšš ๐ŸŒ… ๐Ÿง โš“ ๐Ÿ‘† ๐Ÿ‘ ๐Ÿ“Ÿ.
&amp; ๐Ÿšฅ ๐Ÿ‘† ๐Ÿšซ โš™๏ธ FastAPI, ๐Ÿ‘† ๐Ÿ’ช โœ ๐Ÿ‘† ๐Ÿ‘ ๐Ÿ” ๐Ÿˆธ โฎ๏ธ <a href="https://anyio.readthedocs.io/en/stable/" class="external-link" target="_blank">AnyIO</a> ๐Ÿ† ๐Ÿ”— &amp; ๐Ÿคš ๐Ÿšฎ ๐Ÿ’ฐ (โœ… *๐Ÿ“Š ๐Ÿ› ๏ธ*).
### ๐ŸŽ ๐Ÿ“จ ๐Ÿ” ๐Ÿ“Ÿ
๐Ÿ‘‰ ๐Ÿ‘— โš™๏ธ `async` &amp; `await` ๐Ÿ“ถ ๐Ÿ†• ๐Ÿ‡ช๐Ÿ‡ธ.
โœ‹๏ธ โšซ๏ธ โš’ ๐Ÿ‘ท โฎ๏ธ ๐Ÿ” ๐Ÿ“Ÿ ๐Ÿ“š โฉ.
๐Ÿ‘‰ ๐ŸŽ โ• (โš–๏ธ ๐ŸŒ– ๐ŸŒ“) ๐Ÿ”Œ โณ ๐Ÿ› โฌ ๐Ÿ•ธ (๐Ÿ–ฅ &amp; โœณ).
โœ‹๏ธ โญ ๐Ÿ‘ˆ, ๐Ÿšš ๐Ÿ” ๐Ÿ“Ÿ ๐ŸŒ– ๐Ÿ— &amp; โš .
โฎ๏ธ โฌ ๐Ÿ, ๐Ÿ‘† ๐Ÿ’ช โœ”๏ธ โš™๏ธ ๐Ÿงต โš–๏ธ <a href="https://www.gevent.org/" class="external-link" target="_blank">๐Ÿ</a>. โœ‹๏ธ ๐Ÿ“Ÿ ๐ŸŒŒ ๐ŸŒ– ๐Ÿ— ๐Ÿค”, โ„น, &amp; ๐Ÿ’ญ ๐Ÿ”ƒ.
โฎ๏ธ โฌ โœณ / ๐Ÿ–ฅ ๐Ÿ•ธ, ๐Ÿ‘† ๐Ÿ”œ โœ”๏ธ โš™๏ธ "โฒ". โ” โ†˜๏ธ <a href="http://callbackhell.com/" class="external-link" target="_blank">โฒ ๐Ÿ”ฅ๐Ÿ˜ˆ</a>.
## ๐Ÿ”
**๐Ÿ”** ๐Ÿ“ถ ๐ŸŽ€ โš– ๐Ÿ‘œ ๐Ÿ“จ `async def` ๐Ÿ”ข. ๐Ÿ ๐Ÿ’ญ ๐Ÿ‘ˆ โšซ๏ธ ๐Ÿ•ณ ๐Ÿ’– ๐Ÿ”ข ๐Ÿ‘ˆ โšซ๏ธ ๐Ÿ’ช โ–ถ๏ธ &amp; ๐Ÿ‘ˆ โšซ๏ธ ๐Ÿ”œ ๐Ÿ”š โ˜, โœ‹๏ธ ๐Ÿ‘ˆ โšซ๏ธ 5๏ธโƒฃ๐Ÿ“† โธ โธ ๐Ÿ”˜ ๐Ÿ’โ€โ™‚๏ธ, ๐Ÿ•โ” ๐Ÿ“ค `await` ๐Ÿ”˜ โšซ๏ธ.
โœ‹๏ธ ๐ŸŒ ๐Ÿ‘‰ ๐Ÿ› ๏ธ โš™๏ธ ๐Ÿ” ๐Ÿ“Ÿ โฎ๏ธ `async` &amp; `await` ๐Ÿ“š ๐Ÿ•ฐ ๐Ÿ”ฌ โš™๏ธ "๐Ÿ”". โšซ๏ธ โญ ๐Ÿ‘‘ ๐Ÿ”‘ โš’ ๐Ÿšถ, "๐Ÿ”".
## ๐Ÿ
โžก๏ธ ๐Ÿ‘€ ๐ŸŽ ๐Ÿ”ค โšช๏ธโžก๏ธ ๐Ÿ”›:
> ๐Ÿ› โฌ ๐Ÿ โœ”๏ธ ๐Ÿ•โ€๐Ÿฆบ **"๐Ÿ” ๐Ÿ“Ÿ"** โš™๏ธ ๐Ÿ•ณ ๐Ÿค™ **"๐Ÿ”"**, โฎ๏ธ **`async` &amp; `await`** โ•.
๐Ÿ‘ˆ ๐Ÿ”œ โš’ ๐ŸŒ… ๐Ÿ”‘ ๐Ÿ”œ. ๐Ÿ‘ถ
๐ŸŒ ๐Ÿ‘ˆ โšซ๏ธโ” ๐Ÿ‹๏ธ FastAPI (๐Ÿ”˜ ๐Ÿ’ƒ) &amp; โšซ๏ธโ” โš’ โšซ๏ธ โœ”๏ธ โœ… ๐ŸŽ† ๐ŸŽญ.
## ๐Ÿ“ถ ๐Ÿ“ก โ„น
!!! warning
๐Ÿ‘† ๐Ÿ’ช ๐ŸŽฒ ๐Ÿšถ ๐Ÿ‘‰.
๐Ÿ‘‰ ๐Ÿ“ถ ๐Ÿ“ก โ„น โ” **FastAPI** ๐Ÿ‘ท ๐Ÿ”˜.
๐Ÿšฅ ๐Ÿ‘† โœ”๏ธ ๐Ÿ“ก ๐Ÿ’ก (๐Ÿˆถ-๐Ÿ‹, ๐Ÿงต, ๐Ÿซ, โ™’๏ธ.) &amp; ๐Ÿ˜Ÿ ๐Ÿ”ƒ โ” FastAPI ๐Ÿต `async def` ๐Ÿ†š ๐Ÿ˜ `def`, ๐Ÿšถ โคด๏ธ.
### โžก ๐Ÿ› ๏ธ ๐Ÿ”ข
๐Ÿ•โ” ๐Ÿ‘† ๐Ÿ“ฃ *โžก ๐Ÿ› ๏ธ ๐Ÿ”ข* โฎ๏ธ ๐Ÿ˜ `def` โ†ฉ๏ธ `async def`, โšซ๏ธ ๐Ÿƒ ๐Ÿ”ข ๐Ÿงต ๐Ÿ‘ˆ โคด๏ธ โŒ›, โ†ฉ๏ธ โž– ๐Ÿค™ ๐Ÿ”— (โšซ๏ธ ๐Ÿ”œ ๐Ÿซ ๐Ÿ’ฝ).
๐Ÿšฅ ๐Ÿ‘† ๐Ÿ‘Ÿ โšช๏ธโžก๏ธ โž•1๏ธโƒฃ ๐Ÿ” ๐Ÿ› ๏ธ ๐Ÿ‘ˆ ๐Ÿ”จ ๐Ÿšซ ๐Ÿ‘ท ๐ŸŒŒ ๐Ÿ”ฌ ๐Ÿ”› &amp; ๐Ÿ‘† โš™๏ธ โš– ๐Ÿ™ƒ ๐Ÿ“Š-๐Ÿ•ด *โžก ๐Ÿ› ๏ธ ๐Ÿ”ข* โฎ๏ธ โœ… `def` ๐Ÿคช ๐ŸŽญ ๐Ÿ“ˆ (๐Ÿ”ƒ 1๏ธโƒฃ0๏ธโƒฃ0๏ธโƒฃ ๐Ÿ’“), ๐Ÿ™ ๐Ÿ—’ ๐Ÿ‘ˆ **FastAPI** โญ ๐Ÿ”œ ๐Ÿ”„. ๐Ÿ‘ซ ๐Ÿ’ผ, โšซ๏ธ ๐Ÿ‘ป โš™๏ธ `async def` ๐Ÿšฅ ๐Ÿ‘† *โžก ๐Ÿ› ๏ธ ๐Ÿ”ข* โš™๏ธ ๐Ÿ“Ÿ ๐Ÿ‘ˆ ๐ŸŽญ ๐Ÿšง <abbr title="Input/Output: disk reading or writing, network communications.">๐Ÿ‘ค/๐Ÿ…พ</abbr>.
, ๐Ÿ‘ฏโ€โ™‚๏ธ โš , ๐Ÿคž ๐Ÿ‘ˆ **FastAPI** ๐Ÿ”œ [โฉ](/#performance){.internal-link target=_blank} ๐ŸŒ˜ (โš–๏ธ ๐ŸŒ˜ โญ) ๐Ÿ‘† โฎ๏ธ ๐Ÿ› ๏ธ.
### ๐Ÿ”—
๐ŸŽ โœ” [๐Ÿ”—](/tutorial/dependencies/index.md){.internal-link target=_blank}. ๐Ÿšฅ ๐Ÿ”— ๐Ÿฉ `def` ๐Ÿ”ข โ†ฉ๏ธ `async def`, โšซ๏ธ ๐Ÿƒ ๐Ÿ”ข ๐Ÿงต.
### ๐ŸŽง-๐Ÿ”—
๐Ÿ‘† ๐Ÿ’ช โœ”๏ธ ๐Ÿ’— ๐Ÿ”— &amp; [๐ŸŽง-๐Ÿ”—](/tutorial/dependencies/sub-dependencies.md){.internal-link target=_blank} ๐Ÿšซ ๐Ÿ”  ๐ŸŽ (๐Ÿ”ข ๐Ÿ”ข ๐Ÿ”‘), ๐Ÿ‘ซ ๐Ÿ’ช โœ โฎ๏ธ `async def` &amp; โฎ๏ธ ๐Ÿ˜ `def`. โšซ๏ธ ๐Ÿ”œ ๐Ÿ‘ท, &amp; ๐Ÿ• โœ โฎ๏ธ ๐Ÿ˜ `def` ๐Ÿ”œ ๐Ÿค™ ๐Ÿ”› ๐Ÿ”ข ๐Ÿงต (โšช๏ธโžก๏ธ ๐Ÿงต) โ†ฉ๏ธ โž– "โŒ›".
### ๐ŸŽ ๐Ÿš™ ๐Ÿ”ข
๐Ÿ™† ๐ŸŽ ๐Ÿš™ ๐Ÿ”ข ๐Ÿ‘ˆ ๐Ÿ‘† ๐Ÿค™ ๐Ÿ”— ๐Ÿ’ช โœ โฎ๏ธ ๐Ÿ˜ `def` โš–๏ธ `async def` &amp; FastAPI ๐Ÿ† ๐Ÿšซ ๐Ÿ“‰ ๐ŸŒŒ ๐Ÿ‘† ๐Ÿค™ โšซ๏ธ.
๐Ÿ‘‰ ๐Ÿ”… ๐Ÿ”ข ๐Ÿ‘ˆ FastAPI ๐Ÿค™ ๐Ÿ‘†: *โžก ๐Ÿ› ๏ธ ๐Ÿ”ข* &amp; ๐Ÿ”—.
๐Ÿšฅ ๐Ÿ‘† ๐Ÿš™ ๐Ÿ”ข ๐Ÿ˜ ๐Ÿ”ข โฎ๏ธ `def`, โšซ๏ธ ๐Ÿ”œ ๐Ÿค™ ๐Ÿ”— (๐Ÿ‘† โœ โšซ๏ธ ๐Ÿ‘† ๐Ÿ“Ÿ), ๐Ÿšซ ๐Ÿงต, ๐Ÿšฅ ๐Ÿ”ข โœ โฎ๏ธ `async def` โคด๏ธ ๐Ÿ‘† ๐Ÿ”œ `await` ๐Ÿ‘ˆ ๐Ÿ”ข ๐Ÿ•โ” ๐Ÿ‘† ๐Ÿค™ โšซ๏ธ ๐Ÿ‘† ๐Ÿ“Ÿ.
---
๐Ÿ”„, ๐Ÿ‘‰ ๐Ÿ“ถ ๐Ÿ“ก โ„น ๐Ÿ‘ˆ ๐Ÿ”œ ๐ŸŽฒ โš  ๐Ÿšฅ ๐Ÿ‘† ๐Ÿ‘Ÿ ๐Ÿ”Ž ๐Ÿ‘ซ.
โช, ๐Ÿ‘† ๐Ÿ”œ ๐Ÿ‘ โฎ๏ธ ๐Ÿ“„ โšช๏ธโžก๏ธ ๐Ÿ“„ ๐Ÿ”›: <a href="#in-a-hurry">๐Ÿƒ โ“</a>.

34
docs/em/docs/benchmarks.md

@ -0,0 +1,34 @@
# ๐Ÿ“‡
๐Ÿ”ฌ ๐Ÿ‡ธ๐Ÿ‡ฒ ๐Ÿ“‡ ๐ŸŽฆ **FastAPI** ๐Ÿˆธ ๐Ÿƒโ€โ™‚ ๐Ÿ”ฝ Uvicorn <a href="https://www.techempower.com/benchmarks/#section=test&runid=7464e520-0dc2-473d-bd34-dbdfd7e85911&hw=ph&test=query&l=zijzen-7" class="external-link" target="_blank">1๏ธโƒฃ โฉ ๐Ÿ ๐Ÿ› ๏ธ ๐Ÿ’ช</a>, ๐Ÿ•ด ๐Ÿ”› ๐Ÿ’ƒ &amp; Uvicorn ๐Ÿ‘ซ (โš™๏ธ ๐Ÿ”˜ FastAPI). (*)
โœ‹๏ธ ๐Ÿ•โ” โœ… ๐Ÿ“‡ &amp; ๐Ÿ”บ ๐Ÿ‘† ๐Ÿ”œ โœ”๏ธ ๐Ÿ“„ ๐Ÿคฏ.
## ๐Ÿ“‡ &amp; ๐Ÿš…
๐Ÿ•โ” ๐Ÿ‘† โœ… ๐Ÿ“‡, โšซ๏ธ โš  ๐Ÿ‘€ ๐Ÿ“š ๐Ÿงฐ ๐ŸŽ ๐Ÿ†Ž ๐Ÿ”ฌ ๐ŸŒ“.
๐ŸŽฏ, ๐Ÿ‘€ Uvicorn, ๐Ÿ’ƒ &amp; FastAPI ๐Ÿ”ฌ ๐Ÿ‘ฏโ€โ™‚๏ธ (๐Ÿ‘ช ๐Ÿ“š ๐ŸŽ ๐Ÿงฐ).
๐Ÿ™… โš  โŽ ๐Ÿงฐ, ๐Ÿ‘ ๐ŸŽญ โšซ๏ธ ๐Ÿ”œ ๐Ÿคš. &amp; ๐Ÿ† ๐Ÿ“‡ ๐Ÿšซ ๐Ÿ’ฏ ๐ŸŒ– โš’ ๐Ÿšš ๐Ÿงฐ.
๐Ÿ”— ๐Ÿ’–:
* **Uvicorn**: ๐Ÿ”ซ ๐Ÿ’ฝ
* **๐Ÿ’ƒ**: (โš™๏ธ Uvicorn) ๐Ÿ•ธ ๐Ÿ•ธ
* **FastAPI**: (โš™๏ธ ๐Ÿ’ƒ) ๐Ÿ› ๏ธ ๐Ÿ•ธ โฎ๏ธ ๐Ÿ“š ๐ŸŒ– โš’ ๐Ÿ— ๐Ÿ”—, โฎ๏ธ ๐Ÿ’ฝ ๐Ÿ”ฌ, โ™’๏ธ.
* **Uvicorn**:
* ๐Ÿ”œ โœ”๏ธ ๐Ÿ† ๐ŸŽญ, โšซ๏ธ ๐Ÿšซ โœ”๏ธ ๐ŸŒ… โž• ๐Ÿ“Ÿ โ†–๏ธ โšช๏ธโžก๏ธ ๐Ÿ’ฝ โšซ๏ธ.
* ๐Ÿ‘† ๐Ÿšซ๐Ÿ”œ โœ ๐Ÿˆธ Uvicorn ๐Ÿ”—. ๐Ÿ‘ˆ ๐Ÿ”œ โ›“ ๐Ÿ‘ˆ ๐Ÿ‘† ๐Ÿ“Ÿ ๐Ÿ”œ โœ”๏ธ ๐Ÿ”Œ ๐ŸŒ– โš–๏ธ ๐ŸŒ˜, ๐ŸŒ˜, ๐ŸŒ ๐Ÿ“Ÿ ๐Ÿšš ๐Ÿ’ƒ (โš–๏ธ **FastAPI**). &amp; ๐Ÿšฅ ๐Ÿ‘† ๐Ÿ‘ˆ, ๐Ÿ‘† ๐Ÿ ๐Ÿˆธ ๐Ÿ”œ โœ”๏ธ ๐ŸŽ ๐ŸŒฅ โœ”๏ธ โš™๏ธ ๐Ÿ› ๏ธ &amp; ๐Ÿ“‰ ๐Ÿ‘† ๐Ÿ“ฑ ๐Ÿ“Ÿ &amp; ๐Ÿ›.
* ๐Ÿšฅ ๐Ÿ‘† โš– Uvicorn, ๐Ÿ”ฌ โšซ๏ธ ๐Ÿ›ก ๐Ÿ‘ธ, Hypercorn, โœณ, โ™’๏ธ. ๐Ÿˆธ ๐Ÿ’ฝ.
* **๐Ÿ’ƒ**:
* ๐Ÿ”œ โœ”๏ธ โญ ๐Ÿ† ๐ŸŽญ, โฎ๏ธ Uvicorn. ๐Ÿ‘, ๐Ÿ’ƒ โš™๏ธ Uvicorn ๐Ÿƒ. , โšซ๏ธ ๐ŸŽฒ ๐Ÿ’ช ๐Ÿ•ด ๐Ÿคš "๐ŸŒ" ๐ŸŒ˜ Uvicorn โœ”๏ธ ๐Ÿ› ๏ธ ๐ŸŒ… ๐Ÿ“Ÿ.
* โœ‹๏ธ โšซ๏ธ ๐Ÿšš ๐Ÿ‘† ๐Ÿงฐ ๐Ÿ— ๐Ÿ™… ๐Ÿ•ธ ๐Ÿˆธ, โฎ๏ธ ๐Ÿ•น โš“๏ธ ๐Ÿ”› โžก, โ™’๏ธ.
* ๐Ÿšฅ ๐Ÿ‘† โš– ๐Ÿ’ƒ, ๐Ÿ”ฌ โšซ๏ธ ๐Ÿ›ก ๐Ÿคฃ, ๐Ÿบ, โœณ, โ™’๏ธ. ๐Ÿ•ธ ๐Ÿ› ๏ธ (โš–๏ธ ๐Ÿ•ธ).
* **FastAPI**:
* ๐ŸŽ ๐ŸŒŒ ๐Ÿ‘ˆ ๐Ÿ’ƒ โš™๏ธ Uvicorn &amp; ๐Ÿšซ๐Ÿ”œ โฉ ๐ŸŒ˜ โšซ๏ธ, **FastAPI** โš™๏ธ ๐Ÿ’ƒ, โšซ๏ธ ๐Ÿšซ๐Ÿ”œ โฉ ๐ŸŒ˜ โšซ๏ธ.
* FastAPI ๐Ÿšš ๐ŸŒ… โš’ ๐Ÿ”› ๐Ÿ” ๐Ÿ’ƒ. โš’ ๐Ÿ‘ˆ ๐Ÿ‘† ๐ŸŒ– ๐Ÿ•ง ๐Ÿ’ช ๐Ÿ•โ” ๐Ÿ— ๐Ÿ”—, ๐Ÿ’– ๐Ÿ’ฝ ๐Ÿ”ฌ &amp; ๐Ÿ› ๏ธ. &amp; โš™๏ธ โšซ๏ธ, ๐Ÿ‘† ๐Ÿคš ๐Ÿง ๐Ÿงพ ๐Ÿ†“ (๐Ÿง ๐Ÿงพ ๐Ÿšซ ๐Ÿšฎ ๐ŸŒฅ ๐Ÿƒโ€โ™‚ ๐Ÿˆธ, โšซ๏ธ ๐Ÿ— ๐Ÿ”› ๐Ÿ•ด).
* ๐Ÿšฅ ๐Ÿ‘† ๐Ÿšซ โš™๏ธ FastAPI &amp; โš™๏ธ ๐Ÿ’ƒ ๐Ÿ”— (โš–๏ธ โž•1๏ธโƒฃ ๐Ÿงฐ, ๐Ÿ’– ๐Ÿคฃ, ๐Ÿบ, ๐Ÿ†˜, โ™’๏ธ) ๐Ÿ‘† ๐Ÿ”œ โœ”๏ธ ๐Ÿ› ๏ธ ๐ŸŒ ๐Ÿ’ฝ ๐Ÿ”ฌ &amp; ๐Ÿ› ๏ธ ๐Ÿ‘†. , ๐Ÿ‘† ๐Ÿ ๐Ÿˆธ ๐Ÿ”œ โœ”๏ธ ๐ŸŽ ๐ŸŒฅ ๐Ÿšฅ โšซ๏ธ ๐Ÿ— โš™๏ธ FastAPI. &amp; ๐Ÿ“š ๐Ÿ’ผ, ๐Ÿ‘‰ ๐Ÿ’ฝ ๐Ÿ”ฌ &amp; ๐Ÿ› ๏ธ ๐Ÿฆ ๐Ÿ’ธ ๐Ÿ“Ÿ โœ ๐Ÿˆธ.
* , โš™๏ธ FastAPI ๐Ÿ‘† โ™ป ๐Ÿ› ๏ธ ๐Ÿ•ฐ, ๐Ÿ›, โธ ๐Ÿ“Ÿ, &amp; ๐Ÿ‘† ๐Ÿ”œ ๐ŸŽฒ ๐Ÿคš ๐ŸŽ ๐ŸŽญ (โš–๏ธ ๐Ÿ‘) ๐Ÿ‘† ๐Ÿ”œ ๐Ÿšฅ ๐Ÿ‘† ๐Ÿšซ โš™๏ธ โšซ๏ธ (๐Ÿ‘† ๐Ÿ”œ โœ”๏ธ ๐Ÿ› ๏ธ โšซ๏ธ ๐ŸŒ ๐Ÿ‘† ๐Ÿ“Ÿ).
* ๐Ÿšฅ ๐Ÿ‘† โš– FastAPI, ๐Ÿ”ฌ โšซ๏ธ ๐Ÿ›ก ๐Ÿ•ธ ๐Ÿˆธ ๐Ÿ› ๏ธ (โš–๏ธ โš’ ๐Ÿงฐ) ๐Ÿ‘ˆ ๐Ÿšš ๐Ÿ’ฝ ๐Ÿ”ฌ, ๐Ÿ› ๏ธ &amp; ๐Ÿงพ, ๐Ÿ’– ๐Ÿบ-apispec, NestJS, โ™จ, โ™’๏ธ. ๐Ÿ› ๏ธ โฎ๏ธ ๐Ÿ› ๏ธ ๐Ÿง ๐Ÿ’ฝ ๐Ÿ”ฌ, ๐Ÿ› ๏ธ &amp; ๐Ÿงพ.

465
docs/em/docs/contributing.md

@ -0,0 +1,465 @@
# ๐Ÿ› ๏ธ - ๐Ÿ“‰
๐Ÿฅ‡, ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ’š ๐Ÿ‘€ ๐Ÿ”ฐ ๐ŸŒŒ [โ„น FastAPI &amp; ๐Ÿคš โ„น](help-fastapi.md){.internal-link target=_blank}.
## ๐Ÿ› ๏ธ
๐Ÿšฅ ๐Ÿ‘† โช ๐Ÿ–– ๐Ÿ—ƒ &amp; ๐Ÿ‘† ๐Ÿ’ญ ๐Ÿ‘ˆ ๐Ÿ‘† ๐Ÿ’ช โฌ ๐Ÿคฟ ๐Ÿ“Ÿ, ๐Ÿ“ฅ ๐Ÿ“„ โš’ ๐Ÿ†™ ๐Ÿ‘† ๐ŸŒ.
### ๐Ÿ•น ๐ŸŒ โฎ๏ธ `venv`
๐Ÿ‘† ๐Ÿ’ช โœ ๐Ÿ•น ๐ŸŒ ๐Ÿ“ โš™๏ธ ๐Ÿ `venv` ๐Ÿ•น:
<div class="termy">
```console
$ python -m venv env
```
</div>
๐Ÿ‘ˆ ๐Ÿ”œ โœ ๐Ÿ“ `./env/` โฎ๏ธ ๐Ÿ ๐Ÿ’ฑ &amp; โคด๏ธ ๐Ÿ‘† ๐Ÿ”œ ๐Ÿ’ช โŽ ๐Ÿ“ฆ ๐Ÿ‘ˆ โŽ ๐ŸŒ.
### ๐Ÿ”“ ๐ŸŒ
๐Ÿ”“ ๐Ÿ†• ๐ŸŒ โฎ๏ธ:
=== "๐Ÿ’พ, ๐Ÿ‡ธ๐Ÿ‡ป"
<div class="termy">
```console
$ source ./env/bin/activate
```
</div>
=== "๐Ÿšช ๐Ÿ“‹"
<div class="termy">
```console
$ .\env\Scripts\Activate.ps1
```
</div>
=== "๐Ÿšช ๐ŸŽ‰"
โš–๏ธ ๐Ÿšฅ ๐Ÿ‘† โš™๏ธ ๐ŸŽ‰ ๐Ÿ–ฅ (โœ… <a href="https://gitforwindows.org/" class="external-link" target="_blank">๐Ÿ› ๐ŸŽ‰</a>):
<div class="termy">
```console
$ source ./env/Scripts/activate
```
</div>
โœ… โšซ๏ธ ๐Ÿ‘ท, โš™๏ธ:
=== "๐Ÿ’พ, ๐Ÿ‡ธ๐Ÿ‡ป, ๐Ÿšช ๐ŸŽ‰"
<div class="termy">
```console
$ which pip
some/directory/fastapi/env/bin/pip
```
</div>
=== "๐Ÿšช ๐Ÿ“‹"
<div class="termy">
```console
$ Get-Command pip
some/directory/fastapi/env/bin/pip
```
</div>
๐Ÿšฅ โšซ๏ธ ๐ŸŽฆ `pip` ๐Ÿ’ฑ `env/bin/pip` โคด๏ธ โšซ๏ธ ๐Ÿ‘ท. ๐Ÿ‘ถ
โš’ ๐Ÿ’ญ ๐Ÿ‘† โœ”๏ธ ๐Ÿ“ฐ ๐Ÿ– โฌ ๐Ÿ”› ๐Ÿ‘† ๐Ÿ•น ๐ŸŒ โŽ โŒ ๐Ÿ”› โญ ๐Ÿ“ถ:
<div class="termy">
```console
$ python -m pip install --upgrade pip
---> 100%
```
</div>
!!! tip
๐Ÿ”  ๐Ÿ•ฐ ๐Ÿ‘† โŽ ๐Ÿ†• ๐Ÿ“ฆ โฎ๏ธ `pip` ๐Ÿ”ฝ ๐Ÿ‘ˆ ๐ŸŒ, ๐Ÿ”“ ๐ŸŒ ๐Ÿ”„.
๐Ÿ‘‰ โš’ ๐Ÿ’ญ ๐Ÿ‘ˆ ๐Ÿšฅ ๐Ÿ‘† โš™๏ธ ๐Ÿ“ถ ๐Ÿ“‹ โŽ ๐Ÿ‘ˆ ๐Ÿ“ฆ, ๐Ÿ‘† โš™๏ธ 1๏ธโƒฃ โšช๏ธโžก๏ธ ๐Ÿ‘† ๐Ÿ‡ง๐Ÿ‡ฟ ๐ŸŒ &amp; ๐Ÿšซ ๐Ÿ™† ๐ŸŽ ๐Ÿ‘ˆ ๐Ÿ’ช โŽ ๐ŸŒ.
### ๐Ÿ–
โฎ๏ธ ๐Ÿ”“ ๐ŸŒ ๐Ÿ”ฌ ๐Ÿ”›:
<div class="termy">
```console
$ pip install -e ."[dev,doc,test]"
---> 100%
```
</div>
โšซ๏ธ ๐Ÿ”œ โŽ ๐ŸŒ ๐Ÿ”— &amp; ๐Ÿ‘† ๐Ÿ‡ง๐Ÿ‡ฟ FastAPI ๐Ÿ‘† ๐Ÿ‡ง๐Ÿ‡ฟ ๐ŸŒ.
#### โš™๏ธ ๐Ÿ‘† ๐Ÿ‡ง๐Ÿ‡ฟ FastAPI
๐Ÿšฅ ๐Ÿ‘† โœ ๐Ÿ ๐Ÿ“ ๐Ÿ‘ˆ ๐Ÿ—„ &amp; โš™๏ธ FastAPI, &amp; ๐Ÿƒ โšซ๏ธ โฎ๏ธ ๐Ÿ โšช๏ธโžก๏ธ ๐Ÿ‘† ๐Ÿ‡ง๐Ÿ‡ฟ ๐ŸŒ, โšซ๏ธ ๐Ÿ”œ โš™๏ธ ๐Ÿ‘† ๐Ÿ‡ง๐Ÿ‡ฟ FastAPI โ„น ๐Ÿ“Ÿ.
&amp; ๐Ÿšฅ ๐Ÿ‘† โ„น ๐Ÿ‘ˆ ๐Ÿ‡ง๐Ÿ‡ฟ FastAPI โ„น ๐Ÿ“Ÿ, โšซ๏ธ โŽ โฎ๏ธ `-e`, ๐Ÿ•โ” ๐Ÿ‘† ๐Ÿƒ ๐Ÿ‘ˆ ๐Ÿ ๐Ÿ“ ๐Ÿ”„, โšซ๏ธ ๐Ÿ”œ โš™๏ธ ๐Ÿ‹ โฌ FastAPI ๐Ÿ‘† โœ.
๐Ÿ‘ˆ ๐ŸŒŒ, ๐Ÿ‘† ๐Ÿšซ โœ”๏ธ "โŽ" ๐Ÿ‘† ๐Ÿ‡ง๐Ÿ‡ฟ โฌ ๐Ÿ’ช ๐Ÿ’ฏ ๐Ÿ”  ๐Ÿ”€.
### ๐Ÿ“
๐Ÿ“ค โœ ๐Ÿ‘ˆ ๐Ÿ‘† ๐Ÿ’ช ๐Ÿƒ ๐Ÿ‘ˆ ๐Ÿ”œ ๐Ÿ“ &amp; ๐Ÿงน ๐ŸŒ ๐Ÿ‘† ๐Ÿ“Ÿ:
<div class="termy">
```console
$ bash scripts/format.sh
```
</div>
โšซ๏ธ ๐Ÿ”œ ๐Ÿš˜-๐Ÿ˜‡ ๐ŸŒ ๐Ÿ‘† ๐Ÿ—„.
โšซ๏ธ ๐Ÿ˜‡ ๐Ÿ‘ซ โ˜‘, ๐Ÿ‘† ๐Ÿ’ช โœ”๏ธ FastAPI โŽ ๐ŸŒ ๐Ÿ‘† ๐ŸŒ, โฎ๏ธ ๐Ÿ“‹ ๐Ÿ“„ ๐Ÿ”› โš™๏ธ `-e`.
## ๐Ÿฉบ
๐Ÿฅ‡, โš’ ๐Ÿ’ญ ๐Ÿ‘† โš’ ๐Ÿ†™ ๐Ÿ‘† ๐ŸŒ ๐Ÿ”ฌ ๐Ÿ”›, ๐Ÿ‘ˆ ๐Ÿ”œ โŽ ๐ŸŒ ๐Ÿ“„.
๐Ÿงพ โš™๏ธ <a href="https://www.mkdocs.org/" class="external-link" target="_blank">โฌœ</a>.
&amp; ๐Ÿ“ค โž• ๐Ÿงฐ/โœ ๐Ÿฅ‰ ๐Ÿต โœ `./scripts/docs.py`.
!!! tip
๐Ÿ‘† ๐Ÿšซ ๐Ÿ’ช ๐Ÿ‘€ ๐Ÿ“Ÿ `./scripts/docs.py`, ๐Ÿ‘† โš™๏ธ โšซ๏ธ ๐Ÿ“‹ โธ.
๐ŸŒ ๐Ÿงพ โœ ๐Ÿ“ ๐Ÿ“ `./docs/en/`.
๐Ÿ“š ๐Ÿ”ฐ โœ”๏ธ ๐Ÿซ ๐Ÿ“Ÿ.
๐ŸŒ… ๐Ÿ’ผ, ๐Ÿ‘ซ ๐Ÿซ ๐Ÿ“Ÿ โ˜‘ ๐Ÿ ๐Ÿˆธ ๐Ÿ‘ˆ ๐Ÿ’ช ๐Ÿƒ.
๐Ÿ‘, ๐Ÿ‘ˆ ๐Ÿซ ๐Ÿ“Ÿ ๐Ÿšซ โœ ๐Ÿ”˜ โœ, ๐Ÿ‘ซ ๐Ÿ ๐Ÿ“ `./docs_src/` ๐Ÿ“.
&amp; ๐Ÿ‘ˆ ๐Ÿ ๐Ÿ“ ๐Ÿ”Œ/๐Ÿ’‰ ๐Ÿงพ ๐Ÿ•โ” ๐Ÿญ ๐Ÿ•ธ.
### ๐Ÿฉบ ๐Ÿ’ฏ
๐Ÿ† ๐Ÿ’ฏ ๐Ÿค™ ๐Ÿƒ ๐Ÿ›ก ๐Ÿ–ผ โ„น ๐Ÿ“ ๐Ÿงพ.
๐Ÿ‘‰ โ„น โš’ ๐Ÿ’ญ ๐Ÿ‘ˆ:
* ๐Ÿงพ ๐Ÿ†™ ๐Ÿ“….
* ๐Ÿงพ ๐Ÿ–ผ ๐Ÿ’ช ๐Ÿƒ.
* ๐ŸŒ… โš’ ๐Ÿ“” ๐Ÿงพ, ๐Ÿšš ๐Ÿ’ฏ ๐Ÿ’ฐ.
โฎ๏ธ ๐Ÿ‡ง๐Ÿ‡ฟ ๐Ÿ› ๏ธ, ๐Ÿ“ค โœ ๐Ÿ‘ˆ ๐Ÿ— ๐Ÿ•ธ &amp; โœ… ๐Ÿ™† ๐Ÿ”€, ๐Ÿ––-๐Ÿ”ซ:
<div class="termy">
```console
$ python ./scripts/docs.py live
<span style="color: green;">[INFO]</span> Serving on http://127.0.0.1:8008
<span style="color: green;">[INFO]</span> Start watching changes
<span style="color: green;">[INFO]</span> Start detecting changes
```
</div>
โšซ๏ธ ๐Ÿ”œ ๐Ÿฆ ๐Ÿงพ ๐Ÿ”› `http://127.0.0.1:8008`.
๐Ÿ‘ˆ ๐ŸŒŒ, ๐Ÿ‘† ๐Ÿ’ช โœ ๐Ÿงพ/โ„น ๐Ÿ“ &amp; ๐Ÿ‘€ ๐Ÿ”€ ๐Ÿ––.
#### ๐ŸŽ โœณ (๐Ÿ“ฆ)
๐Ÿ‘ฉโ€๐ŸŒพ ๐Ÿ“ฅ ๐ŸŽฆ ๐Ÿ‘† โ” โš™๏ธ โœ `./scripts/docs.py` โฎ๏ธ `python` ๐Ÿ“‹ ๐Ÿ”—.
โœ‹๏ธ ๐Ÿ‘† ๐Ÿ’ช โš™๏ธ <a href="https://typer.tiangolo.com/typer-cli/" class="external-link" target="_blank">๐ŸŽ โœณ</a>, &amp; ๐Ÿ‘† ๐Ÿ”œ ๐Ÿคš โœ ๐Ÿ‘† ๐Ÿ“ถ ๐Ÿ“‹ โฎ๏ธ โŽ ๐Ÿ› ๏ธ.
๐Ÿšฅ ๐Ÿ‘† โŽ ๐ŸŽ โœณ, ๐Ÿ‘† ๐Ÿ’ช โŽ ๐Ÿ› ๏ธ โฎ๏ธ:
<div class="termy">
```console
$ typer --install-completion
zsh completion installed in /home/user/.bashrc.
Completion will take effect once you restart the terminal.
```
</div>
### ๐Ÿ“ฑ &amp; ๐Ÿฉบ ๐ŸŽ ๐Ÿ•ฐ
๐Ÿšฅ ๐Ÿ‘† ๐Ÿƒ ๐Ÿ–ผ โฎ๏ธ, โœ…:
<div class="termy">
```console
$ uvicorn tutorial001:app --reload
<span style="color: green;">INFO</span>: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
```
</div>
Uvicorn ๐Ÿ”ข ๐Ÿ”œ โš™๏ธ โ›ด `8000`, ๐Ÿงพ ๐Ÿ”› โ›ด `8008` ๐Ÿ† ๐Ÿšซ โš”.
### โœ
โ„น โฎ๏ธ โœ ๐Ÿ“ถ ๐ŸŒ… ๐Ÿ‘ โ— &amp; โšซ๏ธ ๐Ÿ’ช ๐Ÿšซ ๐Ÿ”จ ๐Ÿต โ„น โšช๏ธโžก๏ธ ๐Ÿ‘ช. ๐Ÿ‘ถ ๐Ÿ‘ถ
๐Ÿ“ฅ ๐Ÿ“ถ โ„น โฎ๏ธ โœ.
#### ๐Ÿ’โ€โ™‚ &amp; ๐Ÿ“„
* โœ… โณ <a href="https://github.com/tiangolo/fastapi/pulls" class="external-link" target="_blank">โ™ป ๐Ÿšฒ ๐Ÿ“จ</a> ๐Ÿ‘† ๐Ÿ‡ช๐Ÿ‡ธ &amp; ๐Ÿšฎ ๐Ÿ“„ โœ” ๐Ÿ”€ โš–๏ธ โœ” ๐Ÿ‘ซ.
!!! tip
๐Ÿ‘† ๐Ÿ’ช <a href="https://help.github.com/en/github/collaborating-with-issues-and-pull-requests/commenting-on-a-pull-request" class="external-link" target="_blank">๐Ÿšฎ ๐Ÿค โฎ๏ธ ๐Ÿ”€ ๐Ÿ”‘</a> โ™ป ๐Ÿšฒ ๐Ÿ“จ.
โœ… ๐Ÿฉบ ๐Ÿ”ƒ <a href="https://help.github.com/en/github/collaborating-with-issues-and-pull-requests/about-pull-request-reviews" class="external-link" target="_blank">โŽ ๐Ÿšฒ ๐Ÿ“จ ๐Ÿ“„</a> โœ” โšซ๏ธ โš–๏ธ ๐Ÿ“จ ๐Ÿ”€.
* โœ… <a href="https://github.com/tiangolo/fastapi/issues" class="external-link" target="_blank">โ”</a> ๐Ÿ‘€ ๐Ÿšฅ ๐Ÿ“ค 1๏ธโƒฃ ๐Ÿ› ๏ธ โœ ๐Ÿ‘† ๐Ÿ‡ช๐Ÿ‡ธ.
* ๐Ÿšฎ ๐Ÿ‘ ๐Ÿšฒ ๐Ÿ“จ ๐Ÿ“ ๐Ÿ“ƒ ๐Ÿ’ฌ. ๐Ÿ‘ˆ ๐Ÿ”œ โš’ โšซ๏ธ ๐ŸŒ… โฉ ๐ŸŽ ๐Ÿ“„ โšซ๏ธ.
๐Ÿ‡ช๐Ÿ‡ธ ๐Ÿ‘ค ๐Ÿšซ ๐Ÿ’ฌ, ๐Ÿ‘ค ๐Ÿ”œ โŒ› ๐Ÿ“š ๐ŸŽ ๐Ÿ“„ โœ โญ ๐Ÿ”—.
* ๐Ÿ‘† ๐Ÿ’ช โœ… ๐Ÿšฅ ๐Ÿ“ค โœ ๐Ÿ‘† ๐Ÿ‡ช๐Ÿ‡ธ &amp; ๐Ÿšฎ ๐Ÿ“„ ๐Ÿ‘ซ, ๐Ÿ‘ˆ ๐Ÿ”œ โ„น ๐Ÿ‘ค ๐Ÿ’ญ ๐Ÿ‘ˆ โœ โ˜‘ &amp; ๐Ÿ‘ค ๐Ÿ’ช ๐Ÿ”— โšซ๏ธ.
* โš™๏ธ ๐ŸŽ ๐Ÿ ๐Ÿ–ผ &amp; ๐Ÿ•ด ๐Ÿ’ฌ โœ ๐Ÿฉบ. ๐Ÿ‘† ๐Ÿšซ โœ”๏ธ ๐Ÿ”€ ๐Ÿ•ณ ๐Ÿ‘‰ ๐Ÿ‘ท.
* โš™๏ธ ๐ŸŽ ๐Ÿ–ผ, ๐Ÿ“ ๐Ÿ“›, &amp; ๐Ÿ”—. ๐Ÿ‘† ๐Ÿšซ โœ”๏ธ ๐Ÿ”€ ๐Ÿ•ณ โšซ๏ธ ๐Ÿ‘ท.
* โœ… 2๏ธโƒฃ-๐Ÿ”ค ๐Ÿ“Ÿ ๐Ÿ‡ช๐Ÿ‡ธ ๐Ÿ‘† ๐Ÿ’š ๐Ÿ’ฌ ๐Ÿ‘† ๐Ÿ’ช โš™๏ธ ๐Ÿ“ <a href="https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes" class="external-link" target="_blank">๐Ÿ“‡ ๐Ÿ’พ 6๏ธโƒฃ3๏ธโƒฃ9๏ธโƒฃ-1๏ธโƒฃ ๐Ÿ“Ÿ</a>.
#### โ™ป ๐Ÿ‡ช๐Ÿ‡ธ
โžก๏ธ ๐Ÿ’ฌ ๐Ÿ‘† ๐Ÿ’š ๐Ÿ’ฌ ๐Ÿ“ƒ ๐Ÿ‡ช๐Ÿ‡ธ ๐Ÿ‘ˆ โช โœ”๏ธ โœ ๐Ÿ“ƒ, ๐Ÿ’– ๐Ÿ‡ช๐Ÿ‡ธ.
๐Ÿ’ผ ๐Ÿ‡ช๐Ÿ‡ธ, 2๏ธโƒฃ-๐Ÿ”ค ๐Ÿ“Ÿ `es`. , ๐Ÿ“ ๐Ÿ‡ช๐Ÿ‡ธ โœ ๐Ÿ”Ž `docs/es/`.
!!! tip
๐Ÿ‘‘ ("๐Ÿ›‚") ๐Ÿ‡ช๐Ÿ‡ธ ๐Ÿ‡ช๐Ÿ‡ธ, ๐Ÿ”Ž `docs/en/`.
๐Ÿ”œ ๐Ÿƒ ๐Ÿ–– ๐Ÿ’ฝ ๐Ÿฉบ ๐Ÿ‡ช๐Ÿ‡ธ:
<div class="termy">
```console
// Use the command "live" and pass the language code as a CLI argument
$ python ./scripts/docs.py live es
<span style="color: green;">[INFO]</span> Serving on http://127.0.0.1:8008
<span style="color: green;">[INFO]</span> Start watching changes
<span style="color: green;">[INFO]</span> Start detecting changes
```
</div>
๐Ÿ”œ ๐Ÿ‘† ๐Ÿ’ช ๐Ÿšถ <a href="http://127.0.0.1:8008" class="external-link" target="_blank">http://127.0.0.1:8008</a> &amp; ๐Ÿ‘€ ๐Ÿ‘† ๐Ÿ”€ ๐Ÿ––.
๐Ÿšฅ ๐Ÿ‘† ๐Ÿ‘€ FastAPI ๐Ÿฉบ ๐Ÿ•ธ, ๐Ÿ‘† ๐Ÿ”œ ๐Ÿ‘€ ๐Ÿ‘ˆ ๐Ÿ”  ๐Ÿ‡ช๐Ÿ‡ธ โœ”๏ธ ๐ŸŒ ๐Ÿ“ƒ. โœ‹๏ธ ๐Ÿ“ƒ ๐Ÿšซ ๐Ÿ’ฌ &amp; โœ”๏ธ ๐Ÿ“จ ๐Ÿ”ƒ โŒ โœ.
โœ‹๏ธ ๐Ÿ•โ” ๐Ÿ‘† ๐Ÿƒ โšซ๏ธ ๐ŸŒ ๐Ÿ’– ๐Ÿ‘‰, ๐Ÿ‘† ๐Ÿ”œ ๐Ÿ•ด ๐Ÿ‘€ ๐Ÿ“ƒ ๐Ÿ‘ˆ โช ๐Ÿ’ฌ.
๐Ÿ”œ โžก๏ธ ๐Ÿ’ฌ ๐Ÿ‘ˆ ๐Ÿ‘† ๐Ÿ’š ๐Ÿšฎ โœ ๐Ÿ“„ [โš’](features.md){.internal-link target=_blank}.
* ๐Ÿ“ ๐Ÿ“:
```
docs/en/docs/features.md
```
* ๐Ÿ“‹ โšซ๏ธ โšซ๏ธโ” ๐ŸŽ ๐Ÿ—บ โœ‹๏ธ ๐Ÿ‡ช๐Ÿ‡ธ ๐Ÿ‘† ๐Ÿ’š ๐Ÿ’ฌ, โœ…:
```
docs/es/docs/features.md
```
!!! tip
๐Ÿ‘€ ๐Ÿ‘ˆ ๐Ÿ•ด ๐Ÿ”€ โžก &amp; ๐Ÿ“ ๐Ÿ“› ๐Ÿ‡ช๐Ÿ‡ธ ๐Ÿ“Ÿ, โšช๏ธโžก๏ธ `en` `es`.
* ๐Ÿ”œ ๐Ÿ“‚ โฌœ ๐Ÿ“ ๐Ÿ“ ๐Ÿ‡ช๐Ÿ‡ธ:
```
docs/en/mkdocs.yml
```
* ๐Ÿ”Ž ๐Ÿฅ‰ ๐ŸŒโ” ๐Ÿ‘ˆ `docs/features.md` ๐Ÿ”Ž ๐Ÿ“ ๐Ÿ“. ๐Ÿ‘ฑ ๐Ÿ’–:
```YAML hl_lines="8"
site_name: FastAPI
# More stuff
nav:
- FastAPI: index.md
- Languages:
- en: /
- es: /es/
- features.md
```
* ๐Ÿ“‚ โฌœ ๐Ÿ“ ๐Ÿ“ ๐Ÿ‡ช๐Ÿ‡ธ ๐Ÿ‘† โœ, โœ…:
```
docs/es/mkdocs.yml
```
* ๐Ÿšฎ โšซ๏ธ ๐Ÿ“ค โ˜‘ ๐ŸŽ ๐Ÿ—บ โšซ๏ธ ๐Ÿ‡ช๐Ÿ‡ธ, โœ…:
```YAML hl_lines="8"
site_name: FastAPI
# More stuff
nav:
- FastAPI: index.md
- Languages:
- en: /
- es: /es/
- features.md
```
โš’ ๐Ÿ’ญ ๐Ÿ‘ˆ ๐Ÿšฅ ๐Ÿ“ค ๐ŸŽ โ›”, ๐Ÿ†• โ›” โฎ๏ธ ๐Ÿ‘† โœ โšซ๏ธโ” ๐ŸŽ โœ” ๐Ÿ‡ช๐Ÿ‡ธ โฌ.
๐Ÿšฅ ๐Ÿ‘† ๐Ÿšถ ๐Ÿ‘† ๐Ÿ–ฅ ๐Ÿ‘† ๐Ÿ”œ ๐Ÿ‘€ ๐Ÿ‘ˆ ๐Ÿ”œ ๐Ÿฉบ ๐ŸŽฆ ๐Ÿ‘† ๐Ÿ†• ๐Ÿ“„. ๐Ÿ‘ถ
๐Ÿ”œ ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ’ฌ โšซ๏ธ ๐ŸŒ &amp; ๐Ÿ‘€ โ” โšซ๏ธ ๐Ÿ‘€ ๐Ÿ‘† ๐Ÿ–Š ๐Ÿ“.
#### ๐Ÿ†• ๐Ÿ‡ช๐Ÿ‡ธ
โžก๏ธ ๐Ÿ’ฌ ๐Ÿ‘ˆ ๐Ÿ‘† ๐Ÿ’š ๐Ÿšฎ โœ ๐Ÿ‡ช๐Ÿ‡ธ ๐Ÿ‘ˆ ๐Ÿšซ ๐Ÿ’ฌ, ๐Ÿšซ ๐Ÿ“ƒ.
โžก๏ธ ๐Ÿ’ฌ ๐Ÿ‘† ๐Ÿ’š ๐Ÿšฎ โœ ๐Ÿ‡ญ๐Ÿ‡น, &amp; โšซ๏ธ ๐Ÿšซ ๐Ÿ“ค ๐Ÿฉบ.
โœ… ๐Ÿ”— โšช๏ธโžก๏ธ ๐Ÿ”›, ๐Ÿ“Ÿ "๐Ÿ‡ญ๐Ÿ‡น" `ht`.
โญ ๐Ÿ” ๐Ÿƒ โœ ๐Ÿ— ๐Ÿ†• โœ ๐Ÿ“:
<div class="termy">
```console
// Use the command new-lang, pass the language code as a CLI argument
$ python ./scripts/docs.py new-lang ht
Successfully initialized: docs/ht
Updating ht
Updating en
```
</div>
๐Ÿ”œ ๐Ÿ‘† ๐Ÿ’ช โœ… ๐Ÿ‘† ๐Ÿ“Ÿ ๐Ÿ‘จโ€๐ŸŽจ โณ โœ ๐Ÿ“ `docs/ht/`.
!!! tip
โœ ๐Ÿฅ‡ ๐Ÿšฒ ๐Ÿ“จ โฎ๏ธ ๐Ÿ‘‰, โš’ ๐Ÿ†™ ๐Ÿ“ณ ๐Ÿ†• ๐Ÿ‡ช๐Ÿ‡ธ, โญ โŽ โœ.
๐Ÿ‘ˆ ๐ŸŒŒ ๐ŸŽ ๐Ÿ’ช โ„น โฎ๏ธ ๐ŸŽ ๐Ÿ“ƒ โช ๐Ÿ‘† ๐Ÿ‘ท ๐Ÿ”› ๐Ÿฅ‡ ๐Ÿ•. ๐Ÿ‘ถ
โ–ถ๏ธ โœ ๐Ÿ‘‘ ๐Ÿ“ƒ, `docs/ht/index.md`.
โคด๏ธ ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ˜ฃ โฎ๏ธ โฎ๏ธ ๐Ÿ‘ฉโ€๐ŸŒพ, "โ™ป ๐Ÿ‡ช๐Ÿ‡ธ".
##### ๐Ÿ†• ๐Ÿ‡ช๐Ÿ‡ธ ๐Ÿšซ ๐Ÿ•โ€๐Ÿฆบ
๐Ÿšฅ ๐Ÿ•โ” ๐Ÿƒโ€โ™‚ ๐Ÿ–– ๐Ÿ’ฝ โœ ๐Ÿ‘† ๐Ÿคš โŒ ๐Ÿ”ƒ ๐Ÿ‡ช๐Ÿ‡ธ ๐Ÿšซ โž– ๐Ÿ•โ€๐Ÿฆบ, ๐Ÿ•ณ ๐Ÿ’–:
```
raise TemplateNotFound(template)
jinja2.exceptions.TemplateNotFound: partials/language/xx.html
```
๐Ÿ‘ˆ โ›“ ๐Ÿ‘ˆ ๐ŸŽข ๐Ÿšซ ๐Ÿ•โ€๐Ÿฆบ ๐Ÿ‘ˆ ๐Ÿ‡ช๐Ÿ‡ธ (๐Ÿ‘‰ ๐Ÿ’ผ, โฎ๏ธ โŒ 2๏ธโƒฃ-๐Ÿ”ค ๐Ÿ“Ÿ `xx`).
โœ‹๏ธ ๐Ÿšซ ๐Ÿ˜Ÿ, ๐Ÿ‘† ๐Ÿ’ช โš’ ๐ŸŽข ๐Ÿ‡ช๐Ÿ‡ธ ๐Ÿ‡ช๐Ÿ‡ธ &amp; โคด๏ธ ๐Ÿ’ฌ ๐ŸŽš ๐Ÿฉบ.
๐Ÿšฅ ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ‘ˆ, โœ `mkdocs.yml` ๐Ÿ‘† ๐Ÿ†• ๐Ÿ‡ช๐Ÿ‡ธ, โšซ๏ธ ๐Ÿ”œ โœ”๏ธ ๐Ÿ•ณ ๐Ÿ’–:
```YAML hl_lines="5"
site_name: FastAPI
# More stuff
theme:
# More stuff
language: xx
```
๐Ÿ”€ ๐Ÿ‘ˆ ๐Ÿ‡ช๐Ÿ‡ธ โšช๏ธโžก๏ธ `xx` (โšช๏ธโžก๏ธ ๐Ÿ‘† ๐Ÿ‡ช๐Ÿ‡ธ ๐Ÿ“Ÿ) `en`.
โคด๏ธ ๐Ÿ‘† ๐Ÿ’ช โ–ถ๏ธ ๐Ÿ–– ๐Ÿ’ฝ ๐Ÿ”„.
#### ๐ŸŽฎ ๐Ÿ
๐Ÿ•โ” ๐Ÿ‘† โš™๏ธ โœ `./scripts/docs.py` โฎ๏ธ `live` ๐Ÿ“‹ โšซ๏ธ ๐Ÿ•ด ๐ŸŽฆ ๐Ÿ“ &amp; โœ ๐Ÿ’ช โฎ๏ธ ๐Ÿ‡ช๐Ÿ‡ธ.
โœ‹๏ธ ๐Ÿ• ๐Ÿ‘† ๐Ÿ”จ, ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ’ฏ โšซ๏ธ ๐ŸŒ โšซ๏ธ ๐Ÿ”œ ๐Ÿ‘€ ๐Ÿ’ณ.
๐Ÿ‘ˆ, ๐Ÿฅ‡ ๐Ÿ— ๐ŸŒ ๐Ÿฉบ:
<div class="termy">
```console
// Use the command "build-all", this will take a bit
$ python ./scripts/docs.py build-all
Updating es
Updating en
Building docs for: en
Building docs for: es
Successfully built docs for: es
Copying en index.md to README.md
```
</div>
๐Ÿ‘ˆ ๐Ÿ— ๐ŸŒ ๐Ÿฉบ `./docs_build/` ๐Ÿ”  ๐Ÿ‡ช๐Ÿ‡ธ. ๐Ÿ‘‰ ๐Ÿ”Œ โŽ ๐Ÿ™† ๐Ÿ“ โฎ๏ธ โŒ โœ, โฎ๏ธ ๐Ÿ—’ ๐Ÿ’ฌ ๐Ÿ‘ˆ "๐Ÿ‘‰ ๐Ÿ“ ๐Ÿšซ โœ”๏ธ โœ". โœ‹๏ธ ๐Ÿ‘† ๐Ÿšซ โœ”๏ธ ๐Ÿ•ณ โฎ๏ธ ๐Ÿ‘ˆ ๐Ÿ“.
โคด๏ธ โšซ๏ธ ๐Ÿ— ๐ŸŒ ๐Ÿ‘ˆ ๐Ÿ”ฌ โฌœ ๐Ÿ•ธ ๐Ÿ”  ๐Ÿ‡ช๐Ÿ‡ธ, ๐ŸŒ€ ๐Ÿ‘ซ, &amp; ๐Ÿ— ๐Ÿ ๐Ÿ”ข `./site/`.
โคด๏ธ ๐Ÿ‘† ๐Ÿ’ช ๐Ÿฆ ๐Ÿ‘ˆ โฎ๏ธ ๐Ÿ“‹ `serve`:
<div class="termy">
```console
// Use the command "serve" after running "build-all"
$ python ./scripts/docs.py serve
Warning: this is a very simple server. For development, use mkdocs serve instead.
This is here only to preview a site with translations already built.
Make sure you run the build-all command first.
Serving at: http://127.0.0.1:8008
```
</div>
## ๐Ÿ’ฏ
๐Ÿ“ค โœ ๐Ÿ‘ˆ ๐Ÿ‘† ๐Ÿ’ช ๐Ÿƒ ๐ŸŒ ๐Ÿ’ฏ ๐ŸŒ ๐Ÿ“Ÿ &amp; ๐Ÿ— ๐Ÿ’ฐ ๐Ÿ“„ ๐Ÿ•ธ:
<div class="termy">
```console
$ bash scripts/test-cov-html.sh
```
</div>
๐Ÿ‘‰ ๐Ÿ“‹ ๐Ÿ— ๐Ÿ“ `./htmlcov/`, ๐Ÿšฅ ๐Ÿ‘† ๐Ÿ“‚ ๐Ÿ“ `./htmlcov/index.html` ๐Ÿ‘† ๐Ÿ–ฅ, ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ”ฌ ๐Ÿ–ฅ ๐Ÿ‡น๐Ÿ‡ผ ๐Ÿ“Ÿ ๐Ÿ‘ˆ ๐Ÿ“” ๐Ÿ’ฏ, &amp; ๐Ÿ‘€ ๐Ÿšฅ ๐Ÿ“ค ๐Ÿ™† ๐Ÿ‡น๐Ÿ‡ผ โŒ.

311
docs/em/docs/deployment/concepts.md

@ -0,0 +1,311 @@
# ๐Ÿ› ๏ธ ๐Ÿ”ง
๐Ÿ•โ” ๐Ÿ› ๏ธ **FastAPI** ๐Ÿˆธ, โš–๏ธ ๐Ÿค™, ๐Ÿ™† ๐Ÿ†Ž ๐Ÿ•ธ ๐Ÿ› ๏ธ, ๐Ÿ“ค ๐Ÿ“š ๐Ÿ”ง ๐Ÿ‘ˆ ๐Ÿ‘† ๐ŸŽฒ ๐Ÿ’… ๐Ÿ”ƒ, &amp; โš™๏ธ ๐Ÿ‘ซ ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ”Ž **๐Ÿ† โ˜‘** ๐ŸŒŒ **๐Ÿ› ๏ธ ๐Ÿ‘† ๐Ÿˆธ**.
โš  ๐Ÿ”ง:
* ๐Ÿ’‚โ€โ™‚ - ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ”
* ๐Ÿƒโ€โ™‚ ๐Ÿ”› ๐Ÿ•ด
* โ
* ๐Ÿงฌ (๐Ÿ”ข ๐Ÿ› ๏ธ ๐Ÿƒ)
* ๐Ÿ’พ
* โฎ๏ธ ๐Ÿ” โญ โ–ถ๏ธ
๐Ÿ‘ฅ ๐Ÿ”œ ๐Ÿ‘€ โ” ๐Ÿ‘ซ ๐Ÿ”œ ๐Ÿ“‰ **๐Ÿ› ๏ธ**.
๐Ÿ”š, ๐Ÿ† ๐ŸŽฏ ๐Ÿ’ช **๐Ÿฆ ๐Ÿ‘† ๐Ÿ› ๏ธ ๐Ÿ‘ฉโ€๐Ÿ’ป** ๐ŸŒŒ ๐Ÿ‘ˆ **๐Ÿ”**, **โŽ ๐Ÿ“‰**, &amp; โš™๏ธ **๐Ÿ“Š โ„น** (๐Ÿ–ผ ๐Ÿ›ฐ ๐Ÿ’ฝ/๐Ÿ•น ๐ŸŽฐ) โ™ป ๐Ÿ’ช. ๐Ÿ‘ถ
๐Ÿ‘ค ๐Ÿ”œ ๐Ÿ’ฌ ๐Ÿ‘† ๐Ÿ– ๐ŸŒ– ๐Ÿ”ƒ ๐Ÿ‘ซ **๐Ÿ”ง** ๐Ÿ“ฅ, &amp; ๐Ÿ‘ˆ ๐Ÿ”œ ๐Ÿคž ๐Ÿค ๐Ÿ‘† **๐Ÿค”** ๐Ÿ‘† ๐Ÿ”œ ๐Ÿ’ช ๐Ÿ’ญ โ” ๐Ÿ› ๏ธ ๐Ÿ‘† ๐Ÿ› ๏ธ ๐Ÿ“ถ ๐ŸŽ ๐ŸŒ, ๐ŸŽฒ **๐Ÿ”ฎ** ๐Ÿ• ๐Ÿ‘ˆ ๐Ÿšซ ๐Ÿ”€.
๐Ÿค” ๐Ÿ‘ซ ๐Ÿ”ง, ๐Ÿ‘† ๐Ÿ”œ ๐Ÿ’ช **๐Ÿ”ฌ &amp; ๐Ÿ”ง** ๐Ÿ† ๐ŸŒŒ ๐Ÿ› ๏ธ **๐Ÿ‘† ๐Ÿ‘ ๐Ÿ”—**.
โญ ๐Ÿ“ƒ, ๐Ÿ‘ค ๐Ÿ”œ ๐Ÿค ๐Ÿ‘† ๐ŸŒ… **๐Ÿงฑ ๐Ÿฎ** ๐Ÿ› ๏ธ FastAPI ๐Ÿˆธ.
โœ‹๏ธ ๐Ÿ”œ, โžก๏ธ โœ… ๐Ÿ‘‰ โš  **โš› ๐Ÿ’ญ**. ๐Ÿ‘ซ ๐Ÿ”ง โœ” ๐Ÿ™† ๐ŸŽ ๐Ÿ†Ž ๐Ÿ•ธ ๐Ÿ› ๏ธ. ๐Ÿ‘ถ
## ๐Ÿ’‚โ€โ™‚ - ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ”
[โฎ๏ธ ๐Ÿ“ƒ ๐Ÿ”ƒ ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ”](./https.md){.internal-link target=_blank} ๐Ÿ‘ฅ ๐Ÿ‡ญ๐Ÿ‡ฒ ๐Ÿ”ƒ โ” ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ” ๐Ÿšš ๐Ÿ” ๐Ÿ‘† ๐Ÿ› ๏ธ.
๐Ÿ‘ฅ ๐Ÿ‘€ ๐Ÿ‘ˆ ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ” ๐Ÿ›Ž ๐Ÿšš ๐Ÿฆฒ **๐Ÿ”ข** ๐Ÿ‘† ๐Ÿˆธ ๐Ÿ’ฝ, **๐Ÿค โŽ ๐Ÿ—ณ**.
&amp; ๐Ÿ“ค โœ”๏ธ ๐Ÿ•ณ ๐Ÿˆš **โ™ป ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ” ๐Ÿ“„**, โšซ๏ธ ๐Ÿ’ช ๐ŸŽ ๐Ÿฆฒ โš–๏ธ โšซ๏ธ ๐Ÿ’ช ๐Ÿ•ณ ๐ŸŽ.
### ๐Ÿ–ผ ๐Ÿงฐ ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ”
๐Ÿงฐ ๐Ÿ‘† ๐Ÿ’ช โš™๏ธ ๐Ÿค โŽ ๐Ÿ—ณ:
* Traefik
* ๐Ÿ” ๐Ÿต ๐Ÿ“„ ๐Ÿ”• ๐Ÿ‘ถ
* ๐Ÿ“ฅ
* ๐Ÿ” ๐Ÿต ๐Ÿ“„ ๐Ÿ”• ๐Ÿ‘ถ
* ๐Ÿ‘Œ
* โฎ๏ธ ๐Ÿ”ข ๐Ÿฆฒ ๐Ÿ’– Certbot ๐Ÿ“„ ๐Ÿ”•
* โœณ
* โฎ๏ธ ๐Ÿ”ข ๐Ÿฆฒ ๐Ÿ’– Certbot ๐Ÿ“„ ๐Ÿ”•
* Kubernete โฎ๏ธ ๐Ÿšง ๐Ÿ•น ๐Ÿ’– ๐Ÿ‘Œ
* โฎ๏ธ ๐Ÿ”ข ๐Ÿฆฒ ๐Ÿ’– ๐Ÿ›‚-๐Ÿ‘จโ€๐Ÿ’ผ ๐Ÿ“„ ๐Ÿ”•
* ๐Ÿต ๐Ÿ”˜ โ˜ ๐Ÿ•โ€๐Ÿฆบ ๐Ÿ• ๐Ÿ‘ซ ๐Ÿ•โ€๐Ÿฆบ (โœ ๐Ÿ”› ๐Ÿ‘ถ)
โž•1๏ธโƒฃ ๐ŸŽ› ๐Ÿ‘ˆ ๐Ÿ‘† ๐Ÿ’ช โš™๏ธ **โ˜ ๐Ÿ•โ€๐Ÿฆบ** ๐Ÿ‘ˆ ๐Ÿ”จ ๐ŸŒ– ๐Ÿ‘ท โœ… โš’ ๐Ÿ†™ ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ”. โšซ๏ธ ๐Ÿ’ช โœ”๏ธ ๐Ÿšซ โš–๏ธ ๐Ÿˆš ๐Ÿ‘† ๐ŸŒ…, โ™’๏ธ. โœ‹๏ธ ๐Ÿ‘ˆ ๐Ÿ’ผ, ๐Ÿ‘† ๐Ÿšซ๐Ÿ”œ โœ”๏ธ โš’ ๐Ÿ†™ ๐Ÿค โŽ ๐Ÿ—ณ ๐Ÿ‘†.
๐Ÿ‘ค ๐Ÿ”œ ๐ŸŽฆ ๐Ÿ‘† ๐Ÿงฑ ๐Ÿ–ผ โญ ๐Ÿ“ƒ.
---
โคด๏ธ โญ ๐Ÿ”ง ๐Ÿค” ๐ŸŒ ๐Ÿ”ƒ ๐Ÿ“‹ ๐Ÿƒ ๐Ÿ‘† โ˜‘ ๐Ÿ› ๏ธ (โœ… Uvicorn).
## ๐Ÿ“‹ &amp; ๐Ÿ› ๏ธ
๐Ÿ‘ฅ ๐Ÿ”œ ๐Ÿ’ฌ ๐Ÿ“š ๐Ÿ”ƒ ๐Ÿƒ "**๐Ÿ› ๏ธ**", โšซ๏ธ โš  โœ”๏ธ โ˜ฏ ๐Ÿ”ƒ โšซ๏ธโ” โšซ๏ธ โ›“, &amp; โšซ๏ธโ” ๐Ÿ”บ โฎ๏ธ ๐Ÿ”ค "**๐Ÿ“‹**".
### โšซ๏ธโ” ๐Ÿ“‹
๐Ÿ”ค **๐Ÿ“‹** ๐Ÿ›Ž โš™๏ธ ๐Ÿ”ฌ ๐Ÿ“š ๐Ÿ‘œ:
* **๐Ÿ“Ÿ** ๐Ÿ‘ˆ ๐Ÿ‘† โœ, **๐Ÿ ๐Ÿ“**.
* **๐Ÿ“** ๐Ÿ‘ˆ ๐Ÿ’ช **๐Ÿ› ๏ธ** ๐Ÿƒโ€โ™‚ โš™๏ธ, ๐Ÿ–ผ: `python`, `python.exe` โš–๏ธ `uvicorn`.
* ๐ŸŽฏ ๐Ÿ“‹ โช โšซ๏ธ **๐Ÿƒโ€โ™‚** ๐Ÿ”› ๐Ÿ— โš™๏ธ, โš™๏ธ ๐Ÿ’ฝ, &amp; โ™ป ๐Ÿ‘œ ๐Ÿ”› ๐Ÿ’พ. ๐Ÿ‘‰ ๐Ÿค™ **๐Ÿ› ๏ธ**.
### โšซ๏ธโ” ๐Ÿ› ๏ธ
๐Ÿ”ค **๐Ÿ› ๏ธ** ๐Ÿ›Ž โš™๏ธ ๐ŸŒ– ๐ŸŽฏ ๐ŸŒŒ, ๐Ÿ•ด ๐Ÿ”— ๐Ÿ‘œ ๐Ÿ‘ˆ ๐Ÿƒ ๐Ÿƒโ€โ™‚ โš™๏ธ (๐Ÿ’– ๐Ÿ โ˜ ๐Ÿ”›):
* ๐ŸŽฏ ๐Ÿ“‹ โช โšซ๏ธ **๐Ÿƒโ€โ™‚** ๐Ÿ”› ๐Ÿƒโ€โ™‚ โš™๏ธ.
* ๐Ÿ‘‰ ๐Ÿšซ ๐Ÿ”— ๐Ÿ“, ๐Ÿšซ ๐Ÿ“Ÿ, โšซ๏ธ ๐Ÿ”— **๐ŸŽฏ** ๐Ÿ‘œ ๐Ÿ‘ˆ โž– **๐Ÿ› ๏ธ** &amp; ๐Ÿ”„ ๐Ÿƒโ€โ™‚ โš™๏ธ.
* ๐Ÿ™† ๐Ÿ“‹, ๐Ÿ™† ๐Ÿ“Ÿ, **๐Ÿ’ช ๐Ÿ•ด ๐Ÿ‘œ** ๐Ÿ•โ” โšซ๏ธ โž– **๐Ÿ› ๏ธ**. , ๐Ÿ•โ” ๐Ÿ“ค **๐Ÿ› ๏ธ ๐Ÿƒ**.
* ๐Ÿ› ๏ธ ๐Ÿ’ช **โŽ** (โš–๏ธ "๐Ÿ’ฅ") ๐Ÿ‘†, โš–๏ธ ๐Ÿƒโ€โ™‚ โš™๏ธ. ๐Ÿ‘ˆ โ˜, โšซ๏ธ โ›”๏ธ ๐Ÿƒ/โž– ๐Ÿ› ๏ธ, &amp; โšซ๏ธ ๐Ÿ’ช **๐Ÿ™…โ€โ™‚ ๐Ÿ“ ๐Ÿ‘œ**.
* ๐Ÿ”  ๐Ÿˆธ ๐Ÿ‘ˆ ๐Ÿ‘† โœ”๏ธ ๐Ÿƒ ๐Ÿ”› ๐Ÿ‘† ๐Ÿ’ป โœ”๏ธ ๐Ÿ› ๏ธ โ›… โšซ๏ธ, ๐Ÿ”  ๐Ÿƒโ€โ™‚ ๐Ÿ“‹, ๐Ÿ”  ๐Ÿšช, โ™’๏ธ. &amp; ๐Ÿ“ค ๐Ÿ›Ž ๐Ÿ“š ๐Ÿ› ๏ธ ๐Ÿƒ **๐ŸŽ ๐Ÿ•ฐ** โช ๐Ÿ’ป ๐Ÿ”›.
* ๐Ÿ“ค ๐Ÿ’ช **๐Ÿ’— ๐Ÿ› ๏ธ** **๐ŸŽ ๐Ÿ“‹** ๐Ÿƒ ๐ŸŽ ๐Ÿ•ฐ.
๐Ÿšฅ ๐Ÿ‘† โœ… ๐Ÿ‘… "๐Ÿ“‹ ๐Ÿ‘จโ€๐Ÿ’ผ" โš–๏ธ "โš™๏ธ ๐Ÿ–ฅ" (โš–๏ธ ๐ŸŽ ๐Ÿงฐ) ๐Ÿ‘† ๐Ÿƒโ€โ™‚ โš™๏ธ, ๐Ÿ‘† ๐Ÿ”œ ๐Ÿ’ช ๐Ÿ‘€ ๐Ÿ“š ๐Ÿ‘ˆ ๐Ÿ› ๏ธ ๐Ÿƒโ€โ™‚.
&amp; , ๐Ÿ–ผ, ๐Ÿ‘† ๐Ÿ”œ ๐ŸŽฒ ๐Ÿ‘€ ๐Ÿ‘ˆ ๐Ÿ“ค ๐Ÿ’— ๐Ÿ› ๏ธ ๐Ÿƒ ๐ŸŽ ๐Ÿ–ฅ ๐Ÿ“‹ (๐ŸฆŽ, ๐Ÿ’„, ๐Ÿ“, โ™’๏ธ). ๐Ÿ‘ซ ๐Ÿ›Ž ๐Ÿƒ 1๏ธโƒฃ ๐Ÿ› ๏ธ ๐Ÿ“ ๐Ÿ“‘, โž• ๐ŸŽ โž• ๐Ÿ› ๏ธ.
<img class="shadow" src="/img/deployment/concepts/image01.png">
---
๐Ÿ”œ ๐Ÿ‘ˆ ๐Ÿ‘ฅ ๐Ÿ’ญ ๐Ÿ”บ ๐Ÿ–– โš– **๐Ÿ› ๏ธ** &amp; **๐Ÿ“‹**, โžก๏ธ ๐Ÿ˜ฃ ๐Ÿ’ฌ ๐Ÿ”ƒ ๐Ÿ› ๏ธ.
## ๐Ÿƒโ€โ™‚ ๐Ÿ”› ๐Ÿ•ด
๐ŸŒ… ๐Ÿ’ผ, ๐Ÿ•โ” ๐Ÿ‘† โœ ๐Ÿ•ธ ๐Ÿ› ๏ธ, ๐Ÿ‘† ๐Ÿ’š โšซ๏ธ **๐Ÿ•ง ๐Ÿƒโ€โ™‚**, โžก, ๐Ÿ‘ˆ ๐Ÿ‘† ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ’ช ๐Ÿ•ง ๐Ÿ” โšซ๏ธ. ๐Ÿ‘‰ โ†—๏ธ, ๐Ÿšฅ ๐Ÿ‘† โœ”๏ธ ๐ŸŽฏ ๐Ÿค” โšซ๏ธโ” ๐Ÿ‘† ๐Ÿ’š โšซ๏ธ ๐Ÿƒ ๐Ÿ•ด ๐ŸŽฏ โš , โœ‹๏ธ ๐ŸŒ… ๐Ÿ•ฐ ๐Ÿ‘† ๐Ÿ’š โšซ๏ธ ๐Ÿ•ง ๐Ÿƒโ€โ™‚ &amp; **๐Ÿ’ช**.
### ๐Ÿ›ฐ ๐Ÿ’ฝ
๐Ÿ•โ” ๐Ÿ‘† โš’ ๐Ÿ†™ ๐Ÿ›ฐ ๐Ÿ’ฝ (โ˜ ๐Ÿ’ฝ, ๐Ÿ•น ๐ŸŽฐ, โ™’๏ธ.) ๐Ÿ™… ๐Ÿ‘œ ๐Ÿ‘† ๐Ÿ’ช ๐Ÿƒ Uvicorn (โš–๏ธ ๐ŸŽ) โŽ, ๐ŸŽ ๐ŸŒŒ ๐Ÿ‘† ๐Ÿ•โ” ๐Ÿ› ๏ธ ๐ŸŒ.
&amp; โšซ๏ธ ๐Ÿ”œ ๐Ÿ‘ท &amp; ๐Ÿ”œ โš  **โฎ๏ธ ๐Ÿ› ๏ธ**.
โœ‹๏ธ ๐Ÿšฅ ๐Ÿ‘† ๐Ÿ”— ๐Ÿ’ฝ ๐Ÿ’ธ, **๐Ÿƒโ€โ™‚ ๐Ÿ› ๏ธ** ๐Ÿ”œ ๐ŸŽฒ โ˜ ๏ธ.
&amp; ๐Ÿšฅ ๐Ÿ’ฝ โ (๐Ÿ–ผ โฎ๏ธ โ„น, โš–๏ธ ๐Ÿ› ๏ธ โšช๏ธโžก๏ธ โ˜ ๐Ÿ•โ€๐Ÿฆบ) ๐Ÿ‘† ๐ŸŽฒ **๐Ÿ† ๐Ÿšซ ๐Ÿ‘€ โšซ๏ธ**. &amp; โ†ฉ๏ธ ๐Ÿ‘ˆ, ๐Ÿ‘† ๐Ÿ† ๐Ÿšซ ๐Ÿ’ญ ๐Ÿ‘ˆ ๐Ÿ‘† โœ”๏ธ โ ๐Ÿ› ๏ธ โŽ. , ๐Ÿ‘† ๐Ÿ› ๏ธ ๐Ÿ”œ ๐Ÿšง โ˜ ๏ธ. ๐Ÿ‘ถ
### ๐Ÿƒ ๐Ÿ” ๐Ÿ”› ๐Ÿ•ด
๐Ÿข, ๐Ÿ‘† ๐Ÿ”œ ๐ŸŽฒ ๐Ÿ’š ๐Ÿ’ฝ ๐Ÿ“‹ (โœ… Uvicorn) โ–ถ๏ธ ๐Ÿ” ๐Ÿ”› ๐Ÿ’ฝ ๐Ÿ•ด, &amp; ๐Ÿต ๐Ÿ’ช ๐Ÿ™† **๐Ÿ—ฟ ๐Ÿฅ**, โœ”๏ธ ๐Ÿ› ๏ธ ๐Ÿ•ง ๐Ÿƒ โฎ๏ธ ๐Ÿ‘† ๐Ÿ› ๏ธ (โœ… Uvicorn ๐Ÿƒโ€โ™‚ ๐Ÿ‘† FastAPI ๐Ÿ“ฑ).
### ๐ŸŽ ๐Ÿ“‹
๐Ÿ† ๐Ÿ‘‰, ๐Ÿ‘† ๐Ÿ”œ ๐Ÿ›Ž โœ”๏ธ **๐ŸŽ ๐Ÿ“‹** ๐Ÿ‘ˆ ๐Ÿ”œ โš’ ๐Ÿ’ญ ๐Ÿ‘† ๐Ÿˆธ ๐Ÿƒ ๐Ÿ”› ๐Ÿ•ด. &amp; ๐Ÿ“š ๐Ÿ’ผ, โšซ๏ธ ๐Ÿ”œ โš’ ๐Ÿ’ญ ๐ŸŽ ๐Ÿฆฒ โš–๏ธ ๐Ÿˆธ ๐Ÿƒ, ๐Ÿ–ผ, ๐Ÿ’ฝ.
### ๐Ÿ–ผ ๐Ÿงฐ ๐Ÿƒ ๐Ÿ•ด
๐Ÿ–ผ ๐Ÿงฐ ๐Ÿ‘ˆ ๐Ÿ’ช ๐Ÿ‘‰ ๐Ÿ‘จโ€๐Ÿญ:
* โ˜
* Kubernete
* โ˜ โœ
* โ˜ ๐Ÿ ๐Ÿ“ณ
* โœณ
* ๐Ÿ‘จโ€๐Ÿ’ป
* ๐Ÿต ๐Ÿ”˜ โ˜ ๐Ÿ•โ€๐Ÿฆบ ๐Ÿ• ๐Ÿ‘ซ ๐Ÿ•โ€๐Ÿฆบ
* ๐ŸŽ...
๐Ÿ‘ค ๐Ÿ”œ ๐Ÿค ๐Ÿ‘† ๐ŸŒ… ๐Ÿงฑ ๐Ÿ–ผ โญ ๐Ÿ“ƒ.
## โ
๐ŸŽ โš’ ๐Ÿ’ญ ๐Ÿ‘† ๐Ÿˆธ ๐Ÿƒ ๐Ÿ”› ๐Ÿ•ด, ๐Ÿ‘† ๐ŸŽฒ ๐Ÿ’š โš’ ๐Ÿ’ญ โšซ๏ธ **โ** โฎ๏ธ โŒ.
### ๐Ÿ‘ฅ โš’ โŒ
๐Ÿ‘ฅ, ๐Ÿ—ฟ, โš’ **โŒ**, ๐ŸŒ ๐Ÿ•ฐ. ๐Ÿ–ฅ ๐ŸŒ– *๐Ÿ•ง* โœ”๏ธ **๐Ÿ›** ๐Ÿ•ตโ€โ™‚ ๐ŸŽ ๐Ÿฅ‰. ๐Ÿ‘ถ
&amp; ๐Ÿ‘ฅ ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿšง ๐Ÿ“‰ ๐Ÿ“Ÿ ๐Ÿ‘ฅ ๐Ÿ”Ž ๐Ÿ‘ˆ ๐Ÿ› &amp; ๐Ÿ‘ฅ ๐Ÿ› ๏ธ ๐Ÿ†• โš’ (๐ŸŽฒ โŽ ๐Ÿ†• ๐Ÿ› ๐Ÿ’โ€โ™‚๏ธ ๐Ÿ‘ถ).
### ๐Ÿคช โŒ ๐Ÿ” ๐Ÿต
๐Ÿ•โ” ๐Ÿ— ๐Ÿ•ธ ๐Ÿ”— โฎ๏ธ FastAPI, ๐Ÿšฅ ๐Ÿ“ค โŒ ๐Ÿ‘† ๐Ÿ“Ÿ, FastAPI ๐Ÿ”œ ๐Ÿ›Ž ๐Ÿ”Œ โšซ๏ธ ๐Ÿ‘ ๐Ÿ“จ ๐Ÿ‘ˆ โฒ โŒ. ๐Ÿ›ก
๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ”œ ๐Ÿคš **5๏ธโƒฃ0๏ธโƒฃ0๏ธโƒฃ ๐Ÿ”— ๐Ÿ’ฝ โŒ** ๐Ÿ‘ˆ ๐Ÿ“จ, โœ‹๏ธ ๐Ÿˆธ ๐Ÿ”œ ๐Ÿ˜ฃ ๐Ÿ‘ท โญ ๐Ÿ“จ โ†ฉ๏ธ ๐Ÿ’ฅ ๐Ÿ•.
### ๐Ÿฆ โŒ - ๐Ÿ’ฅ
๐Ÿ‘, ๐Ÿ“ค 5๏ธโƒฃ๐Ÿ“† ๐Ÿ’ผ ๐ŸŒโ” ๐Ÿ‘ฅ โœ ๐Ÿ“Ÿ ๐Ÿ‘ˆ **๐Ÿ’ฅ ๐ŸŽ‚ ๐Ÿˆธ** โš’ Uvicorn &amp; ๐Ÿ ๐Ÿ’ฅ. ๐Ÿ‘ถ
&amp; , ๐Ÿ‘† ๐Ÿ”œ ๐ŸŽฒ ๐Ÿšซ ๐Ÿ’š ๐Ÿˆธ ๐Ÿšง โ˜ ๏ธ โ†ฉ๏ธ ๐Ÿ“ค โŒ 1๏ธโƒฃ ๐Ÿฅ‰, ๐Ÿ‘† ๐ŸŽฒ ๐Ÿ’š โšซ๏ธ **๐Ÿ˜ฃ ๐Ÿƒ** ๐ŸŒ˜ *โžก ๐Ÿ› ๏ธ* ๐Ÿ‘ˆ ๐Ÿšซ ๐Ÿ’”.
### โ โฎ๏ธ ๐Ÿ’ฅ
โœ‹๏ธ ๐Ÿ‘ˆ ๐Ÿ’ผ โฎ๏ธ ๐Ÿค™ ๐Ÿ‘Ž โŒ ๐Ÿ‘ˆ ๐Ÿ’ฅ ๐Ÿƒโ€โ™‚ **๐Ÿ› ๏ธ**, ๐Ÿ‘† ๐Ÿ”œ ๐Ÿ’š ๐Ÿ”ข ๐Ÿฆฒ ๐Ÿ‘ˆ ๐Ÿˆš **๐Ÿ”** ๐Ÿ› ๏ธ, ๐ŸŒ˜ ๐Ÿ‘ฉโ€โคโ€๐Ÿ‘จ ๐Ÿ•ฐ...
!!! tip
...๐Ÿ‘ ๐Ÿšฅ ๐ŸŽ‚ ๐Ÿˆธ **๐Ÿ’ฅ โช** โšซ๏ธ ๐ŸŽฒ ๐Ÿšซ โš’ ๐Ÿ”‘ ๐Ÿšง ๐Ÿ” โšซ๏ธ โ™พ. โœ‹๏ธ ๐Ÿ“š ๐Ÿ’ผ, ๐Ÿ‘† ๐Ÿ”œ ๐ŸŽฒ ๐Ÿ‘€ โšซ๏ธ โฎ๏ธ ๐Ÿ› ๏ธ, โš–๏ธ ๐ŸŒ˜ โ–ถ๏ธ๏ธ โฎ๏ธ ๐Ÿ› ๏ธ.
โžก๏ธ ๐ŸŽฏ ๐Ÿ”› ๐Ÿ‘‘ ๐Ÿ’ผ, ๐ŸŒโ” โšซ๏ธ ๐Ÿ’ช ๐Ÿ’ฅ ๐Ÿ• ๐ŸŽฏ ๐Ÿ’ผ **๐Ÿ”ฎ**, &amp; โšซ๏ธ โš’ ๐Ÿ”‘ โ โšซ๏ธ.
๐Ÿ‘† ๐Ÿ”œ ๐ŸŽฒ ๐Ÿ’š โœ”๏ธ ๐Ÿ‘œ ๐Ÿˆš ๐Ÿ” ๐Ÿ‘† ๐Ÿˆธ **๐Ÿ”ข ๐Ÿฆฒ**, โ†ฉ๏ธ ๐Ÿ‘ˆ โ˜, ๐ŸŽ ๐Ÿˆธ โฎ๏ธ Uvicorn &amp; ๐Ÿ โช ๐Ÿ’ฅ, ๐Ÿ“ค ๐Ÿ•ณ ๐ŸŽ ๐Ÿ“Ÿ ๐ŸŽ ๐Ÿ“ฑ ๐Ÿ‘ˆ ๐Ÿ’ช ๐Ÿ•ณ ๐Ÿ”ƒ โšซ๏ธ.
### ๐Ÿ–ผ ๐Ÿงฐ โ ๐Ÿ”
๐Ÿ† ๐Ÿ’ผ, ๐ŸŽ ๐Ÿงฐ ๐Ÿ‘ˆ โš™๏ธ **๐Ÿƒ ๐Ÿ“‹ ๐Ÿ”› ๐Ÿ•ด** โš™๏ธ ๐Ÿต ๐Ÿง **โ**.
๐Ÿ–ผ, ๐Ÿ‘‰ ๐Ÿ’ช ๐Ÿต:
* โ˜
* Kubernete
* โ˜ โœ
* โ˜ ๐Ÿ ๐Ÿ“ณ
* โœณ
* ๐Ÿ‘จโ€๐Ÿ’ป
* ๐Ÿต ๐Ÿ”˜ โ˜ ๐Ÿ•โ€๐Ÿฆบ ๐Ÿ• ๐Ÿ‘ซ ๐Ÿ•โ€๐Ÿฆบ
* ๐ŸŽ...
## ๐Ÿงฌ - ๐Ÿ› ๏ธ &amp; ๐Ÿ’พ
โฎ๏ธ FastAPI ๐Ÿˆธ, โš™๏ธ ๐Ÿ’ฝ ๐Ÿ“‹ ๐Ÿ’– Uvicorn, ๐Ÿƒโ€โ™‚ โšซ๏ธ ๐Ÿ• **1๏ธโƒฃ ๐Ÿ› ๏ธ** ๐Ÿ’ช ๐Ÿฆ ๐Ÿ’— ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ”.
โœ‹๏ธ ๐Ÿ“š ๐Ÿ’ผ, ๐Ÿ‘† ๐Ÿ”œ ๐Ÿ’š ๐Ÿƒ ๐Ÿ“š ๐Ÿ‘จโ€๐Ÿญ ๐Ÿ› ๏ธ ๐ŸŽ ๐Ÿ•ฐ.
### ๐Ÿ’— ๐Ÿ› ๏ธ - ๐Ÿ‘จโ€๐Ÿญ
๐Ÿšฅ ๐Ÿ‘† โœ”๏ธ ๐ŸŒ… ๐Ÿ‘ฉโ€๐Ÿ’ป ๐ŸŒ˜ โšซ๏ธโ” ๐Ÿ‘ ๐Ÿ› ๏ธ ๐Ÿ’ช ๐Ÿต (๐Ÿ–ผ ๐Ÿšฅ ๐Ÿ•น ๐ŸŽฐ ๐Ÿšซ ๐Ÿ’โ€โ™‚๏ธ ๐Ÿฆ) &amp; ๐Ÿ‘† โœ”๏ธ **๐Ÿ’— ๐Ÿš** ๐Ÿ’ฝ ๐Ÿ’ฝ, โคด๏ธ ๐Ÿ‘† ๐Ÿ’ช โœ”๏ธ **๐Ÿ’— ๐Ÿ› ๏ธ** ๐Ÿƒโ€โ™‚ โฎ๏ธ ๐ŸŽ ๐Ÿˆธ ๐ŸŽ ๐Ÿ•ฐ, &amp; ๐Ÿ“Ž ๐ŸŒ ๐Ÿ“จ ๐Ÿ‘ช ๐Ÿ‘ซ.
๐Ÿ•โ” ๐Ÿ‘† ๐Ÿƒ **๐Ÿ’— ๐Ÿ› ๏ธ** ๐ŸŽ ๐Ÿ› ๏ธ ๐Ÿ“‹, ๐Ÿ‘ซ ๐Ÿ›Ž ๐Ÿค™ **๐Ÿ‘จโ€๐Ÿญ**.
### ๐Ÿ‘จโ€๐Ÿญ ๐Ÿ› ๏ธ &amp; โ›ด
๐Ÿ’ญ โšช๏ธโžก๏ธ ๐Ÿฉบ [๐Ÿ”ƒ ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ”](./https.md){.internal-link target=_blank} ๐Ÿ‘ˆ ๐Ÿ•ด 1๏ธโƒฃ ๐Ÿ› ๏ธ ๐Ÿ’ช ๐Ÿ‘‚ ๐Ÿ”› 1๏ธโƒฃ ๐ŸŒ€ โ›ด &amp; ๐Ÿ“ข ๐Ÿ“ข ๐Ÿ’ฝ โ“
๐Ÿ‘‰ โ˜‘.
, ๐Ÿ’ช โœ”๏ธ **๐Ÿ’— ๐Ÿ› ๏ธ** ๐ŸŽ ๐Ÿ•ฐ, ๐Ÿ“ค โœ”๏ธ **๐Ÿ‘ ๐Ÿ› ๏ธ ๐Ÿ‘‚ ๐Ÿ”› โ›ด** ๐Ÿ‘ˆ โคด๏ธ ๐Ÿ“ถ ๐Ÿ“ป ๐Ÿ”  ๐Ÿ‘จโ€๐Ÿญ ๐Ÿ› ๏ธ ๐ŸŒŒ.
### ๐Ÿ’พ ๐Ÿ“ ๐Ÿ› ๏ธ
๐Ÿ”œ, ๐Ÿ•โ” ๐Ÿ“‹ ๐Ÿ“ ๐Ÿ‘œ ๐Ÿ’พ, ๐Ÿ–ผ, ๐ŸŽฐ ๐Ÿซ ๐Ÿท ๐Ÿ”ข, โš–๏ธ ๐ŸŽš โญ• ๐Ÿ“ ๐Ÿ”ข, ๐ŸŒ ๐Ÿ‘ˆ **๐Ÿด ๐Ÿ‘„ ๐Ÿ’พ (๐Ÿ’พ)** ๐Ÿ’ฝ.
&amp; ๐Ÿ’— ๐Ÿ› ๏ธ ๐Ÿ›Ž **๐Ÿšซ ๐Ÿ’ฐ ๐Ÿ™† ๐Ÿ’พ**. ๐Ÿ‘‰ โ›“ ๐Ÿ‘ˆ ๐Ÿ”  ๐Ÿƒ ๐Ÿ› ๏ธ โœ”๏ธ ๐Ÿšฎ ๐Ÿ‘ ๐Ÿ‘œ, ๐Ÿ”ข, &amp; ๐Ÿ’พ. &amp; ๐Ÿšฅ ๐Ÿ‘† ๐Ÿ˜ฉ โญ• ๐Ÿ’ธ ๐Ÿ’พ ๐Ÿ‘† ๐Ÿ“Ÿ, **๐Ÿ”  ๐Ÿ› ๏ธ** ๐Ÿ”œ ๐Ÿด ๐ŸŒ“ ๐Ÿ’ธ ๐Ÿ’พ.
### ๐Ÿ’ฝ ๐Ÿ’พ
๐Ÿ–ผ, ๐Ÿšฅ ๐Ÿ‘† ๐Ÿ“Ÿ ๐Ÿ“ ๐ŸŽฐ ๐Ÿซ ๐Ÿท โฎ๏ธ **1๏ธโƒฃ ๐Ÿ’พ ๐Ÿ“**, ๐Ÿ•โ” ๐Ÿ‘† ๐Ÿƒ 1๏ธโƒฃ ๐Ÿ› ๏ธ โฎ๏ธ ๐Ÿ‘† ๐Ÿ› ๏ธ, โšซ๏ธ ๐Ÿ”œ ๐Ÿด ๐ŸŒ˜ 1๏ธโƒฃ ๐Ÿ’พ ๐Ÿ’พ. &amp; ๐Ÿšฅ ๐Ÿ‘† โ–ถ๏ธ **4๏ธโƒฃ ๐Ÿ› ๏ธ** (4๏ธโƒฃ ๐Ÿ‘จโ€๐Ÿญ), ๐Ÿ”  ๐Ÿ”œ ๐Ÿด 1๏ธโƒฃ ๐Ÿ’พ ๐Ÿ’พ. ๐ŸŒ, ๐Ÿ‘† ๐Ÿ› ๏ธ ๐Ÿ”œ ๐Ÿด **4๏ธโƒฃ ๐Ÿ’พ ๐Ÿ’พ**.
&amp; ๐Ÿšฅ ๐Ÿ‘† ๐Ÿ›ฐ ๐Ÿ’ฝ โš–๏ธ ๐Ÿ•น ๐ŸŽฐ ๐Ÿ•ด โœ”๏ธ 3๏ธโƒฃ ๐Ÿ’พ ๐Ÿ’พ, ๐Ÿ”„ ๐Ÿ“ ๐ŸŒ… ๐ŸŒ˜ 4๏ธโƒฃ ๐Ÿ’พ ๐Ÿ’พ ๐Ÿ”œ ๐Ÿค• โš . ๐Ÿ‘ถ
### ๐Ÿ’— ๐Ÿ› ๏ธ - ๐Ÿ–ผ
๐Ÿ‘‰ ๐Ÿ–ผ, ๐Ÿ“ค **๐Ÿ‘จโ€๐Ÿ’ผ ๐Ÿ› ๏ธ** ๐Ÿ‘ˆ โ–ถ๏ธ &amp; ๐ŸŽ› 2๏ธโƒฃ **๐Ÿ‘จโ€๐Ÿญ ๐Ÿ› ๏ธ**.
๐Ÿ‘‰ ๐Ÿ‘จโ€๐Ÿ’ผ ๐Ÿ› ๏ธ ๐Ÿ”œ ๐ŸŽฒ 1๏ธโƒฃ ๐Ÿ‘‚ ๐Ÿ”› **โ›ด** ๐Ÿ“ข. &amp; โšซ๏ธ ๐Ÿ”œ ๐Ÿ“ถ ๐ŸŒ ๐Ÿ“ป ๐Ÿ‘จโ€๐Ÿญ ๐Ÿ› ๏ธ.
๐Ÿ‘ˆ ๐Ÿ‘จโ€๐Ÿญ ๐Ÿ› ๏ธ ๐Ÿ”œ ๐Ÿ• ๐Ÿƒโ€โ™‚ ๐Ÿ‘† ๐Ÿˆธ, ๐Ÿ‘ซ ๐Ÿ”œ ๐ŸŽญ ๐Ÿ‘‘ ๐Ÿ“Š ๐Ÿ“จ **๐Ÿ“จ** &amp; ๐Ÿ“จ **๐Ÿ“จ**, &amp; ๐Ÿ‘ซ ๐Ÿ”œ ๐Ÿ“ ๐Ÿ•ณ ๐Ÿ‘† ๐Ÿšฎ ๐Ÿ”ข ๐Ÿ’พ.
<img src="/img/deployment/concepts/process-ram.svg">
&amp; โ†—๏ธ, ๐ŸŽ ๐ŸŽฐ ๐Ÿ”œ ๐ŸŽฒ โœ”๏ธ **๐ŸŽ ๐Ÿ› ๏ธ** ๐Ÿƒ ๐Ÿ‘, โ†–๏ธ โšช๏ธโžก๏ธ ๐Ÿ‘† ๐Ÿˆธ.
๐Ÿ˜Œ โ„น ๐Ÿ‘ˆ ๐ŸŒ **๐Ÿ’ฝ โš™๏ธ** ๐Ÿ”  ๐Ÿ› ๏ธ ๐Ÿ’ช **๐Ÿช€** ๐Ÿ“š ๐Ÿคญ ๐Ÿ•ฐ, โœ‹๏ธ **๐Ÿ’พ (๐Ÿ’พ)** ๐Ÿ›Ž ๐Ÿšง ๐ŸŒ– โš–๏ธ ๐ŸŒ˜ **โš–**.
๐Ÿšฅ ๐Ÿ‘† โœ”๏ธ ๐Ÿ› ๏ธ ๐Ÿ‘ˆ ๐Ÿ”จ โญ ๐Ÿ’ธ ๐Ÿ“Š ๐Ÿ”  ๐Ÿ•ฐ &amp; ๐Ÿ‘† โœ”๏ธ ๐Ÿ“š ๐Ÿ‘ฉโ€๐Ÿ’ป, โคด๏ธ **๐Ÿ’ฝ ๐Ÿ› ๏ธ** ๐Ÿ”œ ๐ŸŽฒ *โš–* (โ†ฉ๏ธ ๐Ÿ•ง ๐Ÿ”œ ๐Ÿ†™ &amp; ๐Ÿ”ฝ ๐Ÿ”œ).
### ๐Ÿ–ผ ๐Ÿงฌ ๐Ÿงฐ &amp; ๐ŸŽ›
๐Ÿ“ค ๐Ÿ’ช ๐Ÿ“š ๐ŸŽฏ ๐Ÿ† ๐Ÿ‘‰, &amp; ๐Ÿ‘ค ๐Ÿ”œ ๐Ÿ’ฌ ๐Ÿ‘† ๐ŸŒ… ๐Ÿ”ƒ ๐ŸŽฏ ๐ŸŽ› โญ ๐Ÿ“ƒ, ๐Ÿ–ผ ๐Ÿ•โ” ๐Ÿ’ฌ ๐Ÿ”ƒ โ˜ &amp; ๐Ÿ“ฆ.
๐Ÿ‘‘ โš› ๐Ÿค” ๐Ÿ‘ˆ ๐Ÿ“ค โœ”๏ธ **๐Ÿ‘** ๐Ÿฆฒ ๐Ÿšš **โ›ด** **๐Ÿ“ข ๐Ÿ“ข**. &amp; โคด๏ธ โšซ๏ธ โœ”๏ธ โœ”๏ธ ๐ŸŒŒ **๐Ÿ“ถ** ๐Ÿ“ป ๐Ÿ” **๐Ÿ› ๏ธ/๐Ÿ‘จโ€๐Ÿญ**.
๐Ÿ“ฅ ๐Ÿ’ช ๐ŸŒ€ &amp; ๐ŸŽ›:
* **๐Ÿ** ๐Ÿ› ๏ธ **Uvicorn ๐Ÿ‘จโ€๐Ÿญ**
* ๐Ÿ ๐Ÿ”œ **๐Ÿ› ๏ธ ๐Ÿ‘จโ€๐Ÿ’ผ** ๐Ÿ‘‚ ๐Ÿ”› **๐Ÿ“ข** &amp; **โ›ด**, ๐Ÿงฌ ๐Ÿ”œ โœ”๏ธ **๐Ÿ’— Uvicorn ๐Ÿ‘จโ€๐Ÿญ ๐Ÿ› ๏ธ**
* **Uvicorn** ๐Ÿ› ๏ธ **Uvicorn ๐Ÿ‘จโ€๐Ÿญ**
* 1๏ธโƒฃ Uvicorn **๐Ÿ› ๏ธ ๐Ÿ‘จโ€๐Ÿ’ผ** ๐Ÿ”œ ๐Ÿ‘‚ ๐Ÿ”› **๐Ÿ“ข** &amp; **โ›ด**, &amp; โšซ๏ธ ๐Ÿ”œ โ–ถ๏ธ **๐Ÿ’— Uvicorn ๐Ÿ‘จโ€๐Ÿญ ๐Ÿ› ๏ธ**
* **Kubernete** &amp; ๐ŸŽ ๐Ÿ“Ž **๐Ÿ“ฆ โš™๏ธ**
* ๐Ÿ•ณ **โ˜** ๐Ÿงฝ ๐Ÿ”œ ๐Ÿ‘‚ ๐Ÿ”› **๐Ÿ“ข** &amp; **โ›ด**. ๐Ÿงฌ ๐Ÿ”œ โœ”๏ธ **๐Ÿ’— ๐Ÿ“ฆ**, ๐Ÿ”  โฎ๏ธ **1๏ธโƒฃ Uvicorn ๐Ÿ› ๏ธ** ๐Ÿƒโ€โ™‚
* **โ˜ ๐Ÿ•โ€๐Ÿฆบ** ๐Ÿ‘ˆ ๐Ÿต ๐Ÿ‘‰ ๐Ÿ‘†
* โ˜ ๐Ÿ•โ€๐Ÿฆบ ๐Ÿ”œ ๐ŸŽฒ **๐Ÿต ๐Ÿงฌ ๐Ÿ‘†**. โšซ๏ธ ๐Ÿ”œ ๐ŸŽฒ โžก๏ธ ๐Ÿ‘† ๐Ÿ”ฌ **๐Ÿ› ๏ธ ๐Ÿƒ**, โš–๏ธ **๐Ÿ“ฆ ๐Ÿ–ผ** โš™๏ธ, ๐Ÿ™† ๐Ÿ’ผ, โšซ๏ธ ๐Ÿ”œ ๐ŸŒ… ๐ŸŽฒ **๐Ÿ‘ Uvicorn ๐Ÿ› ๏ธ**, &amp; โ˜ ๐Ÿ•โ€๐Ÿฆบ ๐Ÿ”œ ๐Ÿˆš ๐Ÿ” โšซ๏ธ.
!!! tip
๐Ÿšซ ๐Ÿ˜Ÿ ๐Ÿšฅ ๐Ÿ‘ซ ๐Ÿฌ ๐Ÿ”ƒ **๐Ÿ“ฆ**, โ˜, โš–๏ธ Kubernete ๐Ÿšซ โš’ ๐Ÿ“š ๐Ÿ”‘.
๐Ÿ‘ค ๐Ÿ”œ ๐Ÿ’ฌ ๐Ÿ‘† ๐ŸŒ… ๐Ÿ”ƒ ๐Ÿ“ฆ ๐Ÿ–ผ, โ˜, Kubernete, โ™’๏ธ. ๐Ÿ”ฎ ๐Ÿ“ƒ: [FastAPI ๐Ÿ“ฆ - โ˜](./docker.md){.internal-link target=_blank}.
## โฎ๏ธ ๐Ÿ” โญ โ–ถ๏ธ
๐Ÿ“ค ๐Ÿ“š ๐Ÿ’ผ ๐ŸŒโ” ๐Ÿ‘† ๐Ÿ’š ๐ŸŽญ ๐Ÿ“ถ **โญ โ–ถ๏ธ** ๐Ÿ‘† ๐Ÿˆธ.
๐Ÿ–ผ, ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ’š ๐Ÿƒ **๐Ÿ’ฝ ๐Ÿ› ๏ธ**.
โœ‹๏ธ ๐ŸŒ… ๐Ÿ’ผ, ๐Ÿ‘† ๐Ÿ”œ ๐Ÿ’š ๐ŸŽญ ๐Ÿ‘‰ ๐Ÿ” ๐Ÿ•ด **๐Ÿ•**.
, ๐Ÿ‘† ๐Ÿ”œ ๐Ÿ’š โœ”๏ธ **๐Ÿ‘ ๐Ÿ› ๏ธ** ๐ŸŽญ ๐Ÿ‘ˆ **โฎ๏ธ ๐Ÿ”**, โญ โ–ถ๏ธ ๐Ÿˆธ.
&amp; ๐Ÿ‘† ๐Ÿ”œ โœ”๏ธ โš’ ๐Ÿ’ญ ๐Ÿ‘ˆ โšซ๏ธ ๐Ÿ‘ ๐Ÿ› ๏ธ ๐Ÿƒ ๐Ÿ‘ˆ โฎ๏ธ ๐Ÿ” ** ๐Ÿšฅ โฎ๏ธ, ๐Ÿ‘† โ–ถ๏ธ **๐Ÿ’— ๐Ÿ› ๏ธ** (๐Ÿ’— ๐Ÿ‘จโ€๐Ÿญ) ๐Ÿˆธ โšซ๏ธ. ๐Ÿšฅ ๐Ÿ‘ˆ ๐Ÿ” ๐Ÿƒ **๐Ÿ’— ๐Ÿ› ๏ธ**, ๐Ÿ‘ซ ๐Ÿ”œ **โŽ** ๐Ÿ‘ท ๐Ÿƒโ€โ™‚ โšซ๏ธ ๐Ÿ”› **๐Ÿ”—**, &amp; ๐Ÿšฅ ๐Ÿ“ถ ๐Ÿ•ณ ๐Ÿ’Ž ๐Ÿ’– ๐Ÿ’ฝ ๐Ÿ› ๏ธ, ๐Ÿ‘ซ ๐Ÿ’ช ๐Ÿค• โš” โฎ๏ธ ๐Ÿ”  ๐ŸŽ.
โ†—๏ธ, ๐Ÿ“ค ๐Ÿ’ผ ๐ŸŒโ” ๐Ÿ“ค ๐Ÿ™…โ€โ™‚ โš  ๐Ÿƒ โฎ๏ธ ๐Ÿ” ๐Ÿ’— ๐Ÿ•ฐ, ๐Ÿ‘ˆ ๐Ÿ’ผ, โšซ๏ธ ๐Ÿ“š โฉ ๐Ÿต.
!!! tip
, โœ”๏ธ ๐Ÿคฏ ๐Ÿ‘ˆ โš“๏ธ ๐Ÿ”› ๐Ÿ‘† ๐Ÿ–ฅ, ๐Ÿ’ผ ๐Ÿ‘† **5๏ธโƒฃ๐Ÿ“† ๐Ÿšซ ๐Ÿ’ช ๐Ÿ™† โฎ๏ธ ๐Ÿ”** โญ โ–ถ๏ธ ๐Ÿ‘† ๐Ÿˆธ.
๐Ÿ‘ˆ ๐Ÿ’ผ, ๐Ÿ‘† ๐Ÿšซ๐Ÿ”œ โœ”๏ธ ๐Ÿ˜Ÿ ๐Ÿ”ƒ ๐Ÿ™† ๐Ÿ‘‰. ๐Ÿคท
### ๐Ÿ–ผ โฎ๏ธ ๐Ÿ” ๐ŸŽ›
๐Ÿ‘‰ ๐Ÿ”œ **๐Ÿช€ ๐Ÿ™‡** ๐Ÿ”› ๐ŸŒŒ ๐Ÿ‘† **๐Ÿ› ๏ธ ๐Ÿ‘† โš™๏ธ**, &amp; โšซ๏ธ ๐Ÿ”œ ๐ŸŽฒ ๐Ÿ”— ๐ŸŒŒ ๐Ÿ‘† โ–ถ๏ธ ๐Ÿ“‹, ๐Ÿšš โ, โ™’๏ธ.
๐Ÿ“ฅ ๐Ÿ’ช ๐Ÿ’ญ:
* "๐Ÿ•‘ ๐Ÿ“ฆ" Kubernete ๐Ÿ‘ˆ ๐Ÿƒ โญ ๐Ÿ‘† ๐Ÿ“ฑ ๐Ÿ“ฆ
* ๐ŸŽ‰ โœ ๐Ÿ‘ˆ ๐Ÿƒ โฎ๏ธ ๐Ÿ” &amp; โคด๏ธ โ–ถ๏ธ ๐Ÿ‘† ๐Ÿˆธ
* ๐Ÿ‘† ๐Ÿ”œ ๐Ÿ’ช ๐ŸŒŒ โ–ถ๏ธ/โ *๐Ÿ‘ˆ* ๐ŸŽ‰ โœ, ๐Ÿ” โŒ, โ™’๏ธ.
!!! tip
๐Ÿ‘ค ๐Ÿ”œ ๐Ÿค ๐Ÿ‘† ๐ŸŒ… ๐Ÿงฑ ๐Ÿ–ผ ๐Ÿ”จ ๐Ÿ‘‰ โฎ๏ธ ๐Ÿ“ฆ ๐Ÿ”ฎ ๐Ÿ“ƒ: [FastAPI ๐Ÿ“ฆ - โ˜](./docker.md){.internal-link target=_blank}.
## โ„น ๐Ÿ› ๏ธ
๐Ÿ‘† ๐Ÿ’ฝ(โ“‚) () **โ„น**, ๐Ÿ‘† ๐Ÿ’ช ๐Ÿด โš–๏ธ **โš™๏ธ**, โฎ๏ธ ๐Ÿ‘† ๐Ÿ“‹, ๐Ÿ“Š ๐Ÿ•ฐ ๐Ÿ”› ๐Ÿ’ฝ, &amp; ๐Ÿ’พ ๐Ÿ’พ ๐Ÿ’ช.
โ” ๐ŸŒ… โš™๏ธ โ„น ๐Ÿ‘† ๐Ÿ’š ๐Ÿ˜ฉ/โ™ป โ“ โšซ๏ธ ๐Ÿ’ช โฉ ๐Ÿ’ญ "๐Ÿšซ ๐ŸŒ…", โœ‹๏ธ ๐ŸŒŒ, ๐Ÿ‘† ๐Ÿ”œ ๐ŸŽฒ ๐Ÿ’š ๐Ÿด **๐ŸŒ… ๐Ÿ’ช ๐Ÿต ๐Ÿ’ฅ**.
๐Ÿšฅ ๐Ÿ‘† ๐Ÿ’ธ 3๏ธโƒฃ ๐Ÿ’ฝ โœ‹๏ธ ๐Ÿ‘† โš™๏ธ ๐Ÿ•ด ๐Ÿฅ ๐Ÿ– ๐Ÿ‘ซ ๐Ÿ’พ &amp; ๐Ÿ’ฝ, ๐Ÿ‘† ๐ŸŽฒ **๐Ÿ—‘ ๐Ÿ’ธ** ๐Ÿ‘ถ, &amp; ๐ŸŽฒ **๐Ÿ—‘ ๐Ÿ’ฝ ๐Ÿ”ฆ ๐Ÿ‹๏ธ** ๐Ÿ‘ถ, โ™’๏ธ.
๐Ÿ‘ˆ ๐Ÿ’ผ, โšซ๏ธ ๐Ÿ’ช ๐Ÿ‘ป โœ”๏ธ ๐Ÿ•ด 2๏ธโƒฃ ๐Ÿ’ฝ &amp; โš™๏ธ โ†• ๐ŸŒ ๐Ÿ‘ซ โ„น (๐Ÿ’ฝ, ๐Ÿ’พ, ๐Ÿ’พ, ๐Ÿ•ธ ๐Ÿ’ฟ, โ™’๏ธ).
๐Ÿ”› ๐ŸŽ โœ‹, ๐Ÿšฅ ๐Ÿ‘† โœ”๏ธ 2๏ธโƒฃ ๐Ÿ’ฝ &amp; ๐Ÿ‘† โš™๏ธ **1๏ธโƒฃ0๏ธโƒฃ0๏ธโƒฃ ๐Ÿ’ฏ ๐Ÿ‘ซ ๐Ÿ’ฝ &amp; ๐Ÿ’พ**, โ˜ 1๏ธโƒฃ ๐Ÿ› ๏ธ ๐Ÿ”œ ๐Ÿ’ญ ๐ŸŒ… ๐Ÿ’พ, &amp; ๐Ÿ’ฝ ๐Ÿ”œ โœ”๏ธ โš™๏ธ ๐Ÿ’พ "๐Ÿ’พ" (โ” ๐Ÿ’ช ๐Ÿ’ฏ ๐Ÿ•ฐ ๐ŸŒ), โš–๏ธ **๐Ÿ’ฅ**. โš–๏ธ 1๏ธโƒฃ ๐Ÿ› ๏ธ ๐Ÿ’ช ๐Ÿ’ช ๐Ÿ“Š &amp; ๐Ÿ”œ โœ”๏ธ โŒ› โญ ๐Ÿ’ฝ ๐Ÿ†“ ๐Ÿ”„.
๐Ÿ‘‰ ๐Ÿ’ผ, โšซ๏ธ ๐Ÿ”œ ๐Ÿ‘ ๐Ÿคš **1๏ธโƒฃ โž• ๐Ÿ’ฝ** &amp; ๐Ÿƒ ๐Ÿ› ๏ธ ๐Ÿ”› โšซ๏ธ ๐Ÿ‘ˆ ๐Ÿ‘ซ ๐ŸŒ โœ”๏ธ **๐Ÿฅƒ ๐Ÿ’พ &amp; ๐Ÿ’ฝ ๐Ÿ•ฐ**.
๐Ÿ“ค ๐Ÿคž ๐Ÿ‘ˆ ๐Ÿค” ๐Ÿ‘† โœ”๏ธ **๐ŸŒต** โš™๏ธ ๐Ÿ‘† ๐Ÿ› ๏ธ. ๐ŸŽฒ โšซ๏ธ ๐Ÿšถ ๐Ÿฆ , โš–๏ธ ๐ŸŽฒ ๐ŸŽ ๐Ÿ•โ€๐Ÿฆบ โš–๏ธ ๐Ÿค– โ–ถ๏ธ โš™๏ธ โšซ๏ธ. &amp; ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ’š โœ”๏ธ โž• โ„น ๐Ÿ”’ ๐Ÿ‘ˆ ๐Ÿ’ผ.
๐Ÿ‘† ๐Ÿ’ช ๐Ÿšฎ **โŒ ๐Ÿ”ข** ๐ŸŽฏ, ๐Ÿ–ผ, ๐Ÿ•ณ **๐Ÿ–– 5๏ธโƒฃ0๏ธโƒฃ ๐Ÿ’ฏ 9๏ธโƒฃ0๏ธโƒฃ ๐Ÿ’ฏ** โ„น ๐Ÿ› ๏ธ. โ˜ ๐Ÿ‘ˆ ๐Ÿ“š ๐ŸŽฒ ๐Ÿ‘‘ ๐Ÿ‘œ ๐Ÿ‘† ๐Ÿ”œ ๐Ÿ’š โš– &amp; โš™๏ธ โš’ ๐Ÿ‘† ๐Ÿ› ๏ธ.
๐Ÿ‘† ๐Ÿ’ช โš™๏ธ ๐Ÿ™… ๐Ÿงฐ ๐Ÿ’– `htop` ๐Ÿ‘€ ๐Ÿ’ฝ &amp; ๐Ÿ’พ โš™๏ธ ๐Ÿ‘† ๐Ÿ’ฝ โš–๏ธ ๐Ÿ’ธ โš™๏ธ ๐Ÿ”  ๐Ÿ› ๏ธ. โš–๏ธ ๐Ÿ‘† ๐Ÿ’ช โš™๏ธ ๐ŸŒ– ๐Ÿ— โš– ๐Ÿงฐ, โ” 5๏ธโƒฃ๐Ÿ“† ๐Ÿ“Ž ๐Ÿคญ ๐Ÿ’ฝ, โ™’๏ธ.
## ๐ŸŒƒ
๐Ÿ‘† โœ”๏ธ ๐Ÿ‘‚ ๐Ÿ“ฅ ๐Ÿ‘‘ ๐Ÿ”ง ๐Ÿ‘ˆ ๐Ÿ‘† ๐Ÿ”œ ๐ŸŽฒ ๐Ÿ’ช โœ”๏ธ ๐Ÿคฏ ๐Ÿ•โ” ๐Ÿค” โ” ๐Ÿ› ๏ธ ๐Ÿ‘† ๐Ÿˆธ:
* ๐Ÿ’‚โ€โ™‚ - ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ”
* ๐Ÿƒโ€โ™‚ ๐Ÿ”› ๐Ÿ•ด
* โ
* ๐Ÿงฌ (๐Ÿ”ข ๐Ÿ› ๏ธ ๐Ÿƒ)
* ๐Ÿ’พ
* โฎ๏ธ ๐Ÿ” โญ โ–ถ๏ธ
๐Ÿค” ๐Ÿ‘‰ ๐Ÿ’ญ &amp; โ” โœ” ๐Ÿ‘ซ ๐Ÿ”œ ๐Ÿค ๐Ÿ‘† ๐Ÿค” ๐Ÿ’ช โœŠ ๐Ÿ™† ๐Ÿšซ ๐Ÿ•โ” ๐Ÿ› ๏ธ &amp; ๐Ÿ› ๏ธ ๐Ÿ‘† ๐Ÿ› ๏ธ. ๐Ÿ‘ถ
โญ ๐Ÿ“„, ๐Ÿ‘ค ๐Ÿ”œ ๐Ÿค ๐Ÿ‘† ๐ŸŒ… ๐Ÿงฑ ๐Ÿ–ผ ๐Ÿ’ช ๐ŸŽ› ๐Ÿ‘† ๐Ÿ’ช โฉ. ๐Ÿ‘ถ

258
docs/em/docs/deployment/deta.md

@ -0,0 +1,258 @@
# ๐Ÿ› ๏ธ FastAPI ๐Ÿ”› ๐Ÿช”
๐Ÿ‘‰ ๐Ÿ“„ ๐Ÿ‘† ๐Ÿ”œ ๐Ÿ’ก โ” ๐Ÿ’ช ๐Ÿ› ๏ธ **FastAPI** ๐Ÿˆธ ๐Ÿ”› <a href="https://www.deta.sh/?ref=fastapi" class="external-link" target="_blank">๐Ÿช”</a> โš™๏ธ ๐Ÿ†“ ๐Ÿ“„. ๐Ÿ‘ถ
โšซ๏ธ ๐Ÿ”œ โœŠ ๐Ÿ‘† ๐Ÿ”ƒ **1๏ธโƒฃ0๏ธโƒฃ โฒ**.
!!! info
<a href="https://www.deta.sh/?ref=fastapi" class="external-link" target="_blank">๐Ÿช”</a> **FastAPI** ๐Ÿ’ฐ. ๐Ÿ‘ถ
## ๐Ÿ”ฐ **FastAPI** ๐Ÿ“ฑ
* โœ ๐Ÿ“ ๐Ÿ‘† ๐Ÿ“ฑ, ๐Ÿ–ผ, `./fastapideta/` &amp; โ›” ๐Ÿ”˜ โšซ๏ธ.
### FastAPI ๐Ÿ“Ÿ
* โœ `main.py` ๐Ÿ“ โฎ๏ธ:
```Python
from fastapi import FastAPI
app = FastAPI()
@app.get("/")
def read_root():
return {"Hello": "World"}
@app.get("/items/{item_id}")
def read_item(item_id: int):
return {"item_id": item_id}
```
### ๐Ÿ“„
๐Ÿ”œ, ๐ŸŽ ๐Ÿ“ โœ ๐Ÿ“ `requirements.txt` โฎ๏ธ:
```text
fastapi
```
!!! tip
๐Ÿ‘† ๐Ÿšซ ๐Ÿ’ช โŽ Uvicorn ๐Ÿ› ๏ธ ๐Ÿ”› ๐Ÿช”, ๐Ÿ‘ ๐Ÿ‘† ๐Ÿ”œ ๐ŸŽฒ ๐Ÿ’š โŽ โšซ๏ธ ๐ŸŒ ๐Ÿ’ฏ ๐Ÿ‘† ๐Ÿ“ฑ.
### ๐Ÿ“ ๐Ÿ“Š
๐Ÿ‘† ๐Ÿ”œ ๐Ÿ”œ โœ”๏ธ 1๏ธโƒฃ ๐Ÿ“ `./fastapideta/` โฎ๏ธ 2๏ธโƒฃ ๐Ÿ“:
```
.
โ””โ”€โ”€ main.py
โ””โ”€โ”€ requirements.txt
```
## โœ ๐Ÿ†“ ๐Ÿช” ๐Ÿง
๐Ÿ”œ โœ <a href="https://www.deta.sh/?ref=fastapi" class="external-link" target="_blank">๐Ÿ†“ ๐Ÿง ๐Ÿ”› ๐Ÿช”</a>, ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ“ง &amp; ๐Ÿ”.
๐Ÿ‘† ๐Ÿšซ ๐Ÿ’ช ๐Ÿ’ณ.
## โŽ โœณ
๐Ÿ• ๐Ÿ‘† โœ”๏ธ ๐Ÿ‘† ๐Ÿง, โŽ ๐Ÿช” <abbr title="Command Line Interface application">โœณ</abbr>:
=== "๐Ÿ’พ, ๐Ÿ‡ธ๐Ÿ‡ป"
<div class="termy">
```console
$ curl -fsSL https://get.deta.dev/cli.sh | sh
```
</div>
=== "๐Ÿšช ๐Ÿ“‹"
<div class="termy">
```console
$ iwr https://get.deta.dev/cli.ps1 -useb | iex
```
</div>
โฎ๏ธ โŽ โšซ๏ธ, ๐Ÿ“‚ ๐Ÿ†• ๐Ÿ“ถ ๐Ÿ‘ˆ โŽ โœณ ๐Ÿ”.
๐Ÿ†• ๐Ÿ“ถ, โœ” ๐Ÿ‘ˆ โšซ๏ธ โ˜‘ โŽ โฎ๏ธ:
<div class="termy">
```console
$ deta --help
Deta command line interface for managing deta micros.
Complete documentation available at https://docs.deta.sh
Usage:
deta [flags]
deta [command]
Available Commands:
auth Change auth settings for a deta micro
...
```
</div>
!!! tip
๐Ÿšฅ ๐Ÿ‘† โœ”๏ธ โš  โŽ โœณ, โœ… <a href="https://docs.deta.sh/docs/micros/getting_started?ref=fastapi" class="external-link" target="_blank">๐Ÿ›‚ ๐Ÿช” ๐Ÿฉบ</a>.
## ๐Ÿ’ณ โฎ๏ธ โœณ
๐Ÿ”œ ๐Ÿ’ณ ๐Ÿช” โšช๏ธโžก๏ธ โœณ โฎ๏ธ:
<div class="termy">
```console
$ deta login
Please, log in from the web page. Waiting..
Logged in successfully.
```
</div>
๐Ÿ‘‰ ๐Ÿ”œ ๐Ÿ“‚ ๐Ÿ•ธ ๐Ÿ–ฅ &amp; ๐Ÿ”“ ๐Ÿ”.
## ๐Ÿ› ๏ธ โฎ๏ธ ๐Ÿช”
โญ, ๐Ÿ› ๏ธ ๐Ÿ‘† ๐Ÿˆธ โฎ๏ธ ๐Ÿช” โœณ:
<div class="termy">
```console
$ deta new
Successfully created a new micro
// Notice the "endpoint" ๐Ÿ”
{
"name": "fastapideta",
"runtime": "python3.7",
"endpoint": "https://qltnci.deta.dev",
"visor": "enabled",
"http_auth": "enabled"
}
Adding dependencies...
---> 100%
Successfully installed fastapi-0.61.1 pydantic-1.7.2 starlette-0.13.6
```
</div>
๐Ÿ‘† ๐Ÿ”œ ๐Ÿ‘€ ๐ŸŽป ๐Ÿ“ง ๐ŸŽ:
```JSON hl_lines="4"
{
"name": "fastapideta",
"runtime": "python3.7",
"endpoint": "https://qltnci.deta.dev",
"visor": "enabled",
"http_auth": "enabled"
}
```
!!! tip
๐Ÿ‘† ๐Ÿ› ๏ธ ๐Ÿ”œ โœ”๏ธ ๐ŸŽ `"endpoint"` ๐Ÿ“›.
## โœ… โšซ๏ธ
๐Ÿ”œ ๐Ÿ“‚ ๐Ÿ‘† ๐Ÿ–ฅ ๐Ÿ‘† `endpoint` ๐Ÿ“›. ๐Ÿ–ผ ๐Ÿ”› โšซ๏ธ `https://qltnci.deta.dev`, โœ‹๏ธ ๐Ÿ‘† ๐Ÿ”œ ๐ŸŽ.
๐Ÿ‘† ๐Ÿ”œ ๐Ÿ‘€ ๐ŸŽป ๐Ÿ“จ โšช๏ธโžก๏ธ ๐Ÿ‘† FastAPI ๐Ÿ“ฑ:
```JSON
{
"Hello": "World"
}
```
&amp; ๐Ÿ”œ ๐Ÿšถ `/docs` ๐Ÿ‘† ๐Ÿ› ๏ธ, ๐Ÿ–ผ ๐Ÿ”› โšซ๏ธ ๐Ÿ”œ `https://qltnci.deta.dev/docs`.
โšซ๏ธ ๐Ÿ”œ ๐ŸŽฆ ๐Ÿ‘† ๐Ÿฉบ ๐Ÿ’–:
<img src="/img/deployment/deta/image01.png">
## ๐Ÿ› ๏ธ ๐Ÿ“ข ๐Ÿ”
๐Ÿ”ข, ๐Ÿช” ๐Ÿ”œ ๐Ÿต ๐Ÿค โš™๏ธ ๐Ÿช ๐Ÿ‘† ๐Ÿง.
โœ‹๏ธ ๐Ÿ• ๐Ÿ‘† ๐Ÿ”œ, ๐Ÿ‘† ๐Ÿ’ช โš’ โšซ๏ธ ๐Ÿ“ข โฎ๏ธ:
<div class="termy">
```console
$ deta auth disable
Successfully disabled http auth
```
</div>
๐Ÿ”œ ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ’ฐ ๐Ÿ‘ˆ ๐Ÿ“› โฎ๏ธ ๐Ÿ™† &amp; ๐Ÿ‘ซ ๐Ÿ”œ ๐Ÿ’ช ๐Ÿ” ๐Ÿ‘† ๐Ÿ› ๏ธ. ๐Ÿ‘ถ
## ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ”
ใŠ— โ— ๐Ÿ‘† ๐Ÿ› ๏ธ ๐Ÿ‘† FastAPI ๐Ÿ“ฑ ๐Ÿช” โ— ๐Ÿ‘ถ ๐Ÿ‘ถ
, ๐Ÿ‘€ ๐Ÿ‘ˆ ๐Ÿช” โ˜‘ ๐Ÿต ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ” ๐Ÿ‘†, ๐Ÿ‘† ๐Ÿšซ โœ”๏ธ โœŠ ๐Ÿ’… ๐Ÿ‘ˆ &amp; ๐Ÿ’ช ๐Ÿ’ญ ๐Ÿ‘ˆ ๐Ÿ‘† ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ”œ โœ”๏ธ ๐Ÿ” ๐Ÿ—œ ๐Ÿ”—. ๐Ÿ‘ถ ๐Ÿ‘ถ
## โœ… ๐Ÿ•ถ
โšช๏ธโžก๏ธ ๐Ÿ‘† ๐Ÿฉบ ๐ŸŽš (๐Ÿ‘ซ ๐Ÿ”œ ๐Ÿ“› ๐Ÿ’– `https://qltnci.deta.dev/docs`) ๐Ÿ“จ ๐Ÿ“จ ๐Ÿ‘† *โžก ๐Ÿ› ๏ธ* `/items/{item_id}`.
๐Ÿ–ผ โฎ๏ธ ๐Ÿ†” `5`.
๐Ÿ”œ ๐Ÿšถ <a href="https://web.deta.sh/" class="external-link" target="_blank">https://web.deta.sh</a>.
๐Ÿ‘† ๐Ÿ”œ ๐Ÿ‘€ ๐Ÿ“ค ๐Ÿ“„ โ—€๏ธ ๐Ÿค™ <abbr title="it comes from Micro(server)">"โ—พ"</abbr> โฎ๏ธ ๐Ÿ”  ๐Ÿ‘† ๐Ÿ“ฑ.
๐Ÿ‘† ๐Ÿ”œ ๐Ÿ‘€ ๐Ÿ“‘ โฎ๏ธ "โ„น", &amp; ๐Ÿ“‘ "๐Ÿ•ถ", ๐Ÿšถ ๐Ÿ“‘ "๐Ÿ•ถ".
๐Ÿ“ค ๐Ÿ‘† ๐Ÿ’ช โœ” โฎ๏ธ ๐Ÿ“จ ๐Ÿ“จ ๐Ÿ‘† ๐Ÿ“ฑ.
๐Ÿ‘† ๐Ÿ’ช โœ ๐Ÿ‘ซ &amp; ๐Ÿค-๐Ÿคพ ๐Ÿ‘ซ.
<img src="/img/deployment/deta/image02.png">
## ๐Ÿ’ก ๐ŸŒ…
โ˜, ๐Ÿ‘† ๐Ÿ”œ ๐ŸŽฒ ๐Ÿ’š ๐Ÿช ๐Ÿ’ฝ ๐Ÿ‘† ๐Ÿ“ฑ ๐ŸŒŒ ๐Ÿ‘ˆ ๐Ÿ˜ฃ ๐Ÿ”˜ ๐Ÿ•ฐ. ๐Ÿ‘ˆ ๐Ÿ‘† ๐Ÿ’ช โš™๏ธ <a href="https://docs.deta.sh/docs/base/py_tutorial?ref=fastapi" class="external-link" target="_blank">๐Ÿช” ๐Ÿงข</a>, โšซ๏ธ โœ”๏ธ ๐Ÿ‘ **๐Ÿ†“ ๐ŸŽš**.
๐Ÿ‘† ๐Ÿ’ช โœ ๐ŸŒ… <a href="https://docs.deta.sh?ref=fastapi" class="external-link" target="_blank">๐Ÿช” ๐Ÿฉบ</a>.
## ๐Ÿ› ๏ธ ๐Ÿ”ง
๐Ÿ‘Ÿ ๐Ÿ”™ ๐Ÿ”ง ๐Ÿ‘ฅ ๐Ÿ”ฌ [๐Ÿ› ๏ธ ๐Ÿ”ง](./concepts.md){.internal-link target=_blank}, ๐Ÿ“ฅ โ” ๐Ÿ”  ๐Ÿ‘ซ ๐Ÿ”œ ๐Ÿต โฎ๏ธ ๐Ÿช”:
* **๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ”**: ๐Ÿต ๐Ÿช”, ๐Ÿ‘ซ ๐Ÿ”œ ๐Ÿค ๐Ÿ‘† ๐Ÿ“ &amp; ๐Ÿต ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ” ๐Ÿ”.
* **๐Ÿƒโ€โ™‚ ๐Ÿ”› ๐Ÿ•ด**: ๐Ÿต ๐Ÿช”, ๐Ÿ• ๐Ÿ‘ซ ๐Ÿ•โ€๐Ÿฆบ.
* **โ**: ๐Ÿต ๐Ÿช”, ๐Ÿ• ๐Ÿ‘ซ ๐Ÿ•โ€๐Ÿฆบ.
* **๐Ÿงฌ**: ๐Ÿต ๐Ÿช”, ๐Ÿ• ๐Ÿ‘ซ ๐Ÿ•โ€๐Ÿฆบ.
* **๐Ÿ’พ**: ๐Ÿ“‰ ๐Ÿ” ๐Ÿช”, ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ“ง ๐Ÿ‘ซ ๐Ÿ“ˆ โšซ๏ธ.
* **โฎ๏ธ ๐Ÿ” โญ โ–ถ๏ธ**: ๐Ÿšซ ๐Ÿ”— ๐Ÿ•โ€๐Ÿฆบ, ๐Ÿ‘† ๐Ÿ’ช โš’ โšซ๏ธ ๐Ÿ‘ท โฎ๏ธ ๐Ÿ‘ซ ๐Ÿ’พ โš™๏ธ โš–๏ธ ๐ŸŒ– โœ.
!!! note
๐Ÿช” ๐Ÿ”ง โš’ โšซ๏ธ โฉ (&amp; ๐Ÿ†“) ๐Ÿ› ๏ธ ๐Ÿ™… ๐Ÿˆธ ๐Ÿ”œ.
โšซ๏ธ ๐Ÿ’ช ๐Ÿ“‰ ๐Ÿ“š โš™๏ธ ๐Ÿ’ผ, โœ‹๏ธ ๐ŸŽ ๐Ÿ•ฐ, โšซ๏ธ ๐Ÿšซ ๐Ÿ•โ€๐Ÿฆบ ๐ŸŽ, ๐Ÿ’– โš™๏ธ ๐Ÿ”ข ๐Ÿ’ฝ (โ†–๏ธ โšช๏ธโžก๏ธ ๐Ÿช” ๐Ÿ‘ โ˜ ๐Ÿ’ฝ โš™๏ธ), ๐Ÿ›ƒ ๐Ÿ•น ๐ŸŽฐ, โ™’๏ธ.
๐Ÿ‘† ๐Ÿ’ช โœ ๐ŸŒ… โ„น <a href="https://docs.deta.sh/docs/micros/about/" class="external-link" target="_blank">๐Ÿช” ๐Ÿฉบ</a> ๐Ÿ‘€ ๐Ÿšฅ โšซ๏ธ โ–ถ๏ธ๏ธ โš’ ๐Ÿ‘†.

698
docs/em/docs/deployment/docker.md

@ -0,0 +1,698 @@
# FastAPI ๐Ÿ“ฆ - โ˜
๐Ÿ•โ” ๐Ÿ› ๏ธ FastAPI ๐Ÿˆธ โš  ๐ŸŽฏ ๐Ÿ— **๐Ÿ’พ ๐Ÿ“ฆ ๐Ÿ–ผ**. โšซ๏ธ ๐Ÿ›Ž ๐Ÿ”จ โš™๏ธ <a href="https://www.docker.com/" class="external-link" target="_blank">**โ˜**</a>. ๐Ÿ‘† ๐Ÿ’ช โคด๏ธ ๐Ÿ› ๏ธ ๐Ÿ‘ˆ ๐Ÿ“ฆ ๐Ÿ–ผ 1๏ธโƒฃ ๐Ÿ‘ฉโ€โคโ€๐Ÿ‘จ ๐Ÿ’ช ๐ŸŒŒ.
โš™๏ธ ๐Ÿ’พ ๐Ÿ“ฆ โœ”๏ธ ๐Ÿ“š ๐Ÿ“ˆ โœ… **๐Ÿ’‚โ€โ™‚**, **๐Ÿ”ฌ**, **๐Ÿฆ**, &amp; ๐ŸŽ.
!!! tip
๐Ÿƒ &amp; โช ๐Ÿ’ญ ๐Ÿ‘‰ ๐Ÿ’ฉ โ“ ๐Ÿฆ˜ [`Dockerfile` ๐Ÿ”› ๐Ÿ‘ถ](#build-a-docker-image-for-fastapi).
<details>
<summary>๐Ÿ“ ๐ŸŽฎ ๐Ÿ‘ถ</summary>
```Dockerfile
FROM python:3.9
WORKDIR /code
COPY ./requirements.txt /code/requirements.txt
RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
COPY ./app /code/app
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "80"]
# If running behind a proxy like Nginx or Traefik add --proxy-headers
# CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "80", "--proxy-headers"]
```
</details>
## โšซ๏ธโ” ๐Ÿ“ฆ
๐Ÿ“ฆ (โœด๏ธ ๐Ÿ’พ ๐Ÿ“ฆ) ๐Ÿ“ถ **๐Ÿ’ฟ** ๐ŸŒŒ ๐Ÿ“ฆ ๐Ÿˆธ โœ… ๐ŸŒ ๐Ÿ‘ซ ๐Ÿ”— &amp; ๐Ÿ’ช ๐Ÿ“ โช ๐Ÿšง ๐Ÿ‘ซ โŽ โšช๏ธโžก๏ธ ๐ŸŽ ๐Ÿ“ฆ (๐ŸŽ ๐Ÿˆธ โš–๏ธ ๐Ÿฆฒ) ๐ŸŽ โš™๏ธ.
๐Ÿ’พ ๐Ÿ“ฆ ๐Ÿƒ โš™๏ธ ๐ŸŽ ๐Ÿ’พ ๐Ÿ’พ ๐Ÿฆ  (๐ŸŽฐ, ๐Ÿ•น ๐ŸŽฐ, โ˜ ๐Ÿ’ฝ, โ™’๏ธ). ๐Ÿ‘‰ โ›“ ๐Ÿ‘ˆ ๐Ÿ‘ซ ๐Ÿ“ถ ๐Ÿ’ฟ (๐Ÿ”ฌ ๐ŸŒ• ๐Ÿ•น ๐ŸŽฐ ๐Ÿ‘ ๐ŸŽ‚ ๐Ÿƒโ€โ™‚ โš™๏ธ).
๐Ÿ‘‰ ๐ŸŒŒ, ๐Ÿ“ฆ ๐Ÿด **๐Ÿฅ โ„น**, ๐Ÿ’ธ โญ ๐Ÿƒโ€โ™‚ ๐Ÿ› ๏ธ ๐Ÿ”— (๐Ÿ•น ๐ŸŽฐ ๐Ÿ”œ ๐Ÿด ๐ŸŒ… ๐ŸŒ…).
๐Ÿ“ฆ โœ”๏ธ ๐Ÿ‘ซ ๐Ÿ‘ **โŽ** ๐Ÿƒโ€โ™‚ ๐Ÿ› ๏ธ (๐Ÿ›Ž 1๏ธโƒฃ ๐Ÿ› ๏ธ), ๐Ÿ“ โš™๏ธ, &amp; ๐Ÿ•ธ, ๐Ÿ”ฌ ๐Ÿ› ๏ธ, ๐Ÿ’‚โ€โ™‚, ๐Ÿ› ๏ธ, โ™’๏ธ.
## โšซ๏ธโ” ๐Ÿ“ฆ ๐Ÿ–ผ
**๐Ÿ“ฆ** ๐Ÿƒ โšช๏ธโžก๏ธ **๐Ÿ“ฆ ๐Ÿ–ผ**.
๐Ÿ“ฆ ๐Ÿ–ผ **๐ŸŽป** โฌ ๐ŸŒ ๐Ÿ“, ๐ŸŒ ๐Ÿ”ข, &amp; ๐Ÿ”ข ๐Ÿ“‹/๐Ÿ“‹ ๐Ÿ‘ˆ ๐Ÿ”œ ๐ŸŽ ๐Ÿ“ฆ. **๐ŸŽป** ๐Ÿ“ฅ โ›“ ๐Ÿ‘ˆ ๐Ÿ“ฆ **๐Ÿ–ผ** ๐Ÿšซ ๐Ÿƒ, โšซ๏ธ ๐Ÿšซ โž– ๐Ÿ› ๏ธ, โšซ๏ธ ๐Ÿ•ด ๐Ÿ“ฆ ๐Ÿ“ &amp; ๐Ÿ—ƒ.
๐Ÿ”… "**๐Ÿ“ฆ ๐Ÿ–ผ**" ๐Ÿ‘ˆ ๐Ÿช ๐ŸŽป ๐ŸŽš,"**๐Ÿ“ฆ**" ๐Ÿ›Ž ๐Ÿ”— ๐Ÿƒโ€โ™‚ ๐Ÿ‘, ๐Ÿ‘œ ๐Ÿ‘ˆ โž– **๐Ÿ› ๏ธ**.
๐Ÿ•โ” **๐Ÿ“ฆ** โ–ถ๏ธ &amp; ๐Ÿƒโ€โ™‚ (โ–ถ๏ธ โšช๏ธโžก๏ธ **๐Ÿ“ฆ ๐Ÿ–ผ**) โšซ๏ธ ๐Ÿ’ช โœ โš–๏ธ ๐Ÿ”€ ๐Ÿ“, ๐ŸŒ ๐Ÿ”ข, โ™’๏ธ. ๐Ÿ‘ˆ ๐Ÿ”€ ๐Ÿ”œ ๐Ÿ”€ ๐Ÿ•ด ๐Ÿ‘ˆ ๐Ÿ“ฆ, โœ‹๏ธ ๐Ÿ”œ ๐Ÿšซ ๐Ÿ˜ฃ ๐Ÿ‘ฝ ๐Ÿ“ฆ ๐Ÿ–ผ (๐Ÿ”œ ๐Ÿšซ ๐Ÿ–Š ๐Ÿ’พ).
๐Ÿ“ฆ ๐Ÿ–ผ โญ **๐Ÿ“‹** ๐Ÿ“ &amp; ๐ŸŽš, โœ… `python` &amp; ๐Ÿ“ `main.py`.
&amp; **๐Ÿ“ฆ** โšซ๏ธ (๐Ÿ”… **๐Ÿ“ฆ ๐Ÿ–ผ**) โ˜‘ ๐Ÿƒ ๐Ÿ‘ ๐Ÿ–ผ, โญ **๐Ÿ› ๏ธ**. ๐Ÿ‘, ๐Ÿ“ฆ ๐Ÿƒ ๐Ÿ•ด ๐Ÿ•โ” โšซ๏ธ โœ”๏ธ **๐Ÿ› ๏ธ ๐Ÿƒ** (&amp; ๐Ÿ›Ž โšซ๏ธ ๐Ÿ•ด ๐Ÿ‘ ๐Ÿ› ๏ธ). ๐Ÿ“ฆ โ›”๏ธ ๐Ÿ•โ” ๐Ÿ“ค ๐Ÿ™…โ€โ™‚ ๐Ÿ› ๏ธ ๐Ÿƒ โšซ๏ธ.
## ๐Ÿ“ฆ ๐Ÿ–ผ
โ˜ โœ”๏ธ 1๏ธโƒฃ ๐Ÿ‘‘ ๐Ÿงฐ โœ &amp; ๐Ÿ› ๏ธ **๐Ÿ“ฆ ๐Ÿ–ผ** &amp; **๐Ÿ“ฆ**.
&amp; ๐Ÿ“ค ๐Ÿ“ข <a href="https://hub.docker.com/" class="external-link" target="_blank">โ˜ ๐ŸŽก</a> โฎ๏ธ ๐Ÿค-โš’ **๐Ÿ›‚ ๐Ÿ“ฆ ๐Ÿ–ผ** ๐Ÿ“š ๐Ÿงฐ, ๐ŸŒ, ๐Ÿ’ฝ, &amp; ๐Ÿˆธ.
๐Ÿ–ผ, ๐Ÿ“ค ๐Ÿ›‚ <a href="https://hub.docker.com/_/python" class="external-link" target="_blank">๐Ÿ ๐Ÿ–ผ</a>.
&amp; ๐Ÿ“ค ๐Ÿ“š ๐ŸŽ ๐Ÿ–ผ ๐ŸŽ ๐Ÿ‘œ ๐Ÿ’– ๐Ÿ’ฝ, ๐Ÿ–ผ:
* <a href="https://hub.docker.com/_/postgres" class="external-link" target="_blank">โœณ</a>
* <a href="https://hub.docker.com/_/mysql" class="external-link" target="_blank">โœณ</a>
* <a href="https://hub.docker.com/_/mongo" class="external-link" target="_blank">โœณ</a>
* <a href="https://hub.docker.com/_/redis" class="external-link" target="_blank">โœณ</a>, โ™’๏ธ.
โš™๏ธ ๐Ÿค-โš’ ๐Ÿ“ฆ ๐Ÿ–ผ โšซ๏ธ ๐Ÿ“ถ โฉ **๐ŸŒ€** &amp; โš™๏ธ ๐ŸŽ ๐Ÿงฐ. ๐Ÿ–ผ, ๐Ÿ”„ ๐Ÿ‘… ๐Ÿ†• ๐Ÿ’ฝ. ๐ŸŒ… ๐Ÿ’ผ, ๐Ÿ‘† ๐Ÿ’ช โš™๏ธ **๐Ÿ›‚ ๐Ÿ–ผ**, &amp; ๐Ÿ”— ๐Ÿ‘ซ โฎ๏ธ ๐ŸŒ ๐Ÿ”ข.
๐Ÿ‘ˆ ๐ŸŒŒ, ๐Ÿ“š ๐Ÿ’ผ ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ’ก ๐Ÿ”ƒ ๐Ÿ“ฆ &amp; โ˜ &amp; ๐Ÿค-โš™๏ธ ๐Ÿ‘ˆ ๐Ÿ’ก โฎ๏ธ ๐Ÿ“š ๐ŸŽ ๐Ÿงฐ &amp; ๐Ÿฆฒ.
, ๐Ÿ‘† ๐Ÿ”œ ๐Ÿƒ **๐Ÿ’— ๐Ÿ“ฆ** โฎ๏ธ ๐ŸŽ ๐Ÿ‘œ, ๐Ÿ’– ๐Ÿ’ฝ, ๐Ÿ ๐Ÿˆธ, ๐Ÿ•ธ ๐Ÿ’ฝ โฎ๏ธ ๐Ÿ˜ฅ ๐Ÿ•ธ ๐Ÿˆธ, &amp; ๐Ÿ”— ๐Ÿ‘ซ ๐Ÿ‘ฏโ€โ™‚๏ธ ๐Ÿ“จ ๐Ÿ‘ซ ๐Ÿ”— ๐Ÿ•ธ.
๐ŸŒ ๐Ÿ“ฆ ๐Ÿงพ โš™๏ธ (๐Ÿ’– โ˜ โš–๏ธ Kubernete) โœ”๏ธ ๐Ÿ‘ซ ๐Ÿ•ธ โš’ ๐Ÿ› ๏ธ ๐Ÿ”˜ ๐Ÿ‘ซ.
## ๐Ÿ“ฆ &amp; ๐Ÿ› ๏ธ
**๐Ÿ“ฆ ๐Ÿ–ผ** ๐Ÿ›Ž ๐Ÿ”Œ ๐Ÿšฎ ๐Ÿ—ƒ ๐Ÿ”ข ๐Ÿ“‹ โš–๏ธ ๐Ÿ“‹ ๐Ÿ‘ˆ ๐Ÿ”œ ๐Ÿƒ ๐Ÿ•โ” **๐Ÿ“ฆ** โ–ถ๏ธ &amp; ๐Ÿ”ข ๐Ÿšถโ€โ™€๏ธ ๐Ÿ‘ˆ ๐Ÿ“‹. ๐Ÿ“ถ ๐ŸŽ โšซ๏ธโ” ๐Ÿ”œ ๐Ÿšฅ โšซ๏ธ ๐Ÿ“‹ โธ.
๐Ÿ•โ” **๐Ÿ“ฆ** โ–ถ๏ธ, โšซ๏ธ ๐Ÿ”œ ๐Ÿƒ ๐Ÿ‘ˆ ๐Ÿ“‹/๐Ÿ“‹ (๐Ÿ‘ ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ” โšซ๏ธ &amp; โš’ โšซ๏ธ ๐Ÿƒ ๐ŸŽ ๐Ÿ“‹/๐Ÿ“‹).
๐Ÿ“ฆ ๐Ÿƒ ๐Ÿ“ **๐Ÿ‘‘ ๐Ÿ› ๏ธ** (๐Ÿ“‹ โš–๏ธ ๐Ÿ“‹) ๐Ÿƒ.
๐Ÿ“ฆ ๐Ÿ›Ž โœ”๏ธ **๐Ÿ‘ ๐Ÿ› ๏ธ**, โœ‹๏ธ โšซ๏ธ ๐Ÿ’ช โ–ถ๏ธ โœณ โšช๏ธโžก๏ธ ๐Ÿ‘‘ ๐Ÿ› ๏ธ, &amp; ๐Ÿ‘ˆ ๐ŸŒŒ ๐Ÿ‘† ๐Ÿ”œ โœ”๏ธ **๐Ÿ’— ๐Ÿ› ๏ธ** ๐ŸŽ ๐Ÿ“ฆ.
โœ‹๏ธ โšซ๏ธ ๐Ÿšซ ๐Ÿ’ช โœ”๏ธ ๐Ÿƒโ€โ™‚ ๐Ÿ“ฆ ๐Ÿต **๐ŸŒ˜ 1๏ธโƒฃ ๐Ÿƒโ€โ™‚ ๐Ÿ› ๏ธ**. ๐Ÿšฅ ๐Ÿ‘‘ ๐Ÿ› ๏ธ โ›”๏ธ, ๐Ÿ“ฆ โ›”๏ธ.
## ๐Ÿ— โ˜ ๐Ÿ–ผ FastAPI
๐Ÿ†—, โžก๏ธ ๐Ÿ— ๐Ÿ•ณ ๐Ÿ”œ โ— ๐Ÿ‘ถ
๐Ÿ‘ค ๐Ÿ”œ ๐ŸŽฆ ๐Ÿ‘† โ” ๐Ÿ— **โ˜ ๐Ÿ–ผ** FastAPI **โšช๏ธโžก๏ธ ๐Ÿ–Œ**, โš“๏ธ ๐Ÿ”› **๐Ÿ›‚ ๐Ÿ** ๐Ÿ–ผ.
๐Ÿ‘‰ โšซ๏ธโ” ๐Ÿ‘† ๐Ÿ”œ ๐Ÿ’š **๐Ÿ† ๐Ÿ’ผ**, ๐Ÿ–ผ:
* โš™๏ธ **Kubernete** โš–๏ธ ๐ŸŽ ๐Ÿงฐ
* ๐Ÿ•โ” ๐Ÿƒโ€โ™‚ ๐Ÿ”› **๐Ÿ“ ๐Ÿ‘ฒ**
* โš™๏ธ โ˜ ๐Ÿ•โ€๐Ÿฆบ ๐Ÿ‘ˆ ๐Ÿ”œ ๐Ÿƒ ๐Ÿ“ฆ ๐Ÿ–ผ ๐Ÿ‘†, โ™’๏ธ.
### ๐Ÿ“ฆ ๐Ÿ“„
๐Ÿ‘† ๐Ÿ”œ ๐Ÿ›Ž โœ”๏ธ **๐Ÿ“ฆ ๐Ÿ“„** ๐Ÿ‘† ๐Ÿˆธ ๐Ÿ“.
โšซ๏ธ ๐Ÿ”œ ๐Ÿช€ โœด๏ธ ๐Ÿ”› ๐Ÿงฐ ๐Ÿ‘† โš™๏ธ **โŽ** ๐Ÿ‘ˆ ๐Ÿ“„.
๐ŸŒ… โš  ๐ŸŒŒ โšซ๏ธ โœ”๏ธ ๐Ÿ“ `requirements.txt` โฎ๏ธ ๐Ÿ“ฆ ๐Ÿ“› &amp; ๐Ÿ‘ซ โฌ, 1๏ธโƒฃ ๐Ÿ“ โธ.
๐Ÿ‘† ๐Ÿ”œ โ†—๏ธ โš™๏ธ ๐ŸŽ ๐Ÿ’ญ ๐Ÿ‘† โœ [๐Ÿ”ƒ FastAPI โฌ](./versions.md){.internal-link target=_blank} โš’ โ†” โฌ.
๐Ÿ–ผ, ๐Ÿ‘† `requirements.txt` ๐Ÿ’ช ๐Ÿ‘€ ๐Ÿ’–:
```
fastapi>=0.68.0,<0.69.0
pydantic>=1.8.0,<2.0.0
uvicorn>=0.15.0,<0.16.0
```
&amp; ๐Ÿ‘† ๐Ÿ”œ ๐Ÿ›Ž โŽ ๐Ÿ‘ˆ ๐Ÿ“ฆ ๐Ÿ”— โฎ๏ธ `pip`, ๐Ÿ–ผ:
<div class="termy">
```console
$ pip install -r requirements.txt
---> 100%
Successfully installed fastapi pydantic uvicorn
```
</div>
!!! info
๐Ÿ“ค ๐ŸŽ ๐Ÿ“ &amp; ๐Ÿงฐ ๐Ÿ”ฌ &amp; โŽ ๐Ÿ“ฆ ๐Ÿ”—.
๐Ÿ‘ค ๐Ÿ”œ ๐ŸŽฆ ๐Ÿ‘† ๐Ÿ–ผ โš™๏ธ ๐ŸŽถ โช ๐Ÿ“„ ๐Ÿ”›. ๐Ÿ‘ถ
### โœ **FastAPI** ๐Ÿ“Ÿ
* โœ `app` ๐Ÿ“ &amp; โ›” โšซ๏ธ.
* โœ ๐Ÿ› ๐Ÿ“ `__init__.py`.
* โœ `main.py` ๐Ÿ“ โฎ๏ธ:
```Python
from typing import Union
from fastapi import FastAPI
app = FastAPI()
@app.get("/")
def read_root():
return {"Hello": "World"}
@app.get("/items/{item_id}")
def read_item(item_id: int, q: Union[str, None] = None):
return {"item_id": item_id, "q": q}
```
### ๐Ÿ“
๐Ÿ”œ ๐ŸŽ ๐Ÿ— ๐Ÿ“ โœ ๐Ÿ“ `Dockerfile` โฎ๏ธ:
```{ .dockerfile .annotate }
# (1)
FROM python:3.9
# (2)
WORKDIR /code
# (3)
COPY ./requirements.txt /code/requirements.txt
# (4)
RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
# (5)
COPY ./app /code/app
# (6)
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "80"]
```
1๏ธโƒฃ. โ–ถ๏ธ โšช๏ธโžก๏ธ ๐Ÿ›‚ ๐Ÿ ๐Ÿงข ๐Ÿ–ผ.
2๏ธโƒฃ. โš’ โฎ๏ธ ๐Ÿ‘ท ๐Ÿ“ `/code`.
๐Ÿ‘‰ ๐ŸŒโ” ๐Ÿ‘ฅ ๐Ÿ”œ ๐Ÿšฎ `requirements.txt` ๐Ÿ“ &amp; `app` ๐Ÿ“.
3๏ธโƒฃ. ๐Ÿ“ ๐Ÿ“ โฎ๏ธ ๐Ÿ“„ `/code` ๐Ÿ“.
๐Ÿ“ **๐Ÿ•ด** ๐Ÿ“ โฎ๏ธ ๐Ÿ“„ ๐Ÿฅ‡, ๐Ÿšซ ๐ŸŽ‚ ๐Ÿ“Ÿ.
๐Ÿ‘‰ ๐Ÿ“ **๐Ÿšซ ๐Ÿ”€ ๐Ÿ›Ž**, โ˜ ๐Ÿ”œ ๐Ÿ” โšซ๏ธ &amp; โš™๏ธ **๐Ÿ’พ** ๐Ÿ‘‰ ๐Ÿ”, ๐Ÿ› ๏ธ ๐Ÿ’พ โญ ๐Ÿ” ๐Ÿ’โ€โ™‚๏ธ.
4๏ธโƒฃ. โŽ ๐Ÿ“ฆ ๐Ÿ”— ๐Ÿ“„ ๐Ÿ“.
`--no-cache-dir` ๐ŸŽ› ๐Ÿ’ฌ `pip` ๐Ÿšซ ๐Ÿ–Š โฌ ๐Ÿ“ฆ ๐ŸŒ, ๐Ÿ‘ˆ ๐Ÿ•ด ๐Ÿšฅ `pip` ๐Ÿ”œ ๐Ÿƒ ๐Ÿ”„ โŽ ๐ŸŽ ๐Ÿ“ฆ, โœ‹๏ธ ๐Ÿ‘ˆ ๐Ÿšซ ๐Ÿ’ผ ๐Ÿ•โ” ๐Ÿ‘ท โฎ๏ธ ๐Ÿ“ฆ.
!!! note
`--no-cache-dir` ๐Ÿ•ด ๐Ÿ”— `pip`, โšซ๏ธ โœ”๏ธ ๐Ÿ•ณ โฎ๏ธ โ˜ โš–๏ธ ๐Ÿ“ฆ.
`--upgrade` ๐ŸŽ› ๐Ÿ’ฌ `pip` โ™ป ๐Ÿ“ฆ ๐Ÿšฅ ๐Ÿ‘ซ โช โŽ.
โ†ฉ๏ธ โฎ๏ธ ๐Ÿ” ๐Ÿ–จ ๐Ÿ“ ๐Ÿ’ช ๐Ÿ” **โ˜ ๐Ÿ’พ**, ๐Ÿ‘‰ ๐Ÿ” ๐Ÿ”œ **โš™๏ธ โ˜ ๐Ÿ’พ** ๐Ÿ•โ” ๐Ÿ’ช.
โš™๏ธ ๐Ÿ’พ ๐Ÿ‘‰ ๐Ÿ” ๐Ÿ”œ **๐Ÿ–Š** ๐Ÿ‘† ๐Ÿ“š **๐Ÿ•ฐ** ๐Ÿ•โ” ๐Ÿ— ๐Ÿ–ผ ๐Ÿ”„ &amp; ๐Ÿ”„ โฎ๏ธ ๐Ÿ› ๏ธ, โ†ฉ๏ธ **โฌ &amp; โŽ** ๐ŸŒ ๐Ÿ”— **๐Ÿ”  ๐Ÿ•ฐ**.
5๏ธโƒฃ. ๐Ÿ“ `./app` ๐Ÿ“ ๐Ÿ”˜ `/code` ๐Ÿ“.
๐Ÿ‘‰ โœ”๏ธ ๐ŸŒ ๐Ÿ“Ÿ โ” โšซ๏ธโ” **๐Ÿ”€ ๐ŸŒ… ๐Ÿ›Ž** โ˜ **๐Ÿ’พ** ๐Ÿ† ๐Ÿšซ โš™๏ธ ๐Ÿ‘‰ โš–๏ธ ๐Ÿ™† **๐Ÿ“„ ๐Ÿ”** ๐Ÿ’ช.
, โšซ๏ธ โš  ๐Ÿšฎ ๐Ÿ‘‰ **๐Ÿ˜ ๐Ÿ”š** `Dockerfile`, ๐Ÿ”ฌ ๐Ÿ“ฆ ๐Ÿ–ผ ๐Ÿ— ๐Ÿ•ฐ.
6๏ธโƒฃ. โš’ **๐Ÿ“‹** ๐Ÿƒ `uvicorn` ๐Ÿ’ฝ.
`CMD` โœŠ ๐Ÿ“‡ ๐ŸŽป, ๐Ÿ”  ๐Ÿ‘ซ ๐ŸŽป โšซ๏ธโ” ๐Ÿ‘† ๐Ÿ”œ ๐Ÿ†Ž ๐Ÿ“‹ โธ ๐Ÿ‘ฝ ๐Ÿš€.
๐Ÿ‘‰ ๐Ÿ“‹ ๐Ÿ”œ ๐Ÿƒ โšช๏ธโžก๏ธ **โฎ๏ธ ๐Ÿ‘ท ๐Ÿ“**, ๐ŸŽ `/code` ๐Ÿ“ ๐Ÿ‘† โš’ ๐Ÿ”› โฎ๏ธ `WORKDIR /code`.
โ†ฉ๏ธ ๐Ÿ“‹ ๐Ÿ”œ โ–ถ๏ธ `/code` &amp; ๐Ÿ”˜ โšซ๏ธ ๐Ÿ“ `./app` โฎ๏ธ ๐Ÿ‘† ๐Ÿ“Ÿ, **Uvicorn** ๐Ÿ”œ ๐Ÿ’ช ๐Ÿ‘€ &amp; **๐Ÿ—„** `app` โšช๏ธโžก๏ธ `app.main`.
!!! tip
๐Ÿ“„ โšซ๏ธโ” ๐Ÿ”  โธ ๐Ÿ”จ ๐Ÿ–Š ๐Ÿ”  ๐Ÿ”ข ๐Ÿ’ญ ๐Ÿ“Ÿ. ๐Ÿ‘ถ
๐Ÿ‘† ๐Ÿ”œ ๐Ÿ”œ โœ”๏ธ ๐Ÿ“ ๐Ÿ“Š ๐Ÿ’–:
```
.
โ”œโ”€โ”€ app
โ”‚ย ย  โ”œโ”€โ”€ __init__.py
โ”‚ โ””โ”€โ”€ main.py
โ”œโ”€โ”€ Dockerfile
โ””โ”€โ”€ requirements.txt
```
#### โ›… ๐Ÿค โŽ ๐Ÿ—ณ
๐Ÿšฅ ๐Ÿ‘† ๐Ÿƒโ€โ™‚ ๐Ÿ‘† ๐Ÿ“ฆ โ›… ๐Ÿค โŽ ๐Ÿ—ณ (๐Ÿ“ โš™) ๐Ÿ’– ๐Ÿ‘Œ โš–๏ธ Traefik, ๐Ÿšฎ ๐ŸŽ› `--proxy-headers`, ๐Ÿ‘‰ ๐Ÿ”œ ๐Ÿ’ฌ Uvicorn ๐Ÿ’™ ๐ŸŽš ๐Ÿ“จ ๐Ÿ‘ˆ ๐Ÿ—ณ ๐Ÿ’ฌ โšซ๏ธ ๐Ÿ‘ˆ ๐Ÿˆธ ๐Ÿƒ โ›… ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ”, โ™’๏ธ.
```Dockerfile
CMD ["uvicorn", "app.main:app", "--proxy-headers", "--host", "0.0.0.0", "--port", "80"]
```
#### โ˜ ๐Ÿ’พ
๐Ÿ“ค โš  ๐ŸŽฑ ๐Ÿ‘‰ `Dockerfile`, ๐Ÿ‘ฅ ๐Ÿฅ‡ ๐Ÿ“ **๐Ÿ“ โฎ๏ธ ๐Ÿ”— ๐Ÿ˜ž**, ๐Ÿšซ ๐ŸŽ‚ ๐Ÿ“Ÿ. โžก๏ธ ๐Ÿ‘ค ๐Ÿ’ฌ ๐Ÿ‘† โšซ๏ธโ” ๐Ÿ‘ˆ.
```Dockerfile
COPY ./requirements.txt /code/requirements.txt
```
โ˜ &amp; ๐ŸŽ ๐Ÿงฐ **๐Ÿ—** ๐Ÿ‘‰ ๐Ÿ“ฆ ๐Ÿ–ผ **๐Ÿ”**, ๐Ÿšฎ **1๏ธโƒฃ ๐Ÿงฝ ๐Ÿ”› ๐Ÿ” ๐ŸŽ**, โ–ถ๏ธ โšช๏ธโžก๏ธ ๐Ÿ” `Dockerfile` &amp; โŽ ๐Ÿ™† ๐Ÿ“ โœ ๐Ÿ”  ๐Ÿ‘ฉโ€๐ŸŒพ `Dockerfile`.
โ˜ &amp; ๐ŸŽ ๐Ÿงฐ โš™๏ธ **๐Ÿ”— ๐Ÿ’พ** ๐Ÿ•โ” ๐Ÿ— ๐Ÿ–ผ, ๐Ÿšฅ ๐Ÿ“ ๐Ÿšซ ๐Ÿ”€ โ†ฉ๏ธ ๐Ÿ ๐Ÿ•ฐ ๐Ÿ— ๐Ÿ“ฆ ๐Ÿ–ผ, โคด๏ธ โšซ๏ธ ๐Ÿ”œ **๐Ÿค-โš™๏ธ ๐ŸŽ ๐Ÿงฝ** โœ ๐Ÿ ๐Ÿ•ฐ, โ†ฉ๏ธ ๐Ÿ–จ ๐Ÿ“ ๐Ÿ”„ &amp; ๐Ÿ— ๐Ÿ†• ๐Ÿงฝ โšช๏ธโžก๏ธ ๐Ÿ–Œ.
โŽ ๐Ÿ“ ๐Ÿ“ ๐Ÿšซ ๐ŸŽฏ ๐Ÿ“‰ ๐Ÿ‘œ ๐Ÿ’โ€โ™‚๏ธ ๐ŸŒ…, โœ‹๏ธ โ†ฉ๏ธ โšซ๏ธ โš™๏ธ ๐Ÿ’พ ๐Ÿ‘ˆ ๐Ÿ”, โšซ๏ธ ๐Ÿ’ช **โš™๏ธ ๐Ÿ’พ โญ ๐Ÿ”**. ๐Ÿ–ผ, โšซ๏ธ ๐Ÿ’ช โš™๏ธ ๐Ÿ’พ ๐Ÿ‘ฉโ€๐ŸŒพ ๐Ÿ‘ˆ โŽ ๐Ÿ”— โฎ๏ธ:
```Dockerfile
RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
```
๐Ÿ“ โฎ๏ธ ๐Ÿ“ฆ ๐Ÿ“„ **๐Ÿ† ๐Ÿšซ ๐Ÿ”€ ๐Ÿ›Ž**. , ๐Ÿ–จ ๐Ÿ•ด ๐Ÿ‘ˆ ๐Ÿ“, โ˜ ๐Ÿ”œ ๐Ÿ’ช **โš™๏ธ ๐Ÿ’พ** ๐Ÿ‘ˆ ๐Ÿ”.
&amp; โคด๏ธ, โ˜ ๐Ÿ”œ ๐Ÿ’ช **โš™๏ธ ๐Ÿ’พ โญ ๐Ÿ”** ๐Ÿ‘ˆ โฌ &amp; โŽ ๐Ÿ‘ˆ ๐Ÿ”—. &amp; ๐Ÿ“ฅ ๐ŸŒโ” ๐Ÿ‘ฅ **๐Ÿ–Š ๐Ÿ“š ๐Ÿ•ฐ**. ๐Ÿ‘ถ ...&amp; โŽ ๐Ÿ˜ฉ โŒ›. ๐Ÿ‘ถ ๐Ÿ‘ถ
โฌ &amp; โŽ ๐Ÿ“ฆ ๐Ÿ”— **๐Ÿ’ช โœŠ โฒ**, โœ‹๏ธ โš™๏ธ **๐Ÿ’พ** ๐Ÿ”œ **โœŠ ๐Ÿฅˆ** ๐ŸŒ….
&amp; ๐Ÿ‘† ๐Ÿ”œ ๐Ÿ— ๐Ÿ“ฆ ๐Ÿ–ผ ๐Ÿ”„ &amp; ๐Ÿ”„ โฎ๏ธ ๐Ÿ› ๏ธ โœ… ๐Ÿ‘ˆ ๐Ÿ‘† ๐Ÿ“Ÿ ๐Ÿ”€ ๐Ÿ‘ท, ๐Ÿ“ค ๐Ÿ“š ๐Ÿ“ˆ ๐Ÿ•ฐ ๐Ÿ‘‰ ๐Ÿ”œ ๐Ÿ–Š.
โคด๏ธ, ๐Ÿ˜ ๐Ÿ”š `Dockerfile`, ๐Ÿ‘ฅ ๐Ÿ“ ๐ŸŒ ๐Ÿ“Ÿ. ๐Ÿ‘‰ โšซ๏ธโ” **๐Ÿ”€ ๐Ÿ† ๐Ÿ›Ž**, ๐Ÿ‘ฅ ๐Ÿšฎ โšซ๏ธ ๐Ÿ˜ ๐Ÿ”š, โ†ฉ๏ธ ๐ŸŒ– ๐Ÿ•ง, ๐Ÿ•ณ โฎ๏ธ ๐Ÿ‘‰ ๐Ÿ” ๐Ÿ”œ ๐Ÿšซ ๐Ÿ’ช โš™๏ธ ๐Ÿ’พ.
```Dockerfile
COPY ./app /code/app
```
### ๐Ÿ— โ˜ ๐Ÿ–ผ
๐Ÿ”œ ๐Ÿ‘ˆ ๐ŸŒ ๐Ÿ“ ๐Ÿฅ‰, โžก๏ธ ๐Ÿ— ๐Ÿ“ฆ ๐Ÿ–ผ.
* ๐Ÿšถ ๐Ÿ— ๐Ÿ“ (๐ŸŒโ” ๐Ÿ‘† `Dockerfile` , โš— ๐Ÿ‘† `app` ๐Ÿ“).
* ๐Ÿ— ๐Ÿ‘† FastAPI ๐Ÿ–ผ:
<div class="termy">
```console
$ docker build -t myimage .
---> 100%
```
</div>
!!! tip
๐Ÿ‘€ `.` ๐Ÿ”š, โšซ๏ธ ๐ŸŒ“ `./`, โšซ๏ธ ๐Ÿ’ฌ โ˜ ๐Ÿ“ โš™๏ธ ๐Ÿ— ๐Ÿ“ฆ ๐Ÿ–ผ.
๐Ÿ‘‰ ๐Ÿ’ผ, โšซ๏ธ ๐ŸŽ โฎ๏ธ ๐Ÿ“ (`.`).
### โ–ถ๏ธ โ˜ ๐Ÿ“ฆ
* ๐Ÿƒ ๐Ÿ“ฆ โš“๏ธ ๐Ÿ”› ๐Ÿ‘† ๐Ÿ–ผ:
<div class="termy">
```console
$ docker run -d --name mycontainer -p 80:80 myimage
```
</div>
## โœ… โšซ๏ธ
๐Ÿ‘† ๐Ÿ”œ ๐Ÿ’ช โœ… โšซ๏ธ ๐Ÿ‘† โ˜ ๐Ÿ“ฆ ๐Ÿ“›, ๐Ÿ–ผ: <a href="http://192.168.99.100/items/5?q=somequery" class="external-link" target="_blank">http://192.168.99.100/items/5?q=somequery</a> โš–๏ธ <a href="http://127.0.0.1/items/5?q=somequery" class="external-link" target="_blank">http://127.0.0.1/items/5?q=somequery</a> (โš–๏ธ ๐ŸŒ“, โš™๏ธ ๐Ÿ‘† โ˜ ๐Ÿฆ ).
๐Ÿ‘† ๐Ÿ”œ ๐Ÿ‘€ ๐Ÿ•ณ ๐Ÿ’–:
```JSON
{"item_id": 5, "q": "somequery"}
```
## ๐ŸŽ“ ๐Ÿ› ๏ธ ๐Ÿฉบ
๐Ÿ”œ ๐Ÿ‘† ๐Ÿ’ช ๐Ÿšถ <a href="http://192.168.99.100/docs" class="external-link" target="_blank">http://192.168.99.100/docs</a> โš–๏ธ <a href="http://127.0.0.1/docs" class="external-link" target="_blank">http://127.0.0.1/docs</a> (โš–๏ธ ๐ŸŒ“, โš™๏ธ ๐Ÿ‘† โ˜ ๐Ÿฆ ).
๐Ÿ‘† ๐Ÿ”œ ๐Ÿ‘€ ๐Ÿง ๐ŸŽ“ ๐Ÿ› ๏ธ ๐Ÿงพ (๐Ÿšš <a href="https://github.com/swagger-api/swagger-ui" class="external-link" target="_blank">๐Ÿฆ ๐ŸŽš</a>):
![Swagger UI](https://fastapi.tiangolo.com/img/index/index-01-swagger-ui-simple.png)
## ๐ŸŽ› ๐Ÿ› ๏ธ ๐Ÿฉบ
&amp; ๐Ÿ‘† ๐Ÿ’ช ๐Ÿšถ <a href="http://192.168.99.100/redoc" class="external-link" target="_blank">http://192.168.99.100/redoc</a> โš–๏ธ <a href="http://127.0.0.1/redoc" class="external-link" target="_blank">http://127.0.0.1/redoc</a> (โš–๏ธ ๐ŸŒ“, โš™๏ธ ๐Ÿ‘† โ˜ ๐Ÿฆ ).
๐Ÿ‘† ๐Ÿ”œ ๐Ÿ‘€ ๐ŸŽ› ๐Ÿง ๐Ÿงพ (๐Ÿšš <a href="https://github.com/Rebilly/ReDoc" class="external-link" target="_blank">๐Ÿ“„</a>):
![ReDoc](https://fastapi.tiangolo.com/img/index/index-02-redoc-simple.png)
## ๐Ÿ— โ˜ ๐Ÿ–ผ โฎ๏ธ ๐Ÿ‘-๐Ÿ“ FastAPI
๐Ÿšฅ ๐Ÿ‘† FastAPI ๐Ÿ‘ ๐Ÿ“, ๐Ÿ–ผ, `main.py` ๐Ÿต `./app` ๐Ÿ“, ๐Ÿ‘† ๐Ÿ“ ๐Ÿ“Š ๐Ÿ’ช ๐Ÿ‘€ ๐Ÿ’– ๐Ÿ‘‰:
```
.
โ”œโ”€โ”€ Dockerfile
โ”œโ”€โ”€ main.py
โ””โ”€โ”€ requirements.txt
```
โคด๏ธ ๐Ÿ‘† ๐Ÿ”œ โœ”๏ธ ๐Ÿ”€ ๐Ÿ”— โžก ๐Ÿ“ ๐Ÿ“ ๐Ÿ”˜ `Dockerfile`:
```{ .dockerfile .annotate hl_lines="10 13" }
FROM python:3.9
WORKDIR /code
COPY ./requirements.txt /code/requirements.txt
RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
# (1)
COPY ./main.py /code/
# (2)
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "80"]
```
1๏ธโƒฃ. ๐Ÿ“ `main.py` ๐Ÿ“ `/code` ๐Ÿ“ ๐Ÿ”— (๐Ÿต ๐Ÿ™† `./app` ๐Ÿ“).
2๏ธโƒฃ. ๐Ÿƒ Uvicorn &amp; ๐Ÿ’ฌ โšซ๏ธ ๐Ÿ—„ `app` ๐ŸŽš โšช๏ธโžก๏ธ `main` (โ†ฉ๏ธ ๐Ÿญ โšช๏ธโžก๏ธ `app.main`).
โคด๏ธ ๐Ÿ”† Uvicorn ๐Ÿ“‹ โš™๏ธ ๐Ÿ†• ๐Ÿ•น `main` โ†ฉ๏ธ `app.main` ๐Ÿ—„ FastAPI ๐ŸŽš `app`.
## ๐Ÿ› ๏ธ ๐Ÿ”ง
โžก๏ธ ๐Ÿ’ฌ ๐Ÿ”„ ๐Ÿ”ƒ ๐ŸŽ [๐Ÿ› ๏ธ ๐Ÿ”ง](./concepts.md){.internal-link target=_blank} โš– ๐Ÿ“ฆ.
๐Ÿ“ฆ โœด๏ธ ๐Ÿงฐ ๐Ÿ“‰ ๐Ÿ› ๏ธ **๐Ÿ— &amp; ๐Ÿ› ๏ธ** ๐Ÿˆธ, โœ‹๏ธ ๐Ÿ‘ซ ๐Ÿšซ ๐Ÿ› ๏ธ ๐ŸŽฏ ๐ŸŽฏ ๐Ÿต ๐Ÿ‘‰ **๐Ÿ› ๏ธ ๐Ÿ”ง**, &amp; ๐Ÿ“ค ๐Ÿ“š ๐Ÿ’ช ๐ŸŽ›.
**๐Ÿ‘ ๐Ÿ“ฐ** ๐Ÿ‘ˆ โฎ๏ธ ๐Ÿ”  ๐ŸŽ ๐ŸŽ› ๐Ÿ“ค ๐ŸŒŒ ๐Ÿ“” ๐ŸŒ ๐Ÿ› ๏ธ ๐Ÿ”ง. ๐Ÿ‘ถ
โžก๏ธ ๐Ÿ“„ ๐Ÿ‘‰ **๐Ÿ› ๏ธ ๐Ÿ”ง** โš– ๐Ÿ“ฆ:
* ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ”
* ๐Ÿƒโ€โ™‚ ๐Ÿ”› ๐Ÿ•ด
* โ
* ๐Ÿงฌ (๐Ÿ”ข ๐Ÿ› ๏ธ ๐Ÿƒ)
* ๐Ÿ’พ
* โฎ๏ธ ๐Ÿ” โญ โ–ถ๏ธ
## ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ”
๐Ÿšฅ ๐Ÿ‘ฅ ๐ŸŽฏ ๐Ÿ”› **๐Ÿ“ฆ ๐Ÿ–ผ** FastAPI ๐Ÿˆธ (&amp; โช ๐Ÿƒโ€โ™‚ **๐Ÿ“ฆ**), ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ” ๐Ÿ›Ž ๐Ÿ”œ ๐Ÿต **๐Ÿ—œ** โž•1๏ธโƒฃ ๐Ÿงฐ.
โšซ๏ธ ๐Ÿ’ช โž•1๏ธโƒฃ ๐Ÿ“ฆ, ๐Ÿ–ผ โฎ๏ธ <a href="https://traefik.io/" class="external-link" target="_blank">Traefik</a>, ๐Ÿšš **๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ”** &amp; **๐Ÿง** ๐Ÿ› ๏ธ **๐Ÿ“„**.
!!! tip
Traefik โœ”๏ธ ๐Ÿ› ๏ธ โฎ๏ธ โ˜, Kubernete, &amp; ๐ŸŽ, โšซ๏ธ ๐Ÿ“ถ โฉ โš’ ๐Ÿ†™ &amp; ๐Ÿ”— ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ” ๐Ÿ‘† ๐Ÿ“ฆ โฎ๏ธ โšซ๏ธ.
๐Ÿ‘, ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ” ๐Ÿ’ช ๐Ÿต โ˜ ๐Ÿ•โ€๐Ÿฆบ 1๏ธโƒฃ ๐Ÿ‘ซ ๐Ÿ•โ€๐Ÿฆบ (โช ๐Ÿƒ ๐Ÿˆธ ๐Ÿ“ฆ).
## ๐Ÿƒโ€โ™‚ ๐Ÿ”› ๐Ÿ•ด &amp; โ
๐Ÿ“ค ๐Ÿ›Ž โž•1๏ธโƒฃ ๐Ÿงฐ ๐Ÿˆš **โ–ถ๏ธ &amp; ๐Ÿƒโ€โ™‚** ๐Ÿ‘† ๐Ÿ“ฆ.
โšซ๏ธ ๐Ÿ’ช **โ˜** ๐Ÿ”—, **โ˜ โœ**, **Kubernete**, **โ˜ ๐Ÿ•โ€๐Ÿฆบ**, โ™’๏ธ.
๐ŸŒ… (โš–๏ธ ๐ŸŒ) ๐Ÿ’ผ, ๐Ÿ“ค ๐Ÿ™… ๐ŸŽ› ๐Ÿ› ๏ธ ๐Ÿƒ ๐Ÿ“ฆ ๐Ÿ”› ๐Ÿ•ด &amp; ๐Ÿ› ๏ธ โ ๐Ÿ”› โŒ. ๐Ÿ–ผ, โ˜, โšซ๏ธ ๐Ÿ“‹ โธ ๐ŸŽ› `--restart`.
๐Ÿต โš™๏ธ ๐Ÿ“ฆ, โš’ ๐Ÿˆธ ๐Ÿƒ ๐Ÿ”› ๐Ÿ•ด &amp; โฎ๏ธ โ ๐Ÿ’ช โš  &amp; โš . โœ‹๏ธ ๐Ÿ•โ” **๐Ÿ‘ท โฎ๏ธ ๐Ÿ“ฆ** ๐ŸŒ… ๐Ÿ’ผ ๐Ÿ‘ˆ ๐Ÿ› ๏ธ ๐Ÿ”Œ ๐Ÿ”ข. ๐Ÿ‘ถ
## ๐Ÿงฌ - ๐Ÿ”ข ๐Ÿ› ๏ธ
๐Ÿšฅ ๐Ÿ‘† โœ”๏ธ <abbr title="A group of machines that are configured to be connected and work together in some way.">๐ŸŒ‘</abbr> ๐ŸŽฐ โฎ๏ธ **โ˜**, โ˜ ๐Ÿ ๐Ÿ“ณ, ๐Ÿ––, โš–๏ธ โž•1๏ธโƒฃ ๐ŸŽ ๐Ÿ— โš™๏ธ ๐Ÿ› ๏ธ ๐Ÿ“Ž ๐Ÿ“ฆ ๐Ÿ”› ๐Ÿ’— ๐ŸŽฐ, โคด๏ธ ๐Ÿ‘† ๐Ÿ”œ ๐ŸŽฒ ๐Ÿ’š **๐Ÿต ๐Ÿงฌ** **๐ŸŒ‘ ๐ŸŽš** โ†ฉ๏ธ โš™๏ธ **๐Ÿ› ๏ธ ๐Ÿ‘จโ€๐Ÿ’ผ** (๐Ÿ’– ๐Ÿ โฎ๏ธ ๐Ÿ‘จโ€๐Ÿญ) ๐Ÿ”  ๐Ÿ“ฆ.
1๏ธโƒฃ ๐Ÿ“š ๐Ÿ“Ž ๐Ÿ“ฆ ๐Ÿงพ โš™๏ธ ๐Ÿ’– Kubernete ๐Ÿ›Ž โœ”๏ธ ๐Ÿ› ๏ธ ๐ŸŒŒ ๐Ÿšš **๐Ÿงฌ ๐Ÿ“ฆ** โช ๐Ÿ”— **๐Ÿ“ โš–** ๐Ÿ“จ ๐Ÿ“จ. ๐ŸŒ **๐ŸŒ‘ ๐ŸŽš**.
๐Ÿ“š ๐Ÿ’ผ, ๐Ÿ‘† ๐Ÿ”œ ๐ŸŽฒ ๐Ÿ’š ๐Ÿ— **โ˜ ๐Ÿ–ผ โšช๏ธโžก๏ธ ๐Ÿ–Œ** [๐Ÿ”ฌ ๐Ÿ”›](#dockerfile), โŽ ๐Ÿ‘† ๐Ÿ”—, &amp; ๐Ÿƒโ€โ™‚ **๐Ÿ‘ Uvicorn ๐Ÿ› ๏ธ** โ†ฉ๏ธ ๐Ÿƒโ€โ™‚ ๐Ÿ•ณ ๐Ÿ’– ๐Ÿ โฎ๏ธ Uvicorn ๐Ÿ‘จโ€๐Ÿญ.
### ๐Ÿ“ โš™
๐Ÿ•โ” โš™๏ธ ๐Ÿ“ฆ, ๐Ÿ‘† ๐Ÿ”œ ๐Ÿ›Ž โœ”๏ธ ๐Ÿฆฒ **๐Ÿ‘‚ ๐Ÿ”› ๐Ÿ‘‘ โ›ด**. โšซ๏ธ ๐Ÿ’ช ๐ŸŽฒ โž•1๏ธโƒฃ ๐Ÿ“ฆ ๐Ÿ‘ˆ **๐Ÿค โŽ ๐Ÿ—ณ** ๐Ÿต **๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ”** โš–๏ธ ๐ŸŽ ๐Ÿงฐ.
๐Ÿ‘‰ ๐Ÿฆฒ ๐Ÿ”œ โœŠ **๐Ÿ“** ๐Ÿ“จ &amp; ๐Ÿ“Ž ๐Ÿ‘ˆ ๐Ÿ‘ช ๐Ÿ‘จโ€๐Ÿญ (๐Ÿคž) **โš–** ๐ŸŒŒ, โšซ๏ธ ๐Ÿ›Ž ๐Ÿค™ **๐Ÿ“ โš™**.
!!! tip
๐ŸŽ **๐Ÿค โŽ ๐Ÿ—ณ** ๐Ÿฆฒ โš™๏ธ ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ” ๐Ÿ”œ ๐ŸŽฒ **๐Ÿ“ โš™**.
&amp; ๐Ÿ•โ” ๐Ÿ‘ท โฎ๏ธ ๐Ÿ“ฆ, ๐ŸŽ โš™๏ธ ๐Ÿ‘† โš™๏ธ โ–ถ๏ธ &amp; ๐Ÿ› ๏ธ ๐Ÿ‘ซ ๐Ÿ”œ โช โœ”๏ธ ๐Ÿ”— ๐Ÿงฐ ๐Ÿ“ถ **๐Ÿ•ธ ๐Ÿ“ป** (โœ… ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ” ๐Ÿ“จ) โšช๏ธโžก๏ธ ๐Ÿ‘ˆ **๐Ÿ“ โš™** (๐Ÿ‘ˆ ๐Ÿ’ช **๐Ÿค โŽ ๐Ÿ—ณ**) ๐Ÿ“ฆ(โ“‚) โฎ๏ธ ๐Ÿ‘† ๐Ÿ“ฑ.
### 1๏ธโƒฃ ๐Ÿ“ โš™ - ๐Ÿ’— ๐Ÿ‘จโ€๐Ÿญ ๐Ÿ“ฆ
๐Ÿ•โ” ๐Ÿ‘ท โฎ๏ธ **Kubernete** โš–๏ธ ๐ŸŽ ๐Ÿ“Ž ๐Ÿ“ฆ ๐Ÿงพ โš™๏ธ, โš™๏ธ ๐Ÿ‘ซ ๐Ÿ”— ๐Ÿ•ธ ๐Ÿ› ๏ธ ๐Ÿ”œ โœ” ๐Ÿ‘ **๐Ÿ“ โš™** ๐Ÿ‘ˆ ๐Ÿ‘‚ ๐Ÿ”› ๐Ÿ‘‘ **โ›ด** ๐Ÿ“ถ ๐Ÿ“ป (๐Ÿ“จ) ๐ŸŽฒ **๐Ÿ’— ๐Ÿ“ฆ** ๐Ÿƒ ๐Ÿ‘† ๐Ÿ“ฑ.
๐Ÿ”  ๐Ÿ‘ซ ๐Ÿ“ฆ ๐Ÿƒโ€โ™‚ ๐Ÿ‘† ๐Ÿ“ฑ ๐Ÿ”œ ๐Ÿ›Ž โœ”๏ธ **1๏ธโƒฃ ๐Ÿ› ๏ธ** (โœ… Uvicorn ๐Ÿ› ๏ธ ๐Ÿƒ ๐Ÿ‘† FastAPI ๐Ÿˆธ). ๐Ÿ‘ซ ๐Ÿ”œ ๐ŸŒ **๐ŸŒ“ ๐Ÿ“ฆ**, ๐Ÿƒโ€โ™‚ ๐ŸŽ ๐Ÿ‘œ, โœ‹๏ธ ๐Ÿ”  โฎ๏ธ ๐Ÿšฎ ๐Ÿ‘ ๐Ÿ› ๏ธ, ๐Ÿ’พ, โ™’๏ธ. ๐Ÿ‘ˆ ๐ŸŒŒ ๐Ÿ‘† ๐Ÿ”œ โœŠ ๐Ÿ“ˆ **๐Ÿ› ๏ธ** **๐ŸŽ ๐Ÿš** ๐Ÿ’ฝ, โš–๏ธ **๐ŸŽ ๐ŸŽฐ**.
&amp; ๐Ÿ“Ž ๐Ÿ“ฆ โš™๏ธ โฎ๏ธ **๐Ÿ“ โš™** ๐Ÿ”œ **๐Ÿ“Ž ๐Ÿ“จ** ๐Ÿ”  1๏ธโƒฃ ๐Ÿ“ฆ โฎ๏ธ ๐Ÿ‘† ๐Ÿ“ฑ **๐Ÿ”„**. , ๐Ÿ”  ๐Ÿ“จ ๐Ÿ’ช ๐Ÿต 1๏ธโƒฃ ๐Ÿ’— **๐Ÿ” ๐Ÿ“ฆ** ๐Ÿƒ ๐Ÿ‘† ๐Ÿ“ฑ.
&amp; ๐Ÿ›Ž ๐Ÿ‘‰ **๐Ÿ“ โš™** ๐Ÿ”œ ๐Ÿ’ช ๐Ÿต ๐Ÿ“จ ๐Ÿ‘ˆ ๐Ÿšถ *๐ŸŽ* ๐Ÿ“ฑ ๐Ÿ‘† ๐ŸŒ‘ (โœ… ๐ŸŽ ๐Ÿ†”, โš–๏ธ ๐Ÿ”ฝ ๐ŸŽ ๐Ÿ“› โžก ๐Ÿ”ก), &amp; ๐Ÿ”œ ๐Ÿ“ถ ๐Ÿ‘ˆ ๐Ÿ“ป โ–ถ๏ธ๏ธ ๐Ÿ“ฆ *๐Ÿ‘ˆ ๐ŸŽ* ๐Ÿˆธ ๐Ÿƒโ€โ™‚ ๐Ÿ‘† ๐ŸŒ‘.
### 1๏ธโƒฃ ๐Ÿ› ๏ธ ๐Ÿ“ ๐Ÿ“ฆ
๐Ÿ‘‰ ๐Ÿ†Ž ๐Ÿ˜, ๐Ÿ‘† ๐ŸŽฒ ๐Ÿ”œ ๐Ÿ’š โœ”๏ธ **๐Ÿ‘ (Uvicorn) ๐Ÿ› ๏ธ ๐Ÿ“ ๐Ÿ“ฆ**, ๐Ÿ‘† ๐Ÿ”œ โช ๐Ÿšš ๐Ÿงฌ ๐ŸŒ‘ ๐ŸŽš.
, ๐Ÿ‘‰ ๐Ÿ’ผ, ๐Ÿ‘† **๐Ÿ”œ ๐Ÿšซ** ๐Ÿ’š โœ”๏ธ ๐Ÿ› ๏ธ ๐Ÿ‘จโ€๐Ÿ’ผ ๐Ÿ’– ๐Ÿ โฎ๏ธ Uvicorn ๐Ÿ‘จโ€๐Ÿญ, โš–๏ธ Uvicorn โš™๏ธ ๐Ÿšฎ ๐Ÿ‘ Uvicorn ๐Ÿ‘จโ€๐Ÿญ. ๐Ÿ‘† ๐Ÿ”œ ๐Ÿ’š โœ”๏ธ **๐Ÿ‘ Uvicorn ๐Ÿ› ๏ธ** ๐Ÿ“ ๐Ÿ“ฆ (โœ‹๏ธ ๐ŸŽฒ ๐Ÿ’— ๐Ÿ“ฆ).
โœ”๏ธ โž•1๏ธโƒฃ ๐Ÿ› ๏ธ ๐Ÿ‘จโ€๐Ÿ’ผ ๐Ÿ”˜ ๐Ÿ“ฆ (๐Ÿ”œ โฎ๏ธ ๐Ÿ โš–๏ธ Uvicorn ๐Ÿ› ๏ธ Uvicorn ๐Ÿ‘จโ€๐Ÿญ) ๐Ÿ”œ ๐Ÿ•ด ๐Ÿšฎ **๐Ÿ™ƒ ๐Ÿ”€** ๐Ÿ‘ˆ ๐Ÿ‘† ๐ŸŒ… ๐ŸŽฒ โช โœŠ ๐Ÿ’… โฎ๏ธ ๐Ÿ‘† ๐ŸŒ‘ โš™๏ธ.
### ๐Ÿ“ฆ โฎ๏ธ ๐Ÿ’— ๐Ÿ› ๏ธ &amp; ๐ŸŽ ๐Ÿ’ผ
โ†—๏ธ, ๐Ÿ“ค **๐ŸŽ ๐Ÿ’ผ** ๐ŸŒโ” ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ’š โœ”๏ธ **๐Ÿ“ฆ** โฎ๏ธ **๐Ÿ ๐Ÿ› ๏ธ ๐Ÿ‘จโ€๐Ÿ’ผ** โ–ถ๏ธ ๐Ÿ“š **Uvicorn ๐Ÿ‘จโ€๐Ÿญ ๐Ÿ› ๏ธ** ๐Ÿ”˜.
๐Ÿ“š ๐Ÿ’ผ, ๐Ÿ‘† ๐Ÿ’ช โš™๏ธ **๐Ÿ›‚ โ˜ ๐Ÿ–ผ** ๐Ÿ‘ˆ ๐Ÿ”Œ **๐Ÿ** ๐Ÿ› ๏ธ ๐Ÿ‘จโ€๐Ÿ’ผ ๐Ÿƒโ€โ™‚ ๐Ÿ’— **Uvicorn ๐Ÿ‘จโ€๐Ÿญ ๐Ÿ› ๏ธ**, &amp; ๐Ÿ”ข โš’ ๐Ÿ”† ๐Ÿ”ข ๐Ÿ‘จโ€๐Ÿญ โš“๏ธ ๐Ÿ”› โฎ๏ธ ๐Ÿ’ฝ ๐Ÿš ๐Ÿ”. ๐Ÿ‘ค ๐Ÿ”œ ๐Ÿ’ฌ ๐Ÿ‘† ๐ŸŒ… ๐Ÿ”ƒ โšซ๏ธ ๐Ÿ”› [๐Ÿ›‚ โ˜ ๐Ÿ–ผ โฎ๏ธ ๐Ÿ - Uvicorn](#official-docker-image-with-gunicorn-uvicorn).
๐Ÿ“ฅ ๐Ÿ–ผ ๐Ÿ•โ” ๐Ÿ‘ˆ ๐Ÿ’ช โš’ ๐Ÿ”‘:
#### ๐Ÿ™… ๐Ÿ“ฑ
๐Ÿ‘† ๐Ÿ’ช ๐Ÿ’š ๐Ÿ› ๏ธ ๐Ÿ‘จโ€๐Ÿ’ผ ๐Ÿ“ฆ ๐Ÿšฅ ๐Ÿ‘† ๐Ÿˆธ **๐Ÿ™… ๐Ÿฅƒ** ๐Ÿ‘ˆ ๐Ÿ‘† ๐Ÿšซ ๐Ÿ’ช (๐Ÿฅ ๐Ÿšซ) ๐Ÿ‘Œ-๐ŸŽถ ๐Ÿ”ข ๐Ÿ› ๏ธ ๐Ÿ’โ€โ™‚๏ธ ๐ŸŒ…, &amp; ๐Ÿ‘† ๐Ÿ’ช โš™๏ธ ๐Ÿง ๐Ÿ”ข (โฎ๏ธ ๐Ÿ›‚ โ˜ ๐Ÿ–ผ), &amp; ๐Ÿ‘† ๐Ÿƒโ€โ™‚ โšซ๏ธ ๐Ÿ”› **๐Ÿ‘ ๐Ÿ’ฝ**, ๐Ÿšซ ๐ŸŒ‘.
#### โ˜ โœ
๐Ÿ‘† ๐Ÿ’ช ๐Ÿ› ๏ธ **๐Ÿ‘ ๐Ÿ’ฝ** (๐Ÿšซ ๐ŸŒ‘) โฎ๏ธ **โ˜ โœ**, ๐Ÿ‘† ๐Ÿšซ๐Ÿ”œ โœ”๏ธ โฉ ๐ŸŒŒ ๐Ÿ› ๏ธ ๐Ÿงฌ ๐Ÿ“ฆ (โฎ๏ธ โ˜ โœ) โช ๐Ÿ›ก ๐Ÿ”— ๐Ÿ•ธ &amp; **๐Ÿ“ โš–**.
โคด๏ธ ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ’š โœ”๏ธ **๐Ÿ‘ ๐Ÿ“ฆ** โฎ๏ธ **๐Ÿ› ๏ธ ๐Ÿ‘จโ€๐Ÿ’ผ** โ–ถ๏ธ **๐Ÿ“š ๐Ÿ‘จโ€๐Ÿญ ๐Ÿ› ๏ธ** ๐Ÿ”˜.
#### ๐Ÿคด &amp; ๐ŸŽ ๐Ÿค”
๐Ÿ‘† ๐Ÿ’ช โœ”๏ธ **๐ŸŽ ๐Ÿค”** ๐Ÿ‘ˆ ๐Ÿ”œ โš’ โšซ๏ธ โฉ โœ”๏ธ **๐Ÿ‘ ๐Ÿ“ฆ** โฎ๏ธ **๐Ÿ’— ๐Ÿ› ๏ธ** โ†ฉ๏ธ โœ”๏ธ **๐Ÿ’— ๐Ÿ“ฆ** โฎ๏ธ **๐Ÿ‘ ๐Ÿ› ๏ธ** ๐Ÿ”  ๐Ÿ‘ซ.
๐Ÿ–ผ (๐Ÿช€ ๐Ÿ”› ๐Ÿ‘† ๐Ÿ–ฅ) ๐Ÿ‘† ๐Ÿ’ช โœ”๏ธ ๐Ÿงฐ ๐Ÿ’– ๐Ÿคด ๐Ÿญ ๐ŸŽ ๐Ÿ“ฆ ๐Ÿ‘ˆ ๐Ÿ”œ โœ”๏ธ ๐Ÿ” **๐Ÿ”  ๐Ÿ“จ** ๐Ÿ‘ˆ ๐Ÿ‘Ÿ.
๐Ÿ‘‰ ๐Ÿ’ผ, ๐Ÿšฅ ๐Ÿ‘† โœ”๏ธ **๐Ÿ’— ๐Ÿ“ฆ**, ๐Ÿ”ข, ๐Ÿ•โ” ๐Ÿคด ๐Ÿ‘Ÿ **โœ โš–**, โšซ๏ธ ๐Ÿ”œ ๐Ÿคš ๐Ÿ• **๐Ÿ‘ ๐Ÿ“ฆ ๐Ÿ”  ๐Ÿ•ฐ** (๐Ÿ“ฆ ๐Ÿ‘ˆ ๐Ÿต ๐Ÿ‘ˆ ๐ŸŽฏ ๐Ÿ“จ), โ†ฉ๏ธ ๐Ÿคš **๐Ÿ“ˆ โš–** ๐ŸŒ ๐Ÿ” ๐Ÿ“ฆ.
โคด๏ธ, ๐Ÿ‘ˆ ๐Ÿ’ผ, โšซ๏ธ ๐Ÿ’ช ๐Ÿ™… โœ”๏ธ **1๏ธโƒฃ ๐Ÿ“ฆ** โฎ๏ธ **๐Ÿ’— ๐Ÿ› ๏ธ**, &amp; ๐Ÿ‡ง๐Ÿ‡ฟ ๐Ÿงฐ (โœ… ๐Ÿคด ๐Ÿญ) ๐Ÿ”› ๐ŸŽ ๐Ÿ“ฆ ๐Ÿ“ˆ ๐Ÿคด โš– ๐ŸŒ ๐Ÿ”— ๐Ÿ› ๏ธ &amp; ๐ŸŽฆ ๐Ÿ‘ˆ โš– ๐Ÿ”› ๐Ÿ‘ˆ ๐Ÿ‘ ๐Ÿ“ฆ.
---
๐Ÿ‘‘ โ˜, **๐Ÿ‘Œ** ๐Ÿ‘‰ **๐Ÿšซ โœ ๐Ÿ—ฟ** ๐Ÿ‘ˆ ๐Ÿ‘† โœ”๏ธ ๐Ÿ˜„ โฉ. ๐Ÿ‘† ๐Ÿ’ช โš™๏ธ ๐Ÿ‘ซ ๐Ÿ’ญ **๐Ÿ”ฌ ๐Ÿ‘† ๐Ÿ‘ โš™๏ธ ๐Ÿ’ผ** &amp; ๐Ÿ’ญ โšซ๏ธโ” ๐Ÿ‘ ๐ŸŽฏ ๐Ÿ‘† โš™๏ธ, โœ… ๐Ÿ‘… โ” ๐Ÿ› ๏ธ ๐Ÿ”ง:
* ๐Ÿ’‚โ€โ™‚ - ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ”
* ๐Ÿƒโ€โ™‚ ๐Ÿ”› ๐Ÿ•ด
* โ
* ๐Ÿงฌ (๐Ÿ”ข ๐Ÿ› ๏ธ ๐Ÿƒ)
* ๐Ÿ’พ
* โฎ๏ธ ๐Ÿ” โญ โ–ถ๏ธ
## ๐Ÿ’พ
๐Ÿšฅ ๐Ÿ‘† ๐Ÿƒ **๐Ÿ‘ ๐Ÿ› ๏ธ ๐Ÿ“ ๐Ÿ“ฆ** ๐Ÿ‘† ๐Ÿ”œ โœ”๏ธ ๐ŸŒ… โš–๏ธ ๐ŸŒ˜ ๐Ÿ‘-๐Ÿ”ฌ, โš–, &amp; ๐Ÿ“‰ ๐Ÿ’ธ ๐Ÿ’พ ๐Ÿด ๐Ÿ”  ๐Ÿ‘ˆ ๐Ÿ“ฆ (๐ŸŒ… ๐ŸŒ˜ 1๏ธโƒฃ ๐Ÿšฅ ๐Ÿ‘ซ ๐Ÿ”).
&amp; โคด๏ธ ๐Ÿ‘† ๐Ÿ’ช โš’ ๐Ÿ‘ˆ ๐ŸŽ ๐Ÿ’พ ๐Ÿ“‰ &amp; ๐Ÿ“„ ๐Ÿ‘† ๐Ÿ“ณ ๐Ÿ‘† ๐Ÿ“ฆ ๐Ÿงพ โš™๏ธ (๐Ÿ–ผ **Kubernete**). ๐Ÿ‘ˆ ๐ŸŒŒ โšซ๏ธ ๐Ÿ”œ ๐Ÿ’ช **๐Ÿ” ๐Ÿ“ฆ** **๐Ÿ’ช ๐ŸŽฐ** โœŠ ๐Ÿ”˜ ๐Ÿง ๐Ÿ’ธ ๐Ÿ’พ ๐Ÿ’ช ๐Ÿ‘ซ, &amp; ๐Ÿ’ธ ๐Ÿ’ช ๐ŸŽฐ ๐ŸŒ‘.
๐Ÿšฅ ๐Ÿ‘† ๐Ÿˆธ **๐Ÿ™…**, ๐Ÿ‘‰ ๐Ÿ”œ ๐ŸŽฒ **๐Ÿšซ โš **, &amp; ๐Ÿ‘† ๐Ÿ’ช ๐Ÿšซ ๐Ÿ’ช โœ” ๐Ÿ‹๏ธ ๐Ÿ’พ ๐Ÿ“‰. โœ‹๏ธ ๐Ÿšฅ ๐Ÿ‘† **โš™๏ธ ๐Ÿ“š ๐Ÿ’พ** (๐Ÿ–ผ โฎ๏ธ **๐ŸŽฐ ๐Ÿซ** ๐Ÿท), ๐Ÿ‘† ๐Ÿ”œ โœ… โ” ๐ŸŒ… ๐Ÿ’พ ๐Ÿ‘† ๐Ÿ˜ฉ &amp; ๐Ÿ”† **๐Ÿ”ข ๐Ÿ“ฆ** ๐Ÿ‘ˆ ๐Ÿƒ **๐Ÿ”  ๐ŸŽฐ** (&amp; ๐ŸŽฒ ๐Ÿšฎ ๐ŸŒ– ๐ŸŽฐ ๐Ÿ‘† ๐ŸŒ‘).
๐Ÿšฅ ๐Ÿ‘† ๐Ÿƒ **๐Ÿ’— ๐Ÿ› ๏ธ ๐Ÿ“ ๐Ÿ“ฆ** (๐Ÿ–ผ โฎ๏ธ ๐Ÿ›‚ โ˜ ๐Ÿ–ผ) ๐Ÿ‘† ๐Ÿ”œ โœ”๏ธ โš’ ๐Ÿ’ญ ๐Ÿ‘ˆ ๐Ÿ”ข ๐Ÿ› ๏ธ โ–ถ๏ธ ๐Ÿšซ **๐Ÿด ๐ŸŒ– ๐Ÿ’พ** ๐ŸŒ˜ โšซ๏ธโ” ๐Ÿ’ช.
## โฎ๏ธ ๐Ÿ” โญ โ–ถ๏ธ &amp; ๐Ÿ“ฆ
๐Ÿšฅ ๐Ÿ‘† โš™๏ธ ๐Ÿ“ฆ (โœ… โ˜, Kubernete), โคด๏ธ ๐Ÿ“ค 2๏ธโƒฃ ๐Ÿ‘‘ ๐ŸŽฏ ๐Ÿ‘† ๐Ÿ’ช โš™๏ธ.
### ๐Ÿ’— ๐Ÿ“ฆ
๐Ÿšฅ ๐Ÿ‘† โœ”๏ธ **๐Ÿ’— ๐Ÿ“ฆ**, ๐ŸŽฒ ๐Ÿ”  1๏ธโƒฃ ๐Ÿƒ **๐Ÿ‘ ๐Ÿ› ๏ธ** (๐Ÿ–ผ, **Kubernete** ๐ŸŒ‘), โคด๏ธ ๐Ÿ‘† ๐Ÿ”œ ๐ŸŽฒ ๐Ÿ’š โœ”๏ธ **๐ŸŽ ๐Ÿ“ฆ** ๐Ÿ”จ ๐Ÿ‘ท **โฎ๏ธ ๐Ÿ“ถ** ๐Ÿ‘ ๐Ÿ“ฆ, ๐Ÿƒ ๐Ÿ‘ ๐Ÿ› ๏ธ, **โญ** ๐Ÿƒ ๐Ÿ” ๐Ÿ‘จโ€๐Ÿญ ๐Ÿ“ฆ.
!!! info
๐Ÿšฅ ๐Ÿ‘† โš™๏ธ Kubernete, ๐Ÿ‘‰ ๐Ÿ”œ ๐ŸŽฒ <a href="https://kubernetes.io/docs/concepts/workloads/pods/init-containers/" class="external-link" target="_blank">๐Ÿ•‘ ๐Ÿ“ฆ</a>.
๐Ÿšฅ ๐Ÿ‘† โš™๏ธ ๐Ÿ’ผ ๐Ÿ“ค ๐Ÿ™…โ€โ™‚ โš  ๐Ÿƒโ€โ™‚ ๐Ÿ‘ˆ โฎ๏ธ ๐Ÿ“ถ **๐Ÿ’— ๐Ÿ•ฐ ๐Ÿ”—** (๐Ÿ–ผ ๐Ÿšฅ ๐Ÿ‘† ๐Ÿšซ ๐Ÿƒ ๐Ÿ’ฝ ๐Ÿ› ๏ธ, โœ‹๏ธ โœ… ๐Ÿšฅ ๐Ÿ’ฝ ๐Ÿ”œ), โคด๏ธ ๐Ÿ‘† ๐Ÿ’ช ๐Ÿšฎ ๐Ÿ‘ซ ๐Ÿ”  ๐Ÿ“ฆ โ–ถ๏ธ๏ธ โญ โ–ถ๏ธ ๐Ÿ‘‘ ๐Ÿ› ๏ธ.
### ๐Ÿ‘ ๐Ÿ“ฆ
๐Ÿšฅ ๐Ÿ‘† โœ”๏ธ ๐Ÿ™… ๐Ÿ–ฅ, โฎ๏ธ **๐Ÿ‘ ๐Ÿ“ฆ** ๐Ÿ‘ˆ โคด๏ธ โ–ถ๏ธ ๐Ÿ’— **๐Ÿ‘จโ€๐Ÿญ ๐Ÿ› ๏ธ** (โš–๏ธ 1๏ธโƒฃ ๐Ÿ› ๏ธ), โคด๏ธ ๐Ÿ‘† ๐Ÿ’ช ๐Ÿƒ ๐Ÿ‘ˆ โฎ๏ธ ๐Ÿ” ๐ŸŽ ๐Ÿ“ฆ, โ–ถ๏ธ๏ธ โญ โ–ถ๏ธ ๐Ÿ› ๏ธ โฎ๏ธ ๐Ÿ“ฑ. ๐Ÿ›‚ โ˜ ๐Ÿ–ผ ๐Ÿ•โ€๐Ÿฆบ ๐Ÿ‘‰ ๐Ÿ”˜.
## ๐Ÿ›‚ โ˜ ๐Ÿ–ผ โฎ๏ธ ๐Ÿ - Uvicorn
๐Ÿ“ค ๐Ÿ›‚ โ˜ ๐Ÿ–ผ ๐Ÿ‘ˆ ๐Ÿ”Œ ๐Ÿ ๐Ÿƒโ€โ™‚ โฎ๏ธ Uvicorn ๐Ÿ‘จโ€๐Ÿญ, โ„น โฎ๏ธ ๐Ÿ“ƒ: [๐Ÿ’ฝ ๐Ÿ‘จโ€๐Ÿญ - ๐Ÿ โฎ๏ธ Uvicorn](./server-workers.md){.internal-link target=_blank}.
๐Ÿ‘‰ ๐Ÿ–ผ ๐Ÿ”œ โš  โœด๏ธ โš  ๐Ÿ”ฌ ๐Ÿ”›: [๐Ÿ“ฆ โฎ๏ธ ๐Ÿ’— ๐Ÿ› ๏ธ &amp; ๐ŸŽ ๐Ÿ’ผ](#containers-with-multiple-processes-and-special-cases).
* <a href="https://github.com/tiangolo/uvicorn-gunicorn-fastapi-docker" class="external-link" target="_blank">tiangolo/uvicorn-๐Ÿ-fastapi</a>.
!!! warning
๐Ÿ“ค โ†• ๐Ÿคž ๐Ÿ‘ˆ ๐Ÿ‘† **๐Ÿšซ** ๐Ÿ’ช ๐Ÿ‘‰ ๐Ÿงข ๐Ÿ–ผ โš–๏ธ ๐Ÿ™† ๐ŸŽ ๐ŸŽ 1๏ธโƒฃ, &amp; ๐Ÿ”œ ๐Ÿ‘ป ๐Ÿ“† ๐Ÿ— ๐Ÿ–ผ โšช๏ธโžก๏ธ ๐Ÿ–Œ [๐Ÿ”ฌ ๐Ÿ”›: ๐Ÿ— โ˜ ๐Ÿ–ผ FastAPI](#build-a-docker-image-for-fastapi).
๐Ÿ‘‰ ๐Ÿ–ผ โœ”๏ธ **๐Ÿš˜-๐Ÿ“ณ** ๐Ÿ› ๏ธ ๐Ÿ”Œ โš’ **๐Ÿ”ข ๐Ÿ‘จโ€๐Ÿญ ๐Ÿ› ๏ธ** โš“๏ธ ๐Ÿ”› ๐Ÿ’ฝ ๐Ÿš ๐Ÿ’ช.
โšซ๏ธ โœ”๏ธ **๐Ÿค” ๐Ÿ”ข**, โœ‹๏ธ ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ”€ &amp; โ„น ๐ŸŒ ๐Ÿ“ณ โฎ๏ธ **๐ŸŒ ๐Ÿ”ข** โš–๏ธ ๐Ÿ“ณ ๐Ÿ“.
โšซ๏ธ ๐Ÿ•โ€๐Ÿฆบ ๐Ÿƒ <a href="https://github.com/tiangolo/uvicorn-gunicorn-fastapi-docker#pre_start_path" class="external-link" target="_blank">**โฎ๏ธ ๐Ÿ” โญ โ–ถ๏ธ**</a> โฎ๏ธ โœ.
!!! tip
๐Ÿ‘€ ๐ŸŒ ๐Ÿ“ณ &amp; ๐ŸŽ›, ๐Ÿšถ โ˜ ๐Ÿ–ผ ๐Ÿ“ƒ: <a href="https://github.com/tiangolo/uvicorn-gunicorn-fastapi-docker" class="external-link" target="_blank">Tiangolo/uvicorn-๐Ÿ-fastapi</a>.
### ๐Ÿ”ข ๐Ÿ› ๏ธ ๐Ÿ”› ๐Ÿ›‚ โ˜ ๐Ÿ–ผ
**๐Ÿ”ข ๐Ÿ› ๏ธ** ๐Ÿ”› ๐Ÿ‘‰ ๐Ÿ–ผ **๐Ÿ“Š ๐Ÿ”** โšช๏ธโžก๏ธ ๐Ÿ’ฝ **๐Ÿš** ๐Ÿ’ช.
๐Ÿ‘‰ โ›“ ๐Ÿ‘ˆ โšซ๏ธ ๐Ÿ”œ ๐Ÿ”„ **๐Ÿ—œ** ๐ŸŒ… **๐ŸŽญ** โšช๏ธโžก๏ธ ๐Ÿ’ฝ ๐Ÿ’ช.
๐Ÿ‘† ๐Ÿ’ช ๐Ÿ”† โšซ๏ธ โฎ๏ธ ๐Ÿ“ณ โš™๏ธ **๐ŸŒ ๐Ÿ”ข**, โ™’๏ธ.
โœ‹๏ธ โšซ๏ธ โ›“ ๐Ÿ‘ˆ ๐Ÿ”ข ๐Ÿ› ๏ธ ๐Ÿช€ ๐Ÿ”› ๐Ÿ’ฝ ๐Ÿ“ฆ ๐Ÿƒ, **๐Ÿ’ธ ๐Ÿ’พ ๐Ÿด** ๐Ÿ”œ ๐Ÿช€ ๐Ÿ”› ๐Ÿ‘ˆ.
, ๐Ÿšฅ ๐Ÿ‘† ๐Ÿˆธ ๐Ÿด ๐Ÿ“š ๐Ÿ’พ (๐Ÿ–ผ โฎ๏ธ ๐ŸŽฐ ๐Ÿซ ๐Ÿท), &amp; ๐Ÿ‘† ๐Ÿ’ฝ โœ”๏ธ ๐Ÿ“š ๐Ÿ’ฝ ๐Ÿš **โœ‹๏ธ ๐Ÿฅ ๐Ÿ’พ**, โคด๏ธ ๐Ÿ‘† ๐Ÿ“ฆ ๐Ÿ’ช ๐Ÿ”š ๐Ÿ†™ ๐Ÿ”„ โš™๏ธ ๐ŸŒ… ๐Ÿ’พ ๐ŸŒ˜ โšซ๏ธโ” ๐Ÿ’ช, &amp; ๐Ÿค• ๐ŸŽญ ๐Ÿ“š (โš–๏ธ ๐Ÿ’ฅ). ๐Ÿ‘ถ
### โœ `Dockerfile`
๐Ÿ“ฅ โ” ๐Ÿ‘† ๐Ÿ”œ โœ `Dockerfile` โš“๏ธ ๐Ÿ”› ๐Ÿ‘‰ ๐Ÿ–ผ:
```Dockerfile
FROM tiangolo/uvicorn-gunicorn-fastapi:python3.9
COPY ./requirements.txt /app/requirements.txt
RUN pip install --no-cache-dir --upgrade -r /app/requirements.txt
COPY ./app /app
```
### ๐Ÿฆ ๐Ÿˆธ
๐Ÿšฅ ๐Ÿ‘† โฉ ๐Ÿ“„ ๐Ÿ”ƒ ๐Ÿ— [๐Ÿฆ ๐Ÿˆธ โฎ๏ธ ๐Ÿ’— ๐Ÿ“](../tutorial/bigger-applications.md){.internal-link target=_blank}, ๐Ÿ‘† `Dockerfile` ๐Ÿ’ช โ†ฉ๏ธ ๐Ÿ‘€ ๐Ÿ’–:
```Dockerfile hl_lines="7"
FROM tiangolo/uvicorn-gunicorn-fastapi:python3.9
COPY ./requirements.txt /app/requirements.txt
RUN pip install --no-cache-dir --upgrade -r /app/requirements.txt
COPY ./app /app/app
```
### ๐Ÿ•โ” โš™๏ธ
๐Ÿ‘† ๐Ÿ”œ ๐ŸŽฒ **๐Ÿšซ** โš™๏ธ ๐Ÿ‘‰ ๐Ÿ›‚ ๐Ÿงข ๐Ÿ–ผ (โš–๏ธ ๐Ÿ™† ๐ŸŽ ๐ŸŽ 1๏ธโƒฃ) ๐Ÿšฅ ๐Ÿ‘† โš™๏ธ **Kubernete** (โš–๏ธ ๐ŸŽ) &amp; ๐Ÿ‘† โช โš’ **๐Ÿงฌ** ๐ŸŒ‘ ๐ŸŽš, โฎ๏ธ ๐Ÿ’— **๐Ÿ“ฆ**. ๐Ÿ“š ๐Ÿ’ผ, ๐Ÿ‘† ๐Ÿ‘ ๐Ÿ“† **๐Ÿ— ๐Ÿ–ผ โšช๏ธโžก๏ธ ๐Ÿ–Œ** ๐Ÿ”ฌ ๐Ÿ”›: [๐Ÿ— โ˜ ๐Ÿ–ผ FastAPI](#build-a-docker-image-for-fastapi).
๐Ÿ‘‰ ๐Ÿ–ผ ๐Ÿ”œ โš  โœด๏ธ ๐ŸŽ ๐Ÿ’ผ ๐Ÿ”ฌ ๐Ÿ”› [๐Ÿ“ฆ โฎ๏ธ ๐Ÿ’— ๐Ÿ› ๏ธ &amp; ๐ŸŽ ๐Ÿ’ผ](#containers-with-multiple-processes-and-special-cases). ๐Ÿ–ผ, ๐Ÿšฅ ๐Ÿ‘† ๐Ÿˆธ **๐Ÿ™… ๐Ÿฅƒ** ๐Ÿ‘ˆ โš’ ๐Ÿ”ข ๐Ÿ”ข ๐Ÿ› ๏ธ โš“๏ธ ๐Ÿ”› ๐Ÿ’ฝ ๐Ÿ‘ท ๐Ÿ‘, ๐Ÿ‘† ๐Ÿšซ ๐Ÿ’š ๐Ÿ˜ฅ โฎ๏ธ โŽ ๐Ÿ› ๏ธ ๐Ÿงฌ ๐ŸŒ‘ ๐ŸŽš, &amp; ๐Ÿ‘† ๐Ÿšซ ๐Ÿƒ ๐ŸŒ… ๐ŸŒ˜ 1๏ธโƒฃ ๐Ÿ“ฆ โฎ๏ธ ๐Ÿ‘† ๐Ÿ“ฑ. โš–๏ธ ๐Ÿšฅ ๐Ÿ‘† ๐Ÿ› ๏ธ โฎ๏ธ **โ˜ โœ**, ๐Ÿƒ ๐Ÿ”› ๐Ÿ‘ ๐Ÿ’ฝ, โ™’๏ธ.
## ๐Ÿ› ๏ธ ๐Ÿ“ฆ ๐Ÿ–ผ
โฎ๏ธ โœ”๏ธ ๐Ÿ“ฆ (โ˜) ๐Ÿ–ผ ๐Ÿ“ค ๐Ÿ“š ๐ŸŒŒ ๐Ÿ› ๏ธ โšซ๏ธ.
๐Ÿ–ผ:
* โฎ๏ธ **โ˜ โœ** ๐Ÿ‘ ๐Ÿ’ฝ
* โฎ๏ธ **Kubernete** ๐ŸŒ‘
* โฎ๏ธ โ˜ ๐Ÿ ๐Ÿ“ณ ๐ŸŒ‘
* โฎ๏ธ โž•1๏ธโƒฃ ๐Ÿงฐ ๐Ÿ’– ๐Ÿ––
* โฎ๏ธ โ˜ ๐Ÿ•โ€๐Ÿฆบ ๐Ÿ‘ˆ โœŠ ๐Ÿ‘† ๐Ÿ“ฆ ๐Ÿ–ผ &amp; ๐Ÿ› ๏ธ โšซ๏ธ
## โ˜ ๐Ÿ–ผ โฎ๏ธ ๐ŸŽถ
๐Ÿšฅ ๐Ÿ‘† โš™๏ธ <a href="https://python-poetry.org/" class="external-link" target="_blank">๐ŸŽถ</a> ๐Ÿ› ๏ธ ๐Ÿ‘† ๐Ÿ— ๐Ÿ”—, ๐Ÿ‘† ๐Ÿ’ช โš™๏ธ โ˜ ๐Ÿ‘-โ–ถ๏ธ ๐Ÿ—:
```{ .dockerfile .annotate }
# (1)
FROM python:3.9 as requirements-stage
# (2)
WORKDIR /tmp
# (3)
RUN pip install poetry
# (4)
COPY ./pyproject.toml ./poetry.lock* /tmp/
# (5)
RUN poetry export -f requirements.txt --output requirements.txt --without-hashes
# (6)
FROM python:3.9
# (7)
WORKDIR /code
# (8)
COPY --from=requirements-stage /tmp/requirements.txt /code/requirements.txt
# (9)
RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
# (10)
COPY ./app /code/app
# (11)
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "80"]
```
1๏ธโƒฃ. ๐Ÿ‘‰ ๐Ÿฅ‡ โ–ถ๏ธ, โšซ๏ธ ๐ŸŒŸ `requirements-stage`.
2๏ธโƒฃ. โš’ `/tmp` โฎ๏ธ ๐Ÿ‘ท ๐Ÿ“.
๐Ÿ“ฅ ๐ŸŒโ” ๐Ÿ‘ฅ ๐Ÿ”œ ๐Ÿ— ๐Ÿ“ `requirements.txt`
3๏ธโƒฃ. โŽ ๐ŸŽถ ๐Ÿ‘‰ โ˜ โ–ถ๏ธ.
4๏ธโƒฃ. ๐Ÿ“ `pyproject.toml` &amp; `poetry.lock` ๐Ÿ“ `/tmp` ๐Ÿ“.
โ†ฉ๏ธ โšซ๏ธ โš™๏ธ `./poetry.lock*` (โ–ถ๏ธ โฎ๏ธ `*`), โšซ๏ธ ๐Ÿ† ๐Ÿšซ ๐Ÿ’ฅ ๐Ÿšฅ ๐Ÿ‘ˆ ๐Ÿ“ ๐Ÿšซ ๐Ÿ’ช.
5๏ธโƒฃ. ๐Ÿ— `requirements.txt` ๐Ÿ“.
6๏ธโƒฃ. ๐Ÿ‘‰ ๐Ÿ โ–ถ๏ธ, ๐Ÿ•ณ ๐Ÿ“ฅ ๐Ÿ”œ ๐Ÿ›ก ๐Ÿ ๐Ÿ“ฆ ๐Ÿ–ผ.
7๏ธโƒฃ. โš’ โฎ๏ธ ๐Ÿ‘ท ๐Ÿ“ `/code`.
8๏ธโƒฃ. ๐Ÿ“ `requirements.txt` ๐Ÿ“ `/code` ๐Ÿ“.
๐Ÿ‘‰ ๐Ÿ“ ๐Ÿ•ด ๐Ÿ–– โฎ๏ธ โ˜ โ–ถ๏ธ, ๐Ÿ‘ˆ โšซ๏ธโ” ๐Ÿ‘ฅ โš™๏ธ `--from-requirements-stage` ๐Ÿ“ โšซ๏ธ.
9๏ธโƒฃ. โŽ ๐Ÿ“ฆ ๐Ÿ”— ๐Ÿ— `requirements.txt` ๐Ÿ“.
1๏ธโƒฃ0๏ธโƒฃ. ๐Ÿ“ `app` ๐Ÿ“ `/code` ๐Ÿ“.
1๏ธโƒฃ1๏ธโƒฃ. ๐Ÿƒ `uvicorn` ๐Ÿ“‹, ๐Ÿ’ฌ โšซ๏ธ โš™๏ธ `app` ๐ŸŽš ๐Ÿ—„ โšช๏ธโžก๏ธ `app.main`.
!!! tip
๐Ÿ–Š ๐Ÿ’ญ ๐Ÿ”ข ๐Ÿ‘€ โšซ๏ธโ” ๐Ÿ”  โธ ๐Ÿ”จ.
**โ˜ โ–ถ๏ธ** ๐Ÿ• `Dockerfile` ๐Ÿ‘ˆ ๐Ÿ‘ท **๐Ÿ• ๐Ÿ“ฆ ๐Ÿ–ผ** ๐Ÿ‘ˆ ๐Ÿ•ด โš™๏ธ ๐Ÿ— ๐Ÿ“ โš™๏ธ โช.
๐Ÿฅ‡ โ–ถ๏ธ ๐Ÿ”œ ๐Ÿ•ด โš™๏ธ **โŽ ๐ŸŽถ** &amp; **๐Ÿ— `requirements.txt`** โฎ๏ธ ๐Ÿ‘† ๐Ÿ— ๐Ÿ”— โšช๏ธโžก๏ธ ๐ŸŽถ `pyproject.toml` ๐Ÿ“.
๐Ÿ‘‰ `requirements.txt` ๐Ÿ“ ๐Ÿ”œ โš™๏ธ โฎ๏ธ `pip` โช **โญ โ–ถ๏ธ**.
๐Ÿ ๐Ÿ“ฆ ๐Ÿ–ผ **๐Ÿ•ด ๐Ÿ โ–ถ๏ธ** ๐Ÿ›ก. โฎ๏ธ โ–ถ๏ธ(โ“‚) ๐Ÿ”œ โŽ.
๐Ÿ•โ” โš™๏ธ ๐ŸŽถ, โšซ๏ธ ๐Ÿ”œ โš’ ๐Ÿ”‘ โš™๏ธ **โ˜ ๐Ÿ‘-โ–ถ๏ธ ๐Ÿ—** โ†ฉ๏ธ ๐Ÿ‘† ๐Ÿšซ ๐Ÿค™ ๐Ÿ’ช โœ”๏ธ ๐ŸŽถ &amp; ๐Ÿšฎ ๐Ÿ”— โŽ ๐Ÿ ๐Ÿ“ฆ ๐Ÿ–ผ, ๐Ÿ‘† **๐Ÿ•ด ๐Ÿ’ช** โœ”๏ธ ๐Ÿ— `requirements.txt` ๐Ÿ“ โŽ ๐Ÿ‘† ๐Ÿ— ๐Ÿ”—.
โคด๏ธ โญ (&amp; ๐Ÿ) โ–ถ๏ธ ๐Ÿ‘† ๐Ÿ”œ ๐Ÿ— ๐Ÿ–ผ ๐ŸŒ… โš–๏ธ ๐ŸŒ˜ ๐ŸŽ ๐ŸŒŒ ๐Ÿ”ฌ โญ.
### โ›… ๐Ÿค โŽ ๐Ÿ—ณ - ๐ŸŽถ
๐Ÿ”„, ๐Ÿšฅ ๐Ÿ‘† ๐Ÿƒโ€โ™‚ ๐Ÿ‘† ๐Ÿ“ฆ โ›… ๐Ÿค โŽ ๐Ÿ—ณ (๐Ÿ“ โš™) ๐Ÿ’– ๐Ÿ‘Œ โš–๏ธ Traefik, ๐Ÿšฎ ๐ŸŽ› `--proxy-headers` ๐Ÿ“‹:
```Dockerfile
CMD ["uvicorn", "app.main:app", "--proxy-headers", "--host", "0.0.0.0", "--port", "80"]
```
## ๐ŸŒƒ
โš™๏ธ ๐Ÿ“ฆ โš™๏ธ (โœ… โฎ๏ธ **โ˜** &amp; **Kubernete**) โšซ๏ธ โ–ถ๏ธ๏ธ ๐Ÿ“ถ ๐ŸŽฏ ๐Ÿต ๐ŸŒ **๐Ÿ› ๏ธ ๐Ÿ”ง**:
* ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ”
* ๐Ÿƒโ€โ™‚ ๐Ÿ”› ๐Ÿ•ด
* โ
* ๐Ÿงฌ (๐Ÿ”ข ๐Ÿ› ๏ธ ๐Ÿƒ)
* ๐Ÿ’พ
* โฎ๏ธ ๐Ÿ” โญ โ–ถ๏ธ
๐ŸŒ… ๐Ÿ’ผ, ๐Ÿ‘† ๐ŸŽฒ ๐Ÿ† ๐Ÿšซ ๐Ÿ’š โš™๏ธ ๐Ÿ™† ๐Ÿงข ๐Ÿ–ผ, &amp; โ†ฉ๏ธ **๐Ÿ— ๐Ÿ“ฆ ๐Ÿ–ผ โšช๏ธโžก๏ธ ๐Ÿ–Œ** 1๏ธโƒฃ โš“๏ธ ๐Ÿ”› ๐Ÿ›‚ ๐Ÿ โ˜ ๐Ÿ–ผ.
โœŠ ๐Ÿ’… **โœ”** ๐Ÿ‘ฉโ€๐ŸŒพ `Dockerfile` &amp; **โ˜ ๐Ÿ’พ** ๐Ÿ‘† ๐Ÿ’ช **๐Ÿ“‰ ๐Ÿ— ๐Ÿ•ฐ**, ๐Ÿ“‰ ๐Ÿ‘† ๐Ÿ“ˆ (&amp; โŽ ๐Ÿ˜ฉ). ๐Ÿ‘ถ
๐ŸŽฏ ๐ŸŽ ๐Ÿ’ผ, ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ’š โš™๏ธ ๐Ÿ›‚ โ˜ ๐Ÿ–ผ FastAPI. ๐Ÿ‘ถ

190
docs/em/docs/deployment/https.md

@ -0,0 +1,190 @@
# ๐Ÿ”ƒ ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ”
โšซ๏ธ โฉ ๐Ÿค” ๐Ÿ‘ˆ ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ” ๐Ÿ•ณ ๐Ÿ‘ˆ "๐Ÿ› ๏ธ" โš–๏ธ ๐Ÿšซ.
โœ‹๏ธ โšซ๏ธ ๐ŸŒŒ ๐ŸŒ– ๐Ÿ— ๐ŸŒ˜ ๐Ÿ‘ˆ.
!!! tip
๐Ÿšฅ ๐Ÿ‘† ๐Ÿƒ โš–๏ธ ๐Ÿšซ ๐Ÿ’…, ๐Ÿ˜ฃ โฎ๏ธ โญ ๐Ÿ“„ ๐Ÿ” ๐Ÿ” ๐Ÿ‘ฉโ€๐ŸŒพ โš’ ๐ŸŒ ๐Ÿ†™ โฎ๏ธ ๐ŸŽ โš’.
**๐Ÿ’ก ๐Ÿ”ฐ ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ”**, โšช๏ธโžก๏ธ ๐Ÿฌ ๐Ÿค”, โœ… <a href="https://howhttps.works/" class="external-link" target="_blank">https://howhttps.works/</a>.
๐Ÿ”œ, โšช๏ธโžก๏ธ **๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿค”**, ๐Ÿ“ฅ ๐Ÿ“š ๐Ÿ‘œ โœ”๏ธ ๐Ÿคฏ โช ๐Ÿ’ญ ๐Ÿ”ƒ ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ”:
* ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ”, **๐Ÿ’ฝ** ๐Ÿ’ช **โœ”๏ธ "๐Ÿ“„"** ๐Ÿ— **๐Ÿฅ‰ ๐Ÿฅณ**.
* ๐Ÿ“š ๐Ÿ“„ ๐Ÿค™ **๐Ÿ†** โšช๏ธโžก๏ธ ๐Ÿฅ‰ ๐Ÿฅณ, ๐Ÿšซ "๐Ÿ—".
* ๐Ÿ“„ โœ”๏ธ **1๏ธโƒฃ2๏ธโƒฃ๐Ÿ—“๏ธ**.
* ๐Ÿ‘ซ **๐Ÿ•›**.
* &amp; โคด๏ธ ๐Ÿ‘ซ ๐Ÿ’ช **โ™ป**, **๐Ÿ† ๐Ÿ”„** โšช๏ธโžก๏ธ ๐Ÿฅ‰ ๐Ÿฅณ.
* ๐Ÿ” ๐Ÿ”— ๐Ÿ”จ **๐Ÿ•ธ ๐ŸŽš**.
* ๐Ÿ‘ˆ 1๏ธโƒฃ ๐Ÿงฝ **๐Ÿ”› ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ”**.
* , **๐Ÿ“„ &amp; ๐Ÿ”** ๐Ÿต ๐Ÿ”จ **โญ ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ”**.
* **๐Ÿ•ธ ๐Ÿšซ ๐Ÿ’ญ ๐Ÿ”ƒ "๐Ÿ†”"**. ๐Ÿ•ด ๐Ÿ”ƒ ๐Ÿ“ข ๐Ÿ“ข.
* โ„น ๐Ÿ”ƒ **๐ŸŽฏ ๐Ÿ†”** ๐Ÿ“จ ๐Ÿšถ **๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ” ๐Ÿ’ฝ**.
* **๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ” ๐Ÿ“„** "โœ”" **๐ŸŽฏ ๐Ÿ†”**, โœ‹๏ธ ๐Ÿ› ๏ธ &amp; ๐Ÿ” ๐Ÿ”จ ๐Ÿ•ธ ๐ŸŽš, **โญ ๐Ÿ’ญ** โ” ๐Ÿ†” โž– ๐Ÿ™… โฎ๏ธ.
* **๐Ÿ”ข**, ๐Ÿ‘ˆ ๐Ÿ”œ โ›“ ๐Ÿ‘ˆ ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ•ด โœ”๏ธ **1๏ธโƒฃ ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ” ๐Ÿ“„ ๐Ÿ“ ๐Ÿ“ข ๐Ÿ“ข**.
* ๐Ÿ™…โ€โ™‚ ๐Ÿค” โ” ๐Ÿฆ ๐Ÿ‘† ๐Ÿ’ฝ โš–๏ธ โ” ๐Ÿคช ๐Ÿ”  ๐Ÿˆธ ๐Ÿ‘† โœ”๏ธ ๐Ÿ”› โšซ๏ธ ๐Ÿ’ช.
* ๐Ÿ“ค **โš—** ๐Ÿ‘‰, ๐Ÿ‘.
* ๐Ÿ“ค **โ†”** **๐Ÿค** ๐Ÿ› ๏ธ (1๏ธโƒฃ ๐Ÿšš ๐Ÿ” ๐Ÿ•ธ ๐ŸŽš, โญ ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ”) ๐Ÿค™ **<a href="https://en.wikipedia.org/wiki/Server_Name_Indication" class="external-link" target="_blank"><abbr title="Server Name Indication">๐Ÿ‘ฒ</abbr></a>**.
* ๐Ÿ‘‰ ๐Ÿ‘ฒ โ†” โœ” 1๏ธโƒฃ ๐Ÿ‘ ๐Ÿ’ฝ (โฎ๏ธ **๐Ÿ‘ ๐Ÿ“ข ๐Ÿ“ข**) โœ”๏ธ **๐Ÿ“š ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ” ๐Ÿ“„** &amp; ๐Ÿฆ **๐Ÿ’— ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ” ๐Ÿ†”/๐Ÿˆธ**.
* ๐Ÿ‘‰ ๐Ÿ‘ท, **๐Ÿ‘** ๐Ÿฆฒ (๐Ÿ“‹) ๐Ÿƒ ๐Ÿ”› ๐Ÿ’ฝ, ๐Ÿ‘‚ ๐Ÿ”› **๐Ÿ“ข ๐Ÿ“ข ๐Ÿ“ข**, ๐Ÿ”œ โœ”๏ธ **๐ŸŒ ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ” ๐Ÿ“„** ๐Ÿ’ฝ.
* **โฎ๏ธ** ๐Ÿ† ๐Ÿ” ๐Ÿ”—, ๐Ÿ“ป ๐Ÿ› ๏ธ **๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ”**.
* ๐ŸŽš **๐Ÿ—œ**, โœ‹๏ธ ๐Ÿ‘ซ โž– ๐Ÿ“จ โฎ๏ธ **๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ” ๐Ÿ› ๏ธ**.
โšซ๏ธ โš  ๐Ÿ’ก โœ”๏ธ **1๏ธโƒฃ ๐Ÿ“‹/๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ” ๐Ÿ’ฝ** ๐Ÿƒ ๐Ÿ”› ๐Ÿ’ฝ (๐ŸŽฐ, ๐Ÿฆ , โ™’๏ธ.) &amp; **๐Ÿ› ๏ธ ๐ŸŒ ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ” ๐Ÿ•**: ๐Ÿ“จ **๐Ÿ—œ ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ” ๐Ÿ“จ**, ๐Ÿ“จ **๐Ÿ—œ ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ” ๐Ÿ“จ** โ˜‘ ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ” ๐Ÿˆธ ๐Ÿƒ ๐ŸŽ ๐Ÿ’ฝ ( **FastAPI** ๐Ÿˆธ, ๐Ÿ‘‰ ๐Ÿ’ผ), โœŠ **๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ” ๐Ÿ“จ** โšช๏ธโžก๏ธ ๐Ÿˆธ, **๐Ÿ—œ โšซ๏ธ** โš™๏ธ โ˜‘ **๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ” ๐Ÿ“„** &amp; ๐Ÿ“จ โšซ๏ธ ๐Ÿ”™ ๐Ÿ‘ฉโ€๐Ÿ’ป โš™๏ธ **๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ”**. ๐Ÿ‘‰ ๐Ÿ’ฝ ๐Ÿ›Ž ๐Ÿค™ **<a href="https://en.wikipedia.org/wiki/TLS_termination_proxy" class="external-link" target="_blank">๐Ÿค โŽ ๐Ÿ—ณ</a>**.
๐ŸŽ› ๐Ÿ‘† ๐Ÿ’ช โš™๏ธ ๐Ÿค โŽ ๐Ÿ—ณ:
* Traefik (๐Ÿ‘ˆ ๐Ÿ’ช ๐Ÿต ๐Ÿ“„ ๐Ÿ”•)
* ๐Ÿ“ฅ (๐Ÿ‘ˆ ๐Ÿ’ช ๐Ÿต ๐Ÿ“„ ๐Ÿ”•)
* ๐Ÿ‘Œ
* โœณ
## โžก๏ธ ๐Ÿ—œ
โญ โžก๏ธ ๐Ÿ—œ, ๐Ÿ‘ซ **๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ” ๐Ÿ“„** ๐Ÿ’ฒ ๐Ÿ’™ ๐Ÿฅ‰ ๐Ÿฅณ.
๐Ÿ› ๏ธ ๐Ÿ“Ž 1๏ธโƒฃ ๐Ÿ‘ซ ๐Ÿ“„ โš™๏ธ โš , ๐Ÿšš ๐Ÿ“  &amp; ๐Ÿ“„ ๐Ÿ˜ฅ.
โœ‹๏ธ โคด๏ธ **<a href="https://letsencrypt.org/" class="external-link" target="_blank">โžก๏ธ ๐Ÿ—œ</a>** โœ.
โšซ๏ธ ๐Ÿ— โšช๏ธโžก๏ธ ๐Ÿ’พ ๐Ÿ›. โšซ๏ธ ๐Ÿšš **๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ” ๐Ÿ“„ ๐Ÿ†“**, ๐Ÿง ๐ŸŒŒ. ๐Ÿ‘ซ ๐Ÿ“„ โš™๏ธ ๐ŸŒ ๐Ÿฉ ๐Ÿ” ๐Ÿ’‚โ€โ™‚, &amp; ๐Ÿ“-๐Ÿ–– (๐Ÿ”ƒ 3๏ธโƒฃ ๐Ÿ—“๏ธ), **๐Ÿ’‚โ€โ™‚ ๐Ÿค™ ๐Ÿ‘** โ†ฉ๏ธ ๐Ÿ‘ซ ๐Ÿ“‰ ๐Ÿ”†.
๐Ÿ†” ๐Ÿ” โœ” &amp; ๐Ÿ“„ ๐Ÿ— ๐Ÿ”. ๐Ÿ‘‰ โœ” ๐Ÿง ๐Ÿ”• ๐Ÿ‘ซ ๐Ÿ“„.
๐Ÿ’ญ ๐Ÿง ๐Ÿ› ๏ธ &amp; ๐Ÿ”• ๐Ÿ‘ซ ๐Ÿ“„ ๐Ÿ‘ˆ ๐Ÿ‘† ๐Ÿ’ช โœ”๏ธ **๐Ÿ” ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ”, ๐Ÿ†“, โ™พ**.
## ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ” ๐Ÿ‘ฉโ€๐Ÿ’ป
๐Ÿ“ฅ ๐Ÿ–ผ โ” ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ” ๐Ÿ› ๏ธ ๐Ÿ’ช ๐Ÿ‘€ ๐Ÿ’–, ๐Ÿ” ๐Ÿ”, ๐Ÿ’ธ ๐Ÿ™‹ โœด๏ธ ๐Ÿ’ญ โš  ๐Ÿ‘ฉโ€๐Ÿ’ป.
### ๐Ÿ†” ๐Ÿ“›
โšซ๏ธ ๐Ÿ”œ ๐ŸŽฒ ๐ŸŒ โ–ถ๏ธ ๐Ÿ‘† **๐Ÿ—** **๐Ÿ†” ๐Ÿ“›**. โคด๏ธ, ๐Ÿ‘† ๐Ÿ”œ ๐Ÿ”— โšซ๏ธ ๐Ÿ“ ๐Ÿ’ฝ (๐ŸŽฒ ๐Ÿ‘† ๐ŸŽ โ˜ ๐Ÿ•โ€๐Ÿฆบ).
๐Ÿ‘† ๐Ÿ”œ ๐ŸŽฒ ๐Ÿคš โ˜ ๐Ÿ’ฝ (๐Ÿ•น ๐ŸŽฐ) โš–๏ธ ๐Ÿ•ณ ๐ŸŽ, &amp; โšซ๏ธ ๐Ÿ”œ โœ”๏ธ <abbr title="That doesn't change">๐Ÿ”ง</abbr> **๐Ÿ“ข ๐Ÿ“ข ๐Ÿ“ข**.
๐Ÿ“ ๐Ÿ’ฝ(โ“‚) ๐Ÿ‘† ๐Ÿ”œ ๐Ÿ”— โบ ("`A record`") โ˜ **๐Ÿ‘† ๐Ÿ†”** ๐Ÿ“ข **๐Ÿ“ข ๐Ÿ“ข ๐Ÿ‘† ๐Ÿ’ฝ**.
๐Ÿ‘† ๐Ÿ”œ ๐ŸŽฒ ๐Ÿ‘‰ ๐Ÿ•, ๐Ÿฅ‡ ๐Ÿ•ฐ, ๐Ÿ•โ” โš’ ๐ŸŒ ๐Ÿ†™.
!!! tip
๐Ÿ‘‰ ๐Ÿ†” ๐Ÿ“› ๐Ÿ• ๐ŸŒŒ โญ ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ”, โœ‹๏ธ ๐ŸŒ ๐Ÿช€ ๐Ÿ”› ๐Ÿ†” &amp; ๐Ÿ“ข ๐Ÿ“ข, โšซ๏ธ ๐Ÿ’ธ ๐Ÿ’ฌ โšซ๏ธ ๐Ÿ“ฅ.
### ๐Ÿ“
๐Ÿ”œ โžก๏ธ ๐ŸŽฏ ๐Ÿ”› ๐ŸŒ โ˜‘ ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ” ๐Ÿ•.
๐Ÿฅ‡, ๐Ÿ–ฅ ๐Ÿ”œ โœ… โฎ๏ธ **๐Ÿ“ ๐Ÿ’ฝ** โšซ๏ธโ” **๐Ÿ“ข ๐Ÿ†”**, ๐Ÿ‘‰ ๐Ÿ’ผ, `someapp.example.com`.
๐Ÿ“ ๐Ÿ’ฝ ๐Ÿ”œ ๐Ÿ’ฌ ๐Ÿ–ฅ โš™๏ธ ๐ŸŽฏ **๐Ÿ“ข ๐Ÿ“ข**. ๐Ÿ‘ˆ ๐Ÿ”œ ๐Ÿ“ข ๐Ÿ“ข ๐Ÿ“ข โš™๏ธ ๐Ÿ‘† ๐Ÿ’ฝ, ๐Ÿ‘ˆ ๐Ÿ‘† ๐Ÿ”— ๐Ÿ“ ๐Ÿ’ฝ.
<img src="/img/deployment/https/https01.svg">
### ๐Ÿค ๐Ÿค โ–ถ๏ธ
๐Ÿ–ฅ ๐Ÿ”œ โคด๏ธ ๐Ÿ”— โฎ๏ธ ๐Ÿ‘ˆ ๐Ÿ“ข ๐Ÿ“ข ๐Ÿ”› **โ›ด 4๏ธโƒฃ4๏ธโƒฃ3๏ธโƒฃ** (๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ” โ›ด).
๐Ÿฅ‡ ๐Ÿ• ๐Ÿ“ป ๐Ÿ› ๏ธ ๐Ÿ”— ๐Ÿ–– ๐Ÿ‘ฉโ€๐Ÿ’ป &amp; ๐Ÿ’ฝ &amp; ๐Ÿ’ญ ๐Ÿ” ๐Ÿ”‘ ๐Ÿ‘ซ ๐Ÿ”œ โš™๏ธ, โ™’๏ธ.
<img src="/img/deployment/https/https02.svg">
๐Ÿ‘‰ ๐Ÿ”— ๐Ÿ–– ๐Ÿ‘ฉโ€๐Ÿ’ป &amp; ๐Ÿ’ฝ ๐Ÿ› ๏ธ ๐Ÿค ๐Ÿ”— ๐Ÿค™ **๐Ÿค ๐Ÿค**.
### ๐Ÿค โฎ๏ธ ๐Ÿ‘ฒ โ†”
**๐Ÿ•ด 1๏ธโƒฃ ๐Ÿ› ๏ธ** ๐Ÿ’ฝ ๐Ÿ’ช ๐Ÿ‘‚ ๐Ÿ”› ๐ŸŽฏ **โ›ด** ๐ŸŽฏ **๐Ÿ“ข ๐Ÿ“ข**. ๐Ÿ“ค ๐Ÿ’ช ๐ŸŽ ๐Ÿ› ๏ธ ๐Ÿ‘‚ ๐Ÿ”› ๐ŸŽ โ›ด ๐ŸŽ ๐Ÿ“ข ๐Ÿ“ข, โœ‹๏ธ ๐Ÿ•ด 1๏ธโƒฃ ๐Ÿ”  ๐ŸŒ€ ๐Ÿ“ข ๐Ÿ“ข &amp; โ›ด.
๐Ÿค (๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ”) โš™๏ธ ๐ŸŽฏ โ›ด `443` ๐Ÿ”ข. ๐Ÿ‘ˆ โ›ด ๐Ÿ‘ฅ ๐Ÿ”œ ๐Ÿ’ช.
๐Ÿ•ด 1๏ธโƒฃ ๐Ÿ› ๏ธ ๐Ÿ’ช ๐Ÿ‘‚ ๐Ÿ”› ๐Ÿ‘‰ โ›ด, ๐Ÿ› ๏ธ ๐Ÿ‘ˆ ๐Ÿ”œ โšซ๏ธ ๐Ÿ”œ **๐Ÿค โŽ ๐Ÿ—ณ**.
๐Ÿค โŽ ๐Ÿ—ณ ๐Ÿ”œ โœ”๏ธ ๐Ÿ” 1๏ธโƒฃ โš–๏ธ ๐ŸŒ… **๐Ÿค ๐Ÿ“„** (๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ” ๐Ÿ“„).
โš™๏ธ **๐Ÿ‘ฒ โ†”** ๐Ÿ”ฌ ๐Ÿ”›, ๐Ÿค โŽ ๐Ÿ—ณ ๐Ÿ”œ โœ… โ” ๐Ÿค (๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ”) ๐Ÿ“„ ๐Ÿ’ช โšซ๏ธ ๐Ÿ”œ โš™๏ธ ๐Ÿ‘‰ ๐Ÿ”—, โš™๏ธ 1๏ธโƒฃ ๐Ÿ‘ˆ ๐Ÿ ๐Ÿ†” ๐Ÿ“ˆ ๐Ÿ‘ฉโ€๐Ÿ’ป.
๐Ÿ‘‰ ๐Ÿ’ผ, โšซ๏ธ ๐Ÿ”œ โš™๏ธ ๐Ÿ“„ `someapp.example.com`.
<img src="/img/deployment/https/https03.svg">
๐Ÿ‘ฉโ€๐Ÿ’ป โช **๐Ÿ’™** ๐Ÿ‘จโ€๐Ÿ’ผ ๐Ÿ‘ˆ ๐Ÿ— ๐Ÿ‘ˆ ๐Ÿค ๐Ÿ“„ (๐Ÿ‘‰ ๐Ÿ’ผ โžก๏ธ ๐Ÿ—œ, โœ‹๏ธ ๐Ÿ‘ฅ ๐Ÿ”œ ๐Ÿ‘€ ๐Ÿ”ƒ ๐Ÿ‘ˆ โช), โšซ๏ธ ๐Ÿ’ช **โœ”** ๐Ÿ‘ˆ ๐Ÿ“„ โ˜‘.
โคด๏ธ, โš™๏ธ ๐Ÿ“„, ๐Ÿ‘ฉโ€๐Ÿ’ป &amp; ๐Ÿค โŽ ๐Ÿ—ณ **๐Ÿ’ญ โ” ๐Ÿ—œ** ๐ŸŽ‚ **๐Ÿ•ธ ๐Ÿ“ป**. ๐Ÿ‘‰ ๐Ÿ **๐Ÿค ๐Ÿค** ๐Ÿ•.
โฎ๏ธ ๐Ÿ‘‰, ๐Ÿ‘ฉโ€๐Ÿ’ป &amp; ๐Ÿ’ฝ โœ”๏ธ **๐Ÿ—œ ๐Ÿ•ธ ๐Ÿ”—**, ๐Ÿ‘‰ โšซ๏ธโ” ๐Ÿค ๐Ÿšš. &amp; โคด๏ธ ๐Ÿ‘ซ ๐Ÿ’ช โš™๏ธ ๐Ÿ‘ˆ ๐Ÿ”— โ–ถ๏ธ โ˜‘ **๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ” ๐Ÿ“ป**.
&amp; ๐Ÿ‘ˆ โšซ๏ธโ” **๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ”** , โšซ๏ธ โœ… **๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ”** ๐Ÿ”˜ **๐Ÿ” ๐Ÿค ๐Ÿ”—** โ†ฉ๏ธ ๐Ÿ˜ (๐Ÿ’ฝ) ๐Ÿ•ธ ๐Ÿ”—.
!!! tip
๐Ÿ‘€ ๐Ÿ‘ˆ ๐Ÿ” ๐Ÿ“ป ๐Ÿ”จ **๐Ÿ•ธ ๐ŸŽš**, ๐Ÿšซ ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ” ๐ŸŽš.
### ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ” ๐Ÿ“จ
๐Ÿ”œ ๐Ÿ‘ˆ ๐Ÿ‘ฉโ€๐Ÿ’ป &amp; ๐Ÿ’ฝ (๐ŸŽฏ ๐Ÿ–ฅ &amp; ๐Ÿค โŽ ๐Ÿ—ณ) โœ”๏ธ **๐Ÿ—œ ๐Ÿ•ธ ๐Ÿ”—**, ๐Ÿ‘ซ ๐Ÿ’ช โ–ถ๏ธ **๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ” ๐Ÿ“ป**.
, ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ“จ **๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ” ๐Ÿ“จ**. ๐Ÿ‘‰ ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ” ๐Ÿ“จ ๐Ÿ”˜ ๐Ÿ—œ ๐Ÿค ๐Ÿ”—.
<img src="/img/deployment/https/https04.svg">
### ๐Ÿ—œ ๐Ÿ“จ
๐Ÿค โŽ ๐Ÿ—ณ ๐Ÿ”œ โš™๏ธ ๐Ÿ” โœ” **๐Ÿ—œ ๐Ÿ“จ**, &amp; ๐Ÿ”œ ๐Ÿ“ถ **โœ… (๐Ÿ—œ) ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ” ๐Ÿ“จ** ๐Ÿ› ๏ธ ๐Ÿƒ ๐Ÿˆธ (๐Ÿ–ผ ๐Ÿ› ๏ธ โฎ๏ธ Uvicorn ๐Ÿƒโ€โ™‚ FastAPI ๐Ÿˆธ).
<img src="/img/deployment/https/https05.svg">
### ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ” ๐Ÿ“จ
๐Ÿˆธ ๐Ÿ”œ ๐Ÿ› ๏ธ ๐Ÿ“จ &amp; ๐Ÿ“จ **โœ… (๐Ÿ’ฝ) ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ” ๐Ÿ“จ** ๐Ÿค โŽ ๐Ÿ—ณ.
<img src="/img/deployment/https/https06.svg">
### ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ” ๐Ÿ“จ
๐Ÿค โŽ ๐Ÿ—ณ ๐Ÿ”œ โคด๏ธ **๐Ÿ—œ ๐Ÿ“จ** โš™๏ธ โš› โœ” โญ (๐Ÿ‘ˆ โ–ถ๏ธ โฎ๏ธ ๐Ÿ“„ `someapp.example.com`), &amp; ๐Ÿ“จ โšซ๏ธ ๐Ÿ”™ ๐Ÿ–ฅ.
โญ, ๐Ÿ–ฅ ๐Ÿ”œ โœ” ๐Ÿ‘ˆ ๐Ÿ“จ โ˜‘ &amp; ๐Ÿ—œ โฎ๏ธ โ–ถ๏ธ๏ธ ๐Ÿ” ๐Ÿ”‘, โ™’๏ธ. โšซ๏ธ ๐Ÿ”œ โคด๏ธ **๐Ÿ—œ ๐Ÿ“จ** &amp; ๐Ÿ› ๏ธ โšซ๏ธ.
<img src="/img/deployment/https/https07.svg">
๐Ÿ‘ฉโ€๐Ÿ’ป (๐Ÿ–ฅ) ๐Ÿ”œ ๐Ÿ’ญ ๐Ÿ‘ˆ ๐Ÿ“จ ๐Ÿ‘Ÿ โšช๏ธโžก๏ธ โ˜‘ ๐Ÿ’ฝ โ†ฉ๏ธ โšซ๏ธ โš™๏ธ โš› ๐Ÿ‘ซ โœ” โš™๏ธ **๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ” ๐Ÿ“„** โญ.
### ๐Ÿ’— ๐Ÿˆธ
๐ŸŽ ๐Ÿ’ฝ (โš–๏ธ ๐Ÿ’ฝ), ๐Ÿ“ค ๐Ÿ’ช **๐Ÿ’— ๐Ÿˆธ**, ๐Ÿ–ผ, ๐ŸŽ ๐Ÿ› ๏ธ ๐Ÿ“‹ โš–๏ธ ๐Ÿ’ฝ.
๐Ÿ•ด 1๏ธโƒฃ ๐Ÿ› ๏ธ ๐Ÿ’ช ๐Ÿšš ๐ŸŽฏ ๐Ÿ“ข &amp; โ›ด (๐Ÿค โŽ ๐Ÿ—ณ ๐Ÿ‘† ๐Ÿ–ผ) โœ‹๏ธ ๐ŸŽ ๐Ÿˆธ/๐Ÿ› ๏ธ ๐Ÿ’ช ๐Ÿƒ ๐Ÿ”› ๐Ÿ’ฝ(โ“‚) ๐Ÿ’โ€โ™‚๏ธ, ๐Ÿ“ ๐Ÿ‘ซ ๐Ÿšซ ๐Ÿ”„ โš™๏ธ ๐ŸŽ **๐ŸŒ€ ๐Ÿ“ข ๐Ÿ“ข &amp; โ›ด**.
<img src="/img/deployment/https/https08.svg">
๐Ÿ‘ˆ ๐ŸŒŒ, ๐Ÿค โŽ ๐Ÿ—ณ ๐Ÿ’ช ๐Ÿต ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ” &amp; ๐Ÿ“„ **๐Ÿ’— ๐Ÿ†”**, ๐Ÿ’— ๐Ÿˆธ, &amp; โคด๏ธ ๐Ÿ“ถ ๐Ÿ“จ โ–ถ๏ธ๏ธ ๐Ÿˆธ ๐Ÿ”  ๐Ÿ’ผ.
### ๐Ÿ“„ ๐Ÿ”•
โ˜ ๐Ÿ”ฎ, ๐Ÿ”  ๐Ÿ“„ ๐Ÿ”œ **๐Ÿ•›** (๐Ÿ”ƒ 3๏ธโƒฃ ๐Ÿ—“๏ธ โฎ๏ธ ๐Ÿ— โšซ๏ธ).
&amp; โคด๏ธ, ๐Ÿ“ค ๐Ÿ”œ โž•1๏ธโƒฃ ๐Ÿ“‹ (๐Ÿ’ผ โšซ๏ธ โž•1๏ธโƒฃ ๐Ÿ“‹, ๐Ÿ’ผ โšซ๏ธ ๐Ÿ’ช ๐ŸŽ ๐Ÿค โŽ ๐Ÿ—ณ) ๐Ÿ‘ˆ ๐Ÿ”œ ๐Ÿ’ฌ โžก๏ธ ๐Ÿ—œ, &amp; โ™ป ๐Ÿ“„(โ“‚).
<img src="/img/deployment/https/https.svg">
**๐Ÿค ๐Ÿ“„** **๐Ÿ”— โฎ๏ธ ๐Ÿ†” ๐Ÿ“›**, ๐Ÿšซ โฎ๏ธ ๐Ÿ“ข ๐Ÿ“ข.
, โ™ป ๐Ÿ“„, ๐Ÿ”• ๐Ÿ“‹ ๐Ÿ’ช **๐ŸŽฆ** ๐Ÿ›ƒ (โžก๏ธ ๐Ÿ—œ) ๐Ÿ‘ˆ โšซ๏ธ ๐Ÿ‘ **"๐Ÿ‘" &amp; ๐ŸŽ› ๐Ÿ‘ˆ ๐Ÿ†”**.
๐Ÿ‘ˆ, &amp; ๐Ÿ— ๐ŸŽ ๐Ÿˆธ ๐Ÿ’ช, ๐Ÿ“ค ๐Ÿ“š ๐ŸŒŒ โšซ๏ธ ๐Ÿ’ช โšซ๏ธ. ๐ŸŒŸ ๐ŸŒŒ:
* **๐Ÿ”€ ๐Ÿ“ โบ**.
* ๐Ÿ‘‰, ๐Ÿ”• ๐Ÿ“‹ ๐Ÿ’ช ๐Ÿ•โ€๐Ÿฆบ ๐Ÿ”— ๐Ÿ“ ๐Ÿ•โ€๐Ÿฆบ,, โš“๏ธ ๐Ÿ”› ๐Ÿ“ ๐Ÿ•โ€๐Ÿฆบ ๐Ÿ‘† โš™๏ธ, ๐Ÿ‘‰ 5๏ธโƒฃ๐Ÿ“† โš–๏ธ ๐Ÿ’ช ๐Ÿšซ ๐ŸŽ›.
* **๐Ÿƒ ๐Ÿ’ฝ** (๐ŸŒ˜ โฎ๏ธ ๐Ÿ“„ ๐Ÿ› ๏ธ ๐Ÿ› ๏ธ) ๐Ÿ”› ๐Ÿ“ข ๐Ÿ“ข ๐Ÿ“ข ๐Ÿ”— โฎ๏ธ ๐Ÿ†”.
* ๐Ÿ‘ฅ ๐Ÿ’ฌ ๐Ÿ”›, ๐Ÿ•ด 1๏ธโƒฃ ๐Ÿ› ๏ธ ๐Ÿ’ช ๐Ÿ‘‚ ๐Ÿ”› ๐ŸŽฏ ๐Ÿ“ข &amp; โ›ด.
* ๐Ÿ‘‰ 1๏ธโƒฃ ๐Ÿค” โšซ๏ธโ” โšซ๏ธ ๐Ÿ“ถ โš  ๐Ÿ•โ” ๐ŸŽ ๐Ÿค โŽ ๐Ÿ—ณ โœŠ ๐Ÿ’… ๐Ÿ“„ ๐Ÿ”• ๐Ÿ› ๏ธ.
* โช, ๐Ÿ‘† ๐Ÿ’ช โœ”๏ธ โ›”๏ธ ๐Ÿค โŽ ๐Ÿ—ณ ๐Ÿ˜–, โ–ถ๏ธ ๐Ÿ”• ๐Ÿ“‹ ๐Ÿ“Ž ๐Ÿ“„, โคด๏ธ ๐Ÿ”— ๐Ÿ‘ซ โฎ๏ธ ๐Ÿค โŽ ๐Ÿ—ณ, &amp; โคด๏ธ โ ๐Ÿค โŽ ๐Ÿ—ณ. ๐Ÿ‘‰ ๐Ÿšซ ๐Ÿ’ฏ, ๐Ÿ‘† ๐Ÿ“ฑ(โ“‚) ๐Ÿ”œ ๐Ÿšซ ๐Ÿ’ช โฎ๏ธ ๐Ÿ•ฐ ๐Ÿ‘ˆ ๐Ÿค โŽ ๐Ÿ—ณ ๐Ÿ“†.
๐ŸŒ ๐Ÿ‘‰ ๐Ÿ”• ๐Ÿ› ๏ธ, โช ๐Ÿฆ ๐Ÿ“ฑ, 1๏ธโƒฃ ๐Ÿ‘‘ ๐Ÿค” โšซ๏ธโ” ๐Ÿ‘† ๐Ÿ”œ ๐Ÿ’š โœ”๏ธ **๐ŸŽ โš™๏ธ ๐Ÿต ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ”** โฎ๏ธ ๐Ÿค โŽ ๐Ÿ—ณ โ†ฉ๏ธ โš™๏ธ ๐Ÿค ๐Ÿ“„ โฎ๏ธ ๐Ÿˆธ ๐Ÿ’ฝ ๐Ÿ”— (โœ… Uvicorn).
## ๐ŸŒƒ
โœ”๏ธ **๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ”** ๐Ÿ“ถ โš , &amp; **๐ŸŽฏ** ๐Ÿ† ๐Ÿ’ผ. ๐ŸŒ… ๐ŸŽฏ ๐Ÿ‘† ๐Ÿ‘ฉโ€๐Ÿ’ป โœ”๏ธ ๐Ÿšฎ ๐Ÿคญ ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ” ๐Ÿ”ƒ **๐Ÿค” ๐Ÿ‘‰ ๐Ÿ”ง** &amp; โ” ๐Ÿ‘ซ ๐Ÿ‘ท.
โœ‹๏ธ ๐Ÿ• ๐Ÿ‘† ๐Ÿ’ญ ๐Ÿ”ฐ โ„น **๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ” ๐Ÿ‘ฉโ€๐Ÿ’ป** ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ’ช ๐ŸŒ€ &amp; ๐Ÿ”— ๐ŸŽ ๐Ÿงฐ โ„น ๐Ÿ‘† ๐Ÿ› ๏ธ ๐ŸŒ ๐Ÿ™… ๐ŸŒŒ.
โญ ๐Ÿ“ƒ, ๐Ÿ‘ค ๐Ÿ”œ ๐ŸŽฆ ๐Ÿ‘† ๐Ÿ“š ๐Ÿงฑ ๐Ÿ–ผ โ” โš’ ๐Ÿ†™ **๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ”** **FastAPI** ๐Ÿˆธ. ๐Ÿ‘ถ

21
docs/em/docs/deployment/index.md

@ -0,0 +1,21 @@
# ๐Ÿ› ๏ธ - ๐ŸŽถ
๐Ÿ› ๏ธ **FastAPI** ๐Ÿˆธ ๐Ÿ“ถ โฉ.
## โšซ๏ธโ” ๐Ÿ”จ ๐Ÿ› ๏ธ โ›“
**๐Ÿ› ๏ธ** ๐Ÿˆธ โ›“ ๐ŸŽญ ๐Ÿ’ช ๐Ÿ“ถ โš’ โšซ๏ธ **๐Ÿ’ช ๐Ÿ‘ฉโ€๐Ÿ’ป**.
**๐Ÿ•ธ ๐Ÿ› ๏ธ**, โšซ๏ธ ๐Ÿ›Ž ๐Ÿ”Œ ๐Ÿšฎ โšซ๏ธ **๐Ÿ›ฐ ๐ŸŽฐ**, โฎ๏ธ **๐Ÿ’ฝ ๐Ÿ“‹** ๐Ÿ‘ˆ ๐Ÿšš ๐Ÿ‘ ๐ŸŽญ, โš–, โ™’๏ธ, ๐Ÿ‘ˆ ๐Ÿ‘† **๐Ÿ‘ฉโ€๐Ÿ’ป** ๐Ÿ’ช **๐Ÿ”** ๐Ÿˆธ โ™ป &amp; ๐Ÿต ๐Ÿ” โš–๏ธ โš .
๐Ÿ‘‰ ๐Ÿ”… **๐Ÿ› ๏ธ** โ–ถ๏ธ, ๐ŸŒโ” ๐Ÿ‘† ๐Ÿ•ง ๐Ÿ”€ ๐Ÿ“Ÿ, ๐Ÿ’” โšซ๏ธ &amp; โ™ป โšซ๏ธ, โ›”๏ธ &amp; ๐Ÿ” ๐Ÿ› ๏ธ ๐Ÿ’ฝ, โ™’๏ธ.
## ๐Ÿ› ๏ธ ๐ŸŽ›
๐Ÿ“ค ๐Ÿ“š ๐ŸŒŒ โšซ๏ธ โš“๏ธ ๐Ÿ”› ๐Ÿ‘† ๐ŸŽฏ โš™๏ธ ๐Ÿ’ผ &amp; ๐Ÿงฐ ๐Ÿ‘ˆ ๐Ÿ‘† โš™๏ธ.
๐Ÿ‘† ๐Ÿ’ช **๐Ÿ› ๏ธ ๐Ÿ’ฝ** ๐Ÿ‘† โš™๏ธ ๐ŸŒ€ ๐Ÿงฐ, ๐Ÿ‘† ๐Ÿ’ช โš™๏ธ **โ˜ ๐Ÿ•โ€๐Ÿฆบ** ๐Ÿ‘ˆ ๐Ÿ”จ ๐Ÿ• ๐Ÿ‘ท ๐Ÿ‘†, โš–๏ธ ๐ŸŽ ๐Ÿ’ช ๐ŸŽ›.
๐Ÿ‘ค ๐Ÿ”œ ๐ŸŽฆ ๐Ÿ‘† ๐Ÿ‘‘ ๐Ÿ”ง ๐Ÿ‘† ๐Ÿ”œ ๐ŸŽฒ โœ”๏ธ ๐Ÿคฏ ๐Ÿ•โ” ๐Ÿ› ๏ธ **FastAPI** ๐Ÿˆธ (๐Ÿ‘ ๐ŸŒ… โšซ๏ธ โœ” ๐Ÿ™† ๐ŸŽ ๐Ÿ†Ž ๐Ÿ•ธ ๐Ÿˆธ).
๐Ÿ‘† ๐Ÿ”œ ๐Ÿ‘€ ๐ŸŒ– โ„น โœ”๏ธ ๐Ÿคฏ &amp; โš’ โšซ๏ธ โญ ๐Ÿ“„. ๐Ÿ‘ถ

145
docs/em/docs/deployment/manually.md

@ -0,0 +1,145 @@
# ๐Ÿƒ ๐Ÿ’ฝ โŽ - Uvicorn
๐Ÿ‘‘ ๐Ÿ‘œ ๐Ÿ‘† ๐Ÿ’ช ๐Ÿƒ **FastAPI** ๐Ÿˆธ ๐Ÿ›ฐ ๐Ÿ’ฝ ๐ŸŽฐ ๐Ÿ”ซ ๐Ÿ’ฝ ๐Ÿ“‹ ๐Ÿ’– **Uvicorn**.
๐Ÿ“ค 3๏ธโƒฃ ๐Ÿ‘‘ ๐ŸŽ›:
* <a href="https://www.uvicorn.org/" class="external-link" target="_blank">Uvicorn</a>: โ†• ๐ŸŽญ ๐Ÿ”ซ ๐Ÿ’ฝ.
* <a href="https://pgjones.gitlab.io/hypercorn/" class="external-link" target="_blank">Hypercorn</a>: ๐Ÿ”ซ ๐Ÿ’ฝ ๐Ÿ”— โฎ๏ธ ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ”/2๏ธโƒฃ &amp; ๐ŸŽป ๐Ÿ‘ช ๐ŸŽ โš’.
* <a href="https://github.com/django/daphne" class="external-link" target="_blank">๐Ÿ‘ธ</a>: ๐Ÿ”ซ ๐Ÿ’ฝ ๐Ÿ— โœณ ๐Ÿ“ป.
## ๐Ÿ’ฝ ๐ŸŽฐ &amp; ๐Ÿ’ฝ ๐Ÿ“‹
๐Ÿ“ค ๐Ÿคช โ„น ๐Ÿ”ƒ ๐Ÿ“› โœ”๏ธ ๐Ÿคฏ. ๐Ÿ‘ถ
๐Ÿ”ค "**๐Ÿ’ฝ**" ๐Ÿ›Ž โš™๏ธ ๐Ÿ”— ๐Ÿ‘ฏโ€โ™‚๏ธ ๐Ÿ›ฐ/โ˜ ๐Ÿ’ป (โš› โš–๏ธ ๐Ÿ•น ๐ŸŽฐ) &amp; ๐Ÿ“‹ ๐Ÿ‘ˆ ๐Ÿƒโ€โ™‚ ๐Ÿ”› ๐Ÿ‘ˆ ๐ŸŽฐ (โœ… Uvicorn).
โœ”๏ธ ๐Ÿ‘ˆ ๐Ÿคฏ ๐Ÿ•โ” ๐Ÿ‘† โœ "๐Ÿ’ฝ" ๐Ÿข, โšซ๏ธ ๐Ÿ’ช ๐Ÿ”— 1๏ธโƒฃ ๐Ÿ“š 2๏ธโƒฃ ๐Ÿ‘œ.
๐Ÿ•โ” ๐Ÿ”— ๐Ÿ›ฐ ๐ŸŽฐ, โšซ๏ธ โš  ๐Ÿค™ โšซ๏ธ **๐Ÿ’ฝ**, โœ‹๏ธ **๐ŸŽฐ**, **๐Ÿ’พ** (๐Ÿ•น ๐ŸŽฐ), **๐Ÿ•ธ**. ๐Ÿ‘ˆ ๐ŸŒ ๐Ÿ”— ๐Ÿ†Ž ๐Ÿ›ฐ ๐ŸŽฐ, ๐Ÿ›Ž ๐Ÿƒโ€โ™‚ ๐Ÿ’พ, ๐ŸŒโ” ๐Ÿ‘† ๐Ÿƒ ๐Ÿ“‹.
## โŽ ๐Ÿ’ฝ ๐Ÿ“‹
๐Ÿ‘† ๐Ÿ’ช โŽ ๐Ÿ”ซ ๐Ÿ”— ๐Ÿ’ฝ โฎ๏ธ:
=== "Uvicorn"
* <a href="https://www.uvicorn.org/" class="external-link" target="_blank">Uvicorn</a>, ๐ŸŒฉ-โฉ ๐Ÿ”ซ ๐Ÿ’ฝ, ๐Ÿ— ๐Ÿ”› uvloop &amp; httptool.
<div class="termy">
```console
$ pip install "uvicorn[standard]"
---> 100%
```
</div>
!!! tip
โŽ `standard`, Uvicorn ๐Ÿ”œ โŽ &amp; โš™๏ธ ๐Ÿ‘ โž• ๐Ÿ”—.
๐Ÿ‘ˆ โœ… `uvloop`, โ†•-๐ŸŽญ ๐Ÿ’ง-โ™ป `asyncio`, ๐Ÿ‘ˆ ๐Ÿšš ๐Ÿฆ ๐Ÿ› ๏ธ ๐ŸŽญ ๐Ÿ“ˆ.
=== "Hypercorn"
* <a href="https://gitlab.com/pgjones/hypercorn" class="external-link" target="_blank">Hypercorn</a>, ๐Ÿ”ซ ๐Ÿ’ฝ ๐Ÿ”— โฎ๏ธ ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ”/2๏ธโƒฃ.
<div class="termy">
```console
$ pip install hypercorn
---> 100%
```
</div>
...โš–๏ธ ๐Ÿ™† ๐ŸŽ ๐Ÿ”ซ ๐Ÿ’ฝ.
## ๐Ÿƒ ๐Ÿ’ฝ ๐Ÿ“‹
๐Ÿ‘† ๐Ÿ’ช โคด๏ธ ๐Ÿƒ ๐Ÿ‘† ๐Ÿˆธ ๐ŸŽ ๐ŸŒŒ ๐Ÿ‘† โœ”๏ธ โŒ› ๐Ÿ”ฐ, โœ‹๏ธ ๐Ÿต `--reload` ๐ŸŽ›, โœ…:
=== "Uvicorn"
<div class="termy">
```console
$ uvicorn main:app --host 0.0.0.0 --port 80
<span style="color: green;">INFO</span>: Uvicorn running on http://0.0.0.0:80 (Press CTRL+C to quit)
```
</div>
=== "Hypercorn"
<div class="termy">
```console
$ hypercorn main:app --bind 0.0.0.0:80
Running on 0.0.0.0:8080 over http (CTRL + C to quit)
```
</div>
!!! warning
๐Ÿ’ญ โŽ `--reload` ๐ŸŽ› ๐Ÿšฅ ๐Ÿ‘† โš™๏ธ โšซ๏ธ.
`--reload` ๐ŸŽ› ๐Ÿด ๐ŸŒ… ๐ŸŒ… โ„น, ๐ŸŒ… โš , โ™’๏ธ.
โšซ๏ธ โ„น ๐Ÿ“š โฎ๏ธ **๐Ÿ› ๏ธ**, โœ‹๏ธ ๐Ÿ‘† **๐Ÿšซ๐Ÿ”œ ๐Ÿšซ** โš™๏ธ โšซ๏ธ **๐Ÿญ**.
## Hypercorn โฎ๏ธ ๐ŸŽป
๐Ÿ’ƒ &amp; **FastAPI** โš“๏ธ ๐Ÿ”› <a href="https://anyio.readthedocs.io/en/stable/" class="external-link" target="_blank">AnyIO</a>, โ” โš’ ๐Ÿ‘ซ ๐Ÿ”— โฎ๏ธ ๐Ÿ‘ฏโ€โ™‚๏ธ ๐Ÿ ๐Ÿฉ ๐Ÿ—ƒ <a href="https://docs.python.org/3/library/asyncio-task.html" class="external-link" target="_blank">โœณ</a> &amp; <a href="https://trio.readthedocs.io/en/stable/" class="external-link" target="_blank">๐ŸŽป</a>.
๐Ÿ‘, Uvicorn โณ ๐Ÿ•ด ๐Ÿ”— โฎ๏ธ โœณ, &amp; โšซ๏ธ ๐Ÿ›Ž โš™๏ธ <a href="https://github.com/MagicStack/uvloop" class="external-link" target="_blank">`uvloop`</a>, โ†•-๐ŸŽญ ๐Ÿ’ง-โ™ป `asyncio`.
โœ‹๏ธ ๐Ÿšฅ ๐Ÿ‘† ๐Ÿ’š ๐Ÿ”— โš™๏ธ **๐ŸŽป**, โคด๏ธ ๐Ÿ‘† ๐Ÿ’ช โš™๏ธ **Hypercorn** โšซ๏ธ ๐Ÿ•โ€๐Ÿฆบ โšซ๏ธ. ๐Ÿ‘ถ
### โŽ Hypercorn โฎ๏ธ ๐ŸŽป
๐Ÿฅ‡ ๐Ÿ‘† ๐Ÿ’ช โŽ Hypercorn โฎ๏ธ ๐ŸŽป ๐Ÿ•โ€๐Ÿฆบ:
<div class="termy">
```console
$ pip install "hypercorn[trio]"
---> 100%
```
</div>
### ๐Ÿƒ โฎ๏ธ ๐ŸŽป
โคด๏ธ ๐Ÿ‘† ๐Ÿ’ช ๐Ÿšถโ€โ™€๏ธ ๐Ÿ“‹ โธ ๐ŸŽ› `--worker-class` โฎ๏ธ ๐Ÿ’ฒ `trio`:
<div class="termy">
```console
$ hypercorn main:app --worker-class trio
```
</div>
&amp; ๐Ÿ‘ˆ ๐Ÿ”œ โ–ถ๏ธ Hypercorn โฎ๏ธ ๐Ÿ‘† ๐Ÿ“ฑ โš™๏ธ ๐ŸŽป ๐Ÿ‘ฉโ€๐Ÿ’ป.
๐Ÿ”œ ๐Ÿ‘† ๐Ÿ’ช โš™๏ธ ๐ŸŽป ๐Ÿ”˜ ๐Ÿ‘† ๐Ÿ“ฑ. โš–๏ธ ๐Ÿ‘, ๐Ÿ‘† ๐Ÿ’ช โš™๏ธ AnyIO, ๐Ÿšง ๐Ÿ‘† ๐Ÿ“Ÿ ๐Ÿ”— โฎ๏ธ ๐Ÿ‘ฏโ€โ™‚๏ธ ๐ŸŽป &amp; โœณ. ๐Ÿ‘ถ
## ๐Ÿ› ๏ธ ๐Ÿ”ง
๐Ÿ‘ซ ๐Ÿ–ผ ๐Ÿƒ ๐Ÿ’ฝ ๐Ÿ“‹ (๐Ÿ“ง.โ“‚ Uvicorn), โ–ถ๏ธ **๐Ÿ‘ ๐Ÿ› ๏ธ**, ๐Ÿ‘‚ ๐Ÿ”› ๐ŸŒ ๐Ÿ“ข (`0.0.0.0`) ๐Ÿ”› ๐Ÿ” โ›ด (โœ… `80`).
๐Ÿ‘‰ ๐Ÿ”ฐ ๐Ÿ’ญ. โœ‹๏ธ ๐Ÿ‘† ๐Ÿ”œ ๐ŸŽฒ ๐Ÿ’š โœŠ ๐Ÿ’… ๐ŸŒ– ๐Ÿ‘œ, ๐Ÿ’–:
* ๐Ÿ’‚โ€โ™‚ - ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ”
* ๐Ÿƒโ€โ™‚ ๐Ÿ”› ๐Ÿ•ด
* โ
* ๐Ÿงฌ (๐Ÿ”ข ๐Ÿ› ๏ธ ๐Ÿƒ)
* ๐Ÿ’พ
* โฎ๏ธ ๐Ÿ” โญ โ–ถ๏ธ
๐Ÿ‘ค ๐Ÿ”œ ๐Ÿ’ฌ ๐Ÿ‘† ๐ŸŒ… ๐Ÿ”ƒ ๐Ÿ”  ๐Ÿ‘ซ ๐Ÿ”ง, โ” ๐Ÿ’ญ ๐Ÿ”ƒ ๐Ÿ‘ซ, &amp; ๐Ÿงฑ ๐Ÿ–ผ โฎ๏ธ ๐ŸŽ› ๐Ÿต ๐Ÿ‘ซ โญ ๐Ÿ“ƒ. ๐Ÿ‘ถ

178
docs/em/docs/deployment/server-workers.md

@ -0,0 +1,178 @@
# ๐Ÿ’ฝ ๐Ÿ‘จโ€๐Ÿญ - ๐Ÿ โฎ๏ธ Uvicorn
โžก๏ธ โœ… ๐Ÿ”™ ๐Ÿ‘ˆ ๐Ÿ› ๏ธ ๐Ÿ”ง โšช๏ธโžก๏ธ โญ:
* ๐Ÿ’‚โ€โ™‚ - ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ”
* ๐Ÿƒโ€โ™‚ ๐Ÿ”› ๐Ÿ•ด
* โ
* **๐Ÿงฌ (๐Ÿ”ข ๐Ÿ› ๏ธ ๐Ÿƒ)**
* ๐Ÿ’พ
* โฎ๏ธ ๐Ÿ” โญ โ–ถ๏ธ
๐Ÿ†™ ๐Ÿ‘‰ โ˜, โฎ๏ธ ๐ŸŒ ๐Ÿ”ฐ ๐Ÿฉบ, ๐Ÿ‘† โœ”๏ธ ๐ŸŽฒ ๐Ÿƒโ€โ™‚ **๐Ÿ’ฝ ๐Ÿ“‹** ๐Ÿ’– Uvicorn, ๐Ÿƒโ€โ™‚ **๐Ÿ‘ ๐Ÿ› ๏ธ**.
๐Ÿ•โ” ๐Ÿ› ๏ธ ๐Ÿˆธ ๐Ÿ‘† ๐Ÿ”œ ๐ŸŽฒ ๐Ÿ’š โœ”๏ธ **๐Ÿงฌ ๐Ÿ› ๏ธ** โœŠ ๐Ÿ“ˆ **๐Ÿ’— ๐Ÿš** &amp; ๐Ÿ’ช ๐Ÿต ๐ŸŒ… ๐Ÿ“จ.
๐Ÿ‘† ๐Ÿ‘€ โฎ๏ธ ๐Ÿ“ƒ ๐Ÿ”ƒ [๐Ÿ› ๏ธ ๐Ÿ”ง](./concepts.md){.internal-link target=_blank}, ๐Ÿ“ค ๐Ÿ’— ๐ŸŽ› ๐Ÿ‘† ๐Ÿ’ช โš™๏ธ.
๐Ÿ“ฅ ๐Ÿ‘ค ๐Ÿ”œ ๐ŸŽฆ ๐Ÿ‘† โ” โš™๏ธ <a href="https://gunicorn.org/" class="external-link" target="_blank">**๐Ÿ**</a> โฎ๏ธ **Uvicorn ๐Ÿ‘จโ€๐Ÿญ ๐Ÿ› ๏ธ**.
!!! info
๐Ÿšฅ ๐Ÿ‘† โš™๏ธ ๐Ÿ“ฆ, ๐Ÿ–ผ โฎ๏ธ โ˜ โš–๏ธ Kubernete, ๐Ÿ‘ค ๐Ÿ”œ ๐Ÿ’ฌ ๐Ÿ‘† ๐ŸŒ… ๐Ÿ”ƒ ๐Ÿ‘ˆ โญ ๐Ÿ“ƒ: [FastAPI ๐Ÿ“ฆ - โ˜](./docker.md){.internal-link target=_blank}.
๐ŸŽฏ, ๐Ÿ•โ” ๐Ÿƒ ๐Ÿ”› **Kubernete** ๐Ÿ‘† ๐Ÿ”œ ๐ŸŽฒ **๐Ÿšซ** ๐Ÿ’š โš™๏ธ ๐Ÿ &amp; โ†ฉ๏ธ ๐Ÿƒ **๐Ÿ‘ Uvicorn ๐Ÿ› ๏ธ ๐Ÿ“ ๐Ÿ“ฆ**, โœ‹๏ธ ๐Ÿ‘ค ๐Ÿ”œ ๐Ÿ’ฌ ๐Ÿ‘† ๐Ÿ”ƒ โšซ๏ธ โช ๐Ÿ‘ˆ ๐Ÿ“ƒ.
## ๐Ÿ โฎ๏ธ Uvicorn ๐Ÿ‘จโ€๐Ÿญ
**๐Ÿ** โœด๏ธ ๐Ÿˆธ ๐Ÿ’ฝ โš™๏ธ **๐Ÿ‡จ๐Ÿ‡ป ๐Ÿฉ**. ๐Ÿ‘ˆ โ›“ ๐Ÿ‘ˆ ๐Ÿ ๐Ÿ’ช ๐Ÿฆ ๐Ÿˆธ ๐Ÿ’– ๐Ÿบ &amp; โœณ. ๐Ÿ โšซ๏ธ ๐Ÿšซ ๐Ÿ”— โฎ๏ธ **FastAPI**, FastAPI โš™๏ธ ๐Ÿ†• **<a href="https://asgi.readthedocs.io/en/latest/" class="external-link" target="_blank">๐Ÿ”ซ ๐Ÿฉ</a>**.
โœ‹๏ธ ๐Ÿ ๐Ÿ•โ€๐Ÿฆบ ๐Ÿ‘ท **๐Ÿ› ๏ธ ๐Ÿ‘จโ€๐Ÿ’ผ** &amp; ๐Ÿค ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ’ฌ โšซ๏ธ โ” ๐ŸŽฏ **๐Ÿ‘จโ€๐Ÿญ ๐Ÿ› ๏ธ ๐ŸŽ“** โš™๏ธ. โคด๏ธ ๐Ÿ ๐Ÿ”œ โ–ถ๏ธ 1๏ธโƒฃ โš–๏ธ ๐ŸŒ– **๐Ÿ‘จโ€๐Ÿญ ๐Ÿ› ๏ธ** โš™๏ธ ๐Ÿ‘ˆ ๐ŸŽ“.
&amp; **Uvicorn** โœ”๏ธ **๐Ÿ-๐Ÿ”— ๐Ÿ‘จโ€๐Ÿญ ๐ŸŽ“**.
โš™๏ธ ๐Ÿ‘ˆ ๐ŸŒ€, ๐Ÿ ๐Ÿ”œ ๐Ÿšซ **๐Ÿ› ๏ธ ๐Ÿ‘จโ€๐Ÿ’ผ**, ๐Ÿ‘‚ ๐Ÿ”› **โ›ด** &amp; **๐Ÿ“ข**. &amp; โšซ๏ธ ๐Ÿ”œ **๐Ÿ“ถ** ๐Ÿ“ป ๐Ÿ‘จโ€๐Ÿญ ๐Ÿ› ๏ธ ๐Ÿƒ **Uvicorn ๐ŸŽ“**.
&amp; โคด๏ธ ๐Ÿ-๐Ÿ”— **Uvicorn ๐Ÿ‘จโ€๐Ÿญ** ๐ŸŽ“ ๐Ÿ”œ ๐Ÿˆš ๐Ÿญ ๐Ÿ“Š ๐Ÿ“จ ๐Ÿ ๐Ÿ”ซ ๐Ÿฉ FastAPI โš™๏ธ โšซ๏ธ.
## โŽ ๐Ÿ &amp; Uvicorn
<div class="termy">
```console
$ pip install "uvicorn[standard]" gunicorn
---> 100%
```
</div>
๐Ÿ‘ˆ ๐Ÿ”œ โŽ ๐Ÿ‘ฏโ€โ™‚๏ธ Uvicorn โฎ๏ธ `standard` โž• ๐Ÿ“ฆ (๐Ÿคš โ†• ๐ŸŽญ) &amp; ๐Ÿ.
## ๐Ÿƒ ๐Ÿ โฎ๏ธ Uvicorn ๐Ÿ‘จโ€๐Ÿญ
โคด๏ธ ๐Ÿ‘† ๐Ÿ’ช ๐Ÿƒ ๐Ÿ โฎ๏ธ:
<div class="termy">
```console
$ gunicorn main:app --workers 4 --worker-class uvicorn.workers.UvicornWorker --bind 0.0.0.0:80
[19499] [INFO] Starting gunicorn 20.1.0
[19499] [INFO] Listening at: http://0.0.0.0:80 (19499)
[19499] [INFO] Using worker: uvicorn.workers.UvicornWorker
[19511] [INFO] Booting worker with pid: 19511
[19513] [INFO] Booting worker with pid: 19513
[19514] [INFO] Booting worker with pid: 19514
[19515] [INFO] Booting worker with pid: 19515
[19511] [INFO] Started server process [19511]
[19511] [INFO] Waiting for application startup.
[19511] [INFO] Application startup complete.
[19513] [INFO] Started server process [19513]
[19513] [INFO] Waiting for application startup.
[19513] [INFO] Application startup complete.
[19514] [INFO] Started server process [19514]
[19514] [INFO] Waiting for application startup.
[19514] [INFO] Application startup complete.
[19515] [INFO] Started server process [19515]
[19515] [INFO] Waiting for application startup.
[19515] [INFO] Application startup complete.
```
</div>
โžก๏ธ ๐Ÿ‘€ โšซ๏ธโ” ๐Ÿ”  ๐Ÿ‘ˆ ๐ŸŽ› โ›“:
* `main:app`: ๐Ÿ‘‰ ๐ŸŽ โ• โš™๏ธ Uvicorn, `main` โ›“ ๐Ÿ ๐Ÿ•น ๐Ÿ“› "`main`",, ๐Ÿ“ `main.py`. &amp; `app` ๐Ÿ“› ๐Ÿ”ข ๐Ÿ‘ˆ **FastAPI** ๐Ÿˆธ.
* ๐Ÿ‘† ๐Ÿ’ช ๐ŸŒˆ ๐Ÿ‘ˆ `main:app` ๐ŸŒ“ ๐Ÿ `import` ๐Ÿ“„ ๐Ÿ’–:
```Python
from main import app
```
* , โค `main:app` ๐Ÿ”œ ๐ŸŒ“ ๐Ÿ `import` ๐Ÿ• `from main import app`.
* `--workers`: ๐Ÿ”ข ๐Ÿ‘จโ€๐Ÿญ ๐Ÿ› ๏ธ โš™๏ธ, ๐Ÿ”  ๐Ÿ”œ ๐Ÿƒ Uvicorn ๐Ÿ‘จโ€๐Ÿญ, ๐Ÿ‘‰ ๐Ÿ’ผ, 4๏ธโƒฃ ๐Ÿ‘จโ€๐Ÿญ.
* `--worker-class`: ๐Ÿ-๐Ÿ”— ๐Ÿ‘จโ€๐Ÿญ ๐ŸŽ“ โš™๏ธ ๐Ÿ‘จโ€๐Ÿญ ๐Ÿ› ๏ธ.
* ๐Ÿ“ฅ ๐Ÿ‘ฅ ๐Ÿšถโ€โ™€๏ธ ๐ŸŽ“ ๐Ÿ‘ˆ ๐Ÿ ๐Ÿ’ช ๐Ÿ—„ &amp; โš™๏ธ โฎ๏ธ:
```Python
import uvicorn.workers.UvicornWorker
```
* `--bind`: ๐Ÿ‘‰ ๐Ÿ’ฌ ๐Ÿ ๐Ÿ“ข &amp; โ›ด ๐Ÿ‘‚, โš™๏ธ โค (`:`) ๐ŸŽ ๐Ÿ“ข &amp; โ›ด.
* ๐Ÿšฅ ๐Ÿ‘† ๐Ÿƒโ€โ™‚ Uvicorn ๐Ÿ”—, โ†ฉ๏ธ `--bind 0.0.0.0:80` (๐Ÿ ๐ŸŽ›) ๐Ÿ‘† ๐Ÿ”œ โš™๏ธ `--host 0.0.0.0` &amp; `--port 80`.
๐Ÿ”ข, ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ‘€ ๐Ÿ‘ˆ โšซ๏ธ ๐ŸŽฆ **๐Ÿ•น** (๐Ÿ› ๏ธ ๐Ÿ†”) ๐Ÿ”  ๐Ÿ› ๏ธ (โšซ๏ธ ๐Ÿ”ข).
๐Ÿ‘† ๐Ÿ’ช ๐Ÿ‘€ ๐Ÿ‘ˆ:
* ๐Ÿ **๐Ÿ› ๏ธ ๐Ÿ‘จโ€๐Ÿ’ผ** โ–ถ๏ธ โฎ๏ธ ๐Ÿ•น `19499` (๐Ÿ‘† ๐Ÿ’ผ โšซ๏ธ ๐Ÿ”œ ๐ŸŽ ๐Ÿ”ข).
* โคด๏ธ โšซ๏ธ โ–ถ๏ธ `Listening at: http://0.0.0.0:80`.
* โคด๏ธ โšซ๏ธ ๐Ÿ” ๐Ÿ‘ˆ โšซ๏ธ โœ”๏ธ โš™๏ธ ๐Ÿ‘จโ€๐Ÿญ ๐ŸŽ“ `uvicorn.workers.UvicornWorker`.
* &amp; โคด๏ธ โšซ๏ธ โ–ถ๏ธ **4๏ธโƒฃ ๐Ÿ‘จโ€๐Ÿญ**, ๐Ÿ”  โฎ๏ธ ๐Ÿšฎ ๐Ÿ‘ ๐Ÿ•น: `19511`, `19513`, `19514`, &amp; `19515`.
๐Ÿ ๐Ÿ”œ โœŠ ๐Ÿ’… ๐Ÿ› ๏ธ **โ˜ ๏ธ ๐Ÿ› ๏ธ** &amp; **๐Ÿ”** ๐Ÿ†• ๐Ÿ• ๐Ÿšฅ ๐Ÿ’š ๐Ÿšง ๐Ÿ”ข ๐Ÿ‘จโ€๐Ÿญ. ๐Ÿ‘ˆ โ„น ๐Ÿ• โฎ๏ธ **โ** ๐Ÿ”ง โšช๏ธโžก๏ธ ๐Ÿ“‡ ๐Ÿ”›.
๐Ÿ‘, ๐Ÿ‘† ๐Ÿ”œ ๐ŸŽฒ ๐Ÿ’š โœ”๏ธ ๐Ÿ•ณ ๐Ÿž โš’ ๐Ÿ’ญ **โ ๐Ÿ** ๐Ÿšฅ ๐Ÿ’ช, &amp; **๐Ÿƒ โšซ๏ธ ๐Ÿ”› ๐Ÿ•ด**, โ™’๏ธ.
## Uvicorn โฎ๏ธ ๐Ÿ‘จโ€๐Ÿญ
Uvicorn โœ”๏ธ ๐ŸŽ› โ–ถ๏ธ &amp; ๐Ÿƒ ๐Ÿ“š **๐Ÿ‘จโ€๐Ÿญ ๐Ÿ› ๏ธ**.
๐Ÿ‘, ๐Ÿ”œ, Uvicorn ๐Ÿ› ๏ธ ๐Ÿšš ๐Ÿ‘จโ€๐Ÿญ ๐Ÿ› ๏ธ ๐ŸŒ… ๐Ÿ“‰ ๐ŸŒ˜ ๐Ÿ. , ๐Ÿšฅ ๐Ÿ‘† ๐Ÿ’š โœ”๏ธ ๐Ÿ› ๏ธ ๐Ÿ‘จโ€๐Ÿ’ผ ๐Ÿ‘‰ ๐ŸŽš (๐Ÿ ๐ŸŽš), โคด๏ธ โšซ๏ธ ๐Ÿ’ช ๐Ÿ‘ ๐Ÿ”„ โฎ๏ธ ๐Ÿ ๐Ÿ› ๏ธ ๐Ÿ‘จโ€๐Ÿ’ผ.
๐Ÿ™† ๐Ÿ’ผ, ๐Ÿ‘† ๐Ÿ”œ ๐Ÿƒ โšซ๏ธ ๐Ÿ’– ๐Ÿ‘‰:
<div class="termy">
```console
$ uvicorn main:app --host 0.0.0.0 --port 8080 --workers 4
<font color="#A6E22E">INFO</font>: Uvicorn running on <b>http://0.0.0.0:8080</b> (Press CTRL+C to quit)
<font color="#A6E22E">INFO</font>: Started parent process [<font color="#A1EFE4"><b>27365</b></font>]
<font color="#A6E22E">INFO</font>: Started server process [<font color="#A1EFE4">27368</font>]
<font color="#A6E22E">INFO</font>: Waiting for application startup.
<font color="#A6E22E">INFO</font>: Application startup complete.
<font color="#A6E22E">INFO</font>: Started server process [<font color="#A1EFE4">27369</font>]
<font color="#A6E22E">INFO</font>: Waiting for application startup.
<font color="#A6E22E">INFO</font>: Application startup complete.
<font color="#A6E22E">INFO</font>: Started server process [<font color="#A1EFE4">27370</font>]
<font color="#A6E22E">INFO</font>: Waiting for application startup.
<font color="#A6E22E">INFO</font>: Application startup complete.
<font color="#A6E22E">INFO</font>: Started server process [<font color="#A1EFE4">27367</font>]
<font color="#A6E22E">INFO</font>: Waiting for application startup.
<font color="#A6E22E">INFO</font>: Application startup complete.
```
</div>
๐Ÿ•ด ๐Ÿ†• ๐ŸŽ› ๐Ÿ“ฅ `--workers` ๐Ÿ’ฌ Uvicorn โ–ถ๏ธ 4๏ธโƒฃ ๐Ÿ‘จโ€๐Ÿญ ๐Ÿ› ๏ธ.
๐Ÿ‘† ๐Ÿ’ช ๐Ÿ‘€ ๐Ÿ‘ˆ โšซ๏ธ ๐ŸŽฆ **๐Ÿ•น** ๐Ÿ”  ๐Ÿ› ๏ธ, `27365` ๐Ÿ‘ช ๐Ÿ› ๏ธ (๐Ÿ‘‰ **๐Ÿ› ๏ธ ๐Ÿ‘จโ€๐Ÿ’ผ**) &amp; 1๏ธโƒฃ ๐Ÿ”  ๐Ÿ‘จโ€๐Ÿญ ๐Ÿ› ๏ธ: `27368`, `27369`, `27370`, &amp; `27367`.
## ๐Ÿ› ๏ธ ๐Ÿ”ง
๐Ÿ“ฅ ๐Ÿ‘† ๐Ÿ‘€ โ” โš™๏ธ **๐Ÿ** (โš–๏ธ Uvicorn) ๐Ÿ› ๏ธ **Uvicorn ๐Ÿ‘จโ€๐Ÿญ ๐Ÿ› ๏ธ** **๐Ÿ”** ๐Ÿ› ๏ธ ๐Ÿˆธ, โœŠ ๐Ÿ“ˆ **๐Ÿ’— ๐Ÿš** ๐Ÿ’ฝ, &amp; ๐Ÿ’ช ๐Ÿฆ **๐ŸŒ… ๐Ÿ“จ**.
โšช๏ธโžก๏ธ ๐Ÿ“‡ ๐Ÿ› ๏ธ ๐Ÿ”ง โšช๏ธโžก๏ธ ๐Ÿ”›, โš™๏ธ ๐Ÿ‘จโ€๐Ÿญ ๐Ÿ”œ โœด๏ธ โ„น โฎ๏ธ **๐Ÿงฌ** ๐Ÿ•, &amp; ๐Ÿฅ ๐Ÿ– โฎ๏ธ **โ**, โœ‹๏ธ ๐Ÿ‘† ๐Ÿ’ช โœŠ ๐Ÿ’… ๐ŸŽ:
* **๐Ÿ’‚โ€โ™‚ - ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ”**
* **๐Ÿƒโ€โ™‚ ๐Ÿ”› ๐Ÿ•ด**
* ***โ***
* ๐Ÿงฌ (๐Ÿ”ข ๐Ÿ› ๏ธ ๐Ÿƒ)
* **๐Ÿ’พ**
* **โฎ๏ธ ๐Ÿ” โญ โ–ถ๏ธ**
## ๐Ÿ“ฆ &amp; โ˜
โญ ๐Ÿ“ƒ ๐Ÿ”ƒ [FastAPI ๐Ÿ“ฆ - โ˜](./docker.md){.internal-link target=_blank} ๐Ÿ‘ค ๐Ÿ”œ ๐Ÿ’ฌ ๐ŸŽ› ๐Ÿ‘† ๐Ÿ’ช โš™๏ธ ๐Ÿต ๐ŸŽ **๐Ÿ› ๏ธ ๐Ÿ”ง**.
๐Ÿ‘ค ๐Ÿ”œ ๐ŸŽฆ ๐Ÿ‘† **๐Ÿ›‚ โ˜ ๐Ÿ–ผ** ๐Ÿ‘ˆ ๐Ÿ”Œ **๐Ÿ โฎ๏ธ Uvicorn ๐Ÿ‘จโ€๐Ÿญ** &amp; ๐Ÿ”ข ๐Ÿ“ณ ๐Ÿ‘ˆ ๐Ÿ’ช โš  ๐Ÿ™… ๐Ÿ’ผ.
๐Ÿ“ค ๐Ÿ‘ค ๐Ÿ”œ ๐ŸŽฆ ๐Ÿ‘† โ” **๐Ÿ— ๐Ÿ‘† ๐Ÿ‘ ๐Ÿ–ผ โšช๏ธโžก๏ธ ๐Ÿ–Œ** ๐Ÿƒ ๐Ÿ‘ Uvicorn ๐Ÿ› ๏ธ (๐Ÿต ๐Ÿ). โšซ๏ธ ๐Ÿ™… ๐Ÿ› ๏ธ &amp; ๐ŸŽฒ โšซ๏ธโ” ๐Ÿ‘† ๐Ÿ”œ ๐Ÿ’š ๐Ÿ•โ” โš™๏ธ ๐Ÿ“Ž ๐Ÿ“ฆ ๐Ÿงพ โš™๏ธ ๐Ÿ’– **Kubernete**.
## ๐ŸŒƒ
๐Ÿ‘† ๐Ÿ’ช โš™๏ธ **๐Ÿ** (โš–๏ธ Uvicorn) ๐Ÿ› ๏ธ ๐Ÿ‘จโ€๐Ÿ’ผ โฎ๏ธ Uvicorn ๐Ÿ‘จโ€๐Ÿญ โœŠ ๐Ÿ“ˆ **๐Ÿ‘-๐Ÿš ๐Ÿ’ฝ**, ๐Ÿƒ **๐Ÿ’— ๐Ÿ› ๏ธ ๐Ÿ”—**.
๐Ÿ‘† ๐Ÿ’ช โš™๏ธ ๐Ÿ‘‰ ๐Ÿงฐ &amp; ๐Ÿ’ญ ๐Ÿšฅ ๐Ÿ‘† โš’ ๐Ÿ†™ **๐Ÿ‘† ๐Ÿ‘ ๐Ÿ› ๏ธ โš™๏ธ** โช โœŠ ๐Ÿ’… ๐ŸŽ ๐Ÿ› ๏ธ ๐Ÿ”ง ๐Ÿ‘†.
โœ… ๐Ÿ‘… โญ ๐Ÿ“ƒ ๐Ÿ’ก ๐Ÿ”ƒ **FastAPI** โฎ๏ธ ๐Ÿ“ฆ (โœ… โ˜ &amp; Kubernete). ๐Ÿ‘† ๐Ÿ”œ ๐Ÿ‘€ ๐Ÿ‘ˆ ๐Ÿ‘ˆ ๐Ÿงฐ โœ”๏ธ ๐Ÿ™… ๐ŸŒŒ โŽ ๐ŸŽ **๐Ÿ› ๏ธ ๐Ÿ”ง** ๐Ÿ‘. ๐Ÿ‘ถ

87
docs/em/docs/deployment/versions.md

@ -0,0 +1,87 @@
# ๐Ÿ”ƒ FastAPI โฌ
**FastAPI** โช โž– โš™๏ธ ๐Ÿญ ๐Ÿ“š ๐Ÿˆธ &amp; โš™๏ธ. &amp; ๐Ÿ’ฏ ๐Ÿ’ฐ ๐Ÿšง 1๏ธโƒฃ0๏ธโƒฃ0๏ธโƒฃ ๐Ÿ’ฏ. โœ‹๏ธ ๐Ÿšฎ ๐Ÿ› ๏ธ ๐Ÿšš ๐Ÿ”œ.
๐Ÿ†• โš’ ๐Ÿšฎ ๐Ÿ›Ž, ๐Ÿ› ๐Ÿ”ง ๐Ÿ›Ž, &amp; ๐Ÿ“Ÿ ๐Ÿ” ๐Ÿ“‰.
๐Ÿ‘ˆ โšซ๏ธโ” โฎ๏ธ โฌ `0.x.x`, ๐Ÿ‘‰ ๐ŸŽจ ๐Ÿ‘ˆ ๐Ÿ”  โฌ ๐Ÿ’ช โš  โœ”๏ธ ๐Ÿ’” ๐Ÿ”€. ๐Ÿ‘‰ โฉ <a href="https://semver.org/" class="external-link" target="_blank">โš› ๐Ÿ› ๏ธ</a> ๐Ÿ›.
๐Ÿ‘† ๐Ÿ’ช โœ ๐Ÿญ ๐Ÿˆธ โฎ๏ธ **FastAPI** โ–ถ๏ธ๏ธ ๐Ÿ”œ (&amp; ๐Ÿ‘† โœ”๏ธ ๐ŸŽฒ ๐Ÿ”จ โšซ๏ธ ๐Ÿ•ฐ), ๐Ÿ‘† โœ”๏ธ โš’ ๐Ÿ’ญ ๐Ÿ‘ˆ ๐Ÿ‘† โš™๏ธ โฌ ๐Ÿ‘ˆ ๐Ÿ‘ท โ˜‘ โฎ๏ธ ๐ŸŽ‚ ๐Ÿ‘† ๐Ÿ“Ÿ.
## ๐Ÿ“Œ ๐Ÿ‘† `fastapi` โฌ
๐Ÿฅ‡ ๐Ÿ‘œ ๐Ÿ‘† ๐Ÿ”œ "๐Ÿ“Œ" โฌ **FastAPI** ๐Ÿ‘† โš™๏ธ ๐ŸŽฏ ๐Ÿ“ฐ โฌ ๐Ÿ‘ˆ ๐Ÿ‘† ๐Ÿ’ญ ๐Ÿ‘ท โ˜‘ ๐Ÿ‘† ๐Ÿˆธ.
๐Ÿ–ผ, โžก๏ธ ๐Ÿ’ฌ ๐Ÿ‘† โš™๏ธ โฌ `0.45.0` ๐Ÿ‘† ๐Ÿ“ฑ.
๐Ÿšฅ ๐Ÿ‘† โš™๏ธ `requirements.txt` ๐Ÿ“ ๐Ÿ‘† ๐Ÿ’ช โœ” โฌ โฎ๏ธ:
```txt
fastapi==0.45.0
```
๐Ÿ‘ˆ ๐Ÿ”œ โ›“ ๐Ÿ‘ˆ ๐Ÿ‘† ๐Ÿ”œ โš™๏ธ โšซ๏ธโ” โฌ `0.45.0`.
โš–๏ธ ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ“Œ โšซ๏ธ โฎ๏ธ:
```txt
fastapi>=0.45.0,<0.46.0
```
๐Ÿ‘ˆ ๐Ÿ”œ โ›“ ๐Ÿ‘ˆ ๐Ÿ‘† ๐Ÿ”œ โš™๏ธ โฌ `0.45.0` โš–๏ธ ๐Ÿ”›, โœ‹๏ธ ๐ŸŒ˜ ๐ŸŒ˜ `0.46.0`, ๐Ÿ–ผ, โฌ `0.45.2` ๐Ÿ”œ ๐Ÿšซ.
๐Ÿšฅ ๐Ÿ‘† โš™๏ธ ๐Ÿ™† ๐ŸŽ ๐Ÿงฐ ๐Ÿ› ๏ธ ๐Ÿ‘† ๐Ÿ‘ทโ€โ™‚, ๐Ÿ’– ๐ŸŽถ, Pipenv, โš–๏ธ ๐ŸŽ, ๐Ÿ‘ซ ๐ŸŒ โœ”๏ธ ๐ŸŒŒ ๐Ÿ‘ˆ ๐Ÿ‘† ๐Ÿ’ช โš™๏ธ ๐Ÿ”ฌ ๐ŸŽฏ โฌ ๐Ÿ‘† ๐Ÿ“ฆ.
## ๐Ÿ’ช โฌ
๐Ÿ‘† ๐Ÿ’ช ๐Ÿ‘€ ๐Ÿ’ช โฌ (โœ… โœ… โšซ๏ธโ” โฎ๏ธ ๐Ÿ“ฐ) [๐Ÿš€ ๐Ÿ—’](../release-notes.md){.internal-link target=_blank}.
## ๐Ÿ”ƒ โฌ
๐Ÿ“„ โš› ๐Ÿ› ๏ธ ๐Ÿ›, ๐Ÿ™† โฌ ๐Ÿ”› `1.0.0` ๐Ÿ’ช โš  ๐Ÿšฎ ๐Ÿ’” ๐Ÿ”€.
FastAPI โฉ ๐Ÿ› ๐Ÿ‘ˆ ๐Ÿ™† "๐Ÿ›" โฌ ๐Ÿ”€ ๐Ÿ› ๐Ÿ”ง &amp; ๐Ÿšซ-๐Ÿ’” ๐Ÿ”€.
!!! tip
"๐Ÿ›" ๐Ÿ ๐Ÿ”ข, ๐Ÿ–ผ, `0.2.3`, ๐Ÿ› โฌ `3`.
, ๐Ÿ‘† ๐Ÿ”œ ๐Ÿ’ช ๐Ÿ“Œ โฌ ๐Ÿ’–:
```txt
fastapi>=0.45.0,<0.46.0
```
๐Ÿ’” ๐Ÿ”€ &amp; ๐Ÿ†• โš’ ๐Ÿšฎ "๐Ÿ‡บ๐Ÿ‡ฒ" โฌ.
!!! tip
"๐Ÿ‡บ๐Ÿ‡ฒ" ๐Ÿ”ข ๐Ÿ–•, ๐Ÿ–ผ, `0.2.3`, ๐Ÿ‡บ๐Ÿ‡ฒ โฌ `2`.
## โ™ป FastAPI โฌ
๐Ÿ‘† ๐Ÿ”œ ๐Ÿšฎ ๐Ÿ’ฏ ๐Ÿ‘† ๐Ÿ“ฑ.
โฎ๏ธ **FastAPI** โšซ๏ธ ๐Ÿ“ถ โฉ (๐Ÿ‘ ๐Ÿ’ƒ), โœ… ๐Ÿฉบ: [๐Ÿ”ฌ](../tutorial/testing.md){.internal-link target=_blank}
โฎ๏ธ ๐Ÿ‘† โœ”๏ธ ๐Ÿ’ฏ, โคด๏ธ ๐Ÿ‘† ๐Ÿ’ช โ™ป **FastAPI** โฌ ๐ŸŒ– โฎ๏ธ 1๏ธโƒฃ, &amp; โš’ ๐Ÿ’ญ ๐Ÿ‘ˆ ๐ŸŒ ๐Ÿ‘† ๐Ÿ“Ÿ ๐Ÿ‘ท โ˜‘ ๐Ÿƒ ๐Ÿ‘† ๐Ÿ’ฏ.
๐Ÿšฅ ๐ŸŒ ๐Ÿ‘ท, โš–๏ธ โฎ๏ธ ๐Ÿ‘† โš’ ๐Ÿ’ช ๐Ÿ”€, &amp; ๐ŸŒ ๐Ÿ‘† ๐Ÿ’ฏ ๐Ÿšถโ€โ™€๏ธ, โคด๏ธ ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ“Œ ๐Ÿ‘† `fastapi` ๐Ÿ‘ˆ ๐Ÿ†• โฎ๏ธ โฌ.
## ๐Ÿ”ƒ ๐Ÿ’ƒ
๐Ÿ‘† ๐Ÿšซ๐Ÿ”œ ๐Ÿšซ ๐Ÿ“Œ โฌ `starlette`.
๐ŸŽ โฌ **FastAPI** ๐Ÿ”œ โš™๏ธ ๐ŸŽฏ ๐Ÿ†• โฌ ๐Ÿ’ƒ.
, ๐Ÿ‘† ๐Ÿ’ช โžก๏ธ **FastAPI** โš™๏ธ โ˜‘ ๐Ÿ’ƒ โฌ.
## ๐Ÿ”ƒ Pydantic
Pydantic ๐Ÿ”Œ ๐Ÿ’ฏ **FastAPI** โฎ๏ธ ๐Ÿšฎ ๐Ÿ‘ ๐Ÿ’ฏ, ๐Ÿ†• โฌ Pydantic (๐Ÿ”› `1.0.0`) ๐Ÿ•ง ๐Ÿ”— โฎ๏ธ FastAPI.
๐Ÿ‘† ๐Ÿ’ช ๐Ÿ“Œ Pydantic ๐Ÿ™† โฌ ๐Ÿ”› `1.0.0` ๐Ÿ‘ˆ ๐Ÿ‘ท ๐Ÿ‘† &amp; ๐Ÿ”› `2.0.0`.
๐Ÿ–ผ:
```txt
pydantic>=1.2.0,<2.0.0
```

91
docs/em/docs/external-links.md

@ -0,0 +1,91 @@
# ๐Ÿ”ข ๐Ÿ”— &amp; ๐Ÿ“„
**FastAPI** โœ”๏ธ ๐Ÿ‘‘ ๐Ÿ‘ช ๐Ÿ•ง ๐Ÿ’—.
๐Ÿ“ค ๐Ÿ“š ๐Ÿค, ๐Ÿ“„, ๐Ÿงฐ, &amp; ๐Ÿ—, ๐Ÿ”— **FastAPI**.
๐Ÿ“ฅ โŒ ๐Ÿ“‡ ๐Ÿ‘ซ.
!!! tip
๐Ÿšฅ ๐Ÿ‘† โœ”๏ธ ๐Ÿ“„, ๐Ÿ—, ๐Ÿงฐ, โš–๏ธ ๐Ÿ•ณ ๐Ÿ”— **FastAPI** ๐Ÿ‘ˆ ๐Ÿšซ ๐Ÿ“‡ ๐Ÿ“ฅ, โœ <a href="https://github.com/tiangolo/fastapi/edit/master/docs/en/data/external_links.yml" class="external-link" target="_blank">๐Ÿšฒ ๐Ÿ“จ โŽ โšซ๏ธ</a>.
## ๐Ÿ“„
### ๐Ÿ‡ช๐Ÿ‡ธ
{% if external_links %}
{% for article in external_links.articles.english %}
* <a href="{{ article.link }}" class="external-link" target="_blank">{{ article.title }}</a> <a href="{{ article.author_link }}" class="external-link" target="_blank">{{ article.author }}</a>.
{% endfor %}
{% endif %}
### ๐Ÿ‡ฏ๐Ÿ‡ต
{% if external_links %}
{% for article in external_links.articles.japanese %}
* <a href="{{ article.link }}" class="external-link" target="_blank">{{ article.title }}</a> <a href="{{ article.author_link }}" class="external-link" target="_blank">{{ article.author }}</a>.
{% endfor %}
{% endif %}
### ๐Ÿ‡ป๐Ÿ‡ณ
{% if external_links %}
{% for article in external_links.articles.vietnamese %}
* <a href="{{ article.link }}" class="external-link" target="_blank">{{ article.title }}</a> <a href="{{ article.author_link }}" class="external-link" target="_blank">{{ article.author }}</a>.
{% endfor %}
{% endif %}
### ๐Ÿ‡ท๐Ÿ‡บ
{% if external_links %}
{% for article in external_links.articles.russian %}
* <a href="{{ article.link }}" class="external-link" target="_blank">{{ article.title }}</a> <a href="{{ article.author_link }}" class="external-link" target="_blank">{{ article.author }}</a>.
{% endfor %}
{% endif %}
### ๐Ÿ‡ฉ๐Ÿ‡ช
{% if external_links %}
{% for article in external_links.articles.german %}
* <a href="{{ article.link }}" class="external-link" target="_blank">{{ article.title }}</a> <a href="{{ article.author_link }}" class="external-link" target="_blank">{{ article.author }}</a>.
{% endfor %}
{% endif %}
### ๐Ÿ‡น๐Ÿ‡ผ
{% if external_links %}
{% for article in external_links.articles.taiwanese %}
* <a href="{{ article.link }}" class="external-link" target="_blank">{{ article.title }}</a> <a href="{{ article.author_link }}" class="external-link" target="_blank">{{ article.author }}</a>.
{% endfor %}
{% endif %}
## ๐Ÿ“ป
{% if external_links %}
{% for article in external_links.podcasts.english %}
* <a href="{{ article.link }}" class="external-link" target="_blank">{{ article.title }}</a> <a href="{{ article.author_link }}" class="external-link" target="_blank">{{ article.author }}</a>.
{% endfor %}
{% endif %}
## ๐Ÿ’ฌ
{% if external_links %}
{% for article in external_links.talks.english %}
* <a href="{{ article.link }}" class="external-link" target="_blank">{{ article.title }}</a> <a href="{{ article.author_link }}" class="external-link" target="_blank">{{ article.author }}</a>.
{% endfor %}
{% endif %}
## ๐Ÿ—
โช ๐Ÿ“‚ ๐Ÿ— โฎ๏ธ โ” `fastapi`:
<div class="github-topic-projects">
</div>

178
docs/em/docs/fastapi-people.md

@ -0,0 +1,178 @@
# FastAPI ๐Ÿ‘ซ๐Ÿ‘ซ
FastAPI โœ”๏ธ ๐ŸŽ† ๐Ÿ‘ช ๐Ÿ‘ˆ ๐Ÿ™‹ ๐Ÿ‘ซ๐Ÿ‘ซ โšช๏ธโžก๏ธ ๐ŸŒ ๐Ÿ–ฅ.
## ๐Ÿ‘ผ - ๐Ÿ›
๐Ÿ™‹ โ— ๐Ÿ‘ถ
๐Ÿ‘‰ ๐Ÿ‘ค:
{% if people %}
<div class="user-list user-list-center">
{% for user in people.maintainers %}
<div class="user"><a href="{{ user.url }}" target="_blank"><div class="avatar-wrapper"><img src="{{ user.avatarUrl }}"/></div><div class="title">@{{ user.login }}</div></a> <div class="count">โ”: {{ user.answers }}</div><div class="count">๐Ÿšฒ ๐Ÿ“จ: {{ user.prs }}</div></div>
{% endfor %}
</div>
{% endif %}
๐Ÿ‘ค ๐Ÿ‘ผ &amp; ๐Ÿ› **FastAPI**. ๐Ÿ‘† ๐Ÿ’ช โœ ๐ŸŒ… ๐Ÿ”ƒ ๐Ÿ‘ˆ [โ„น FastAPI - ๐Ÿคš โ„น - ๐Ÿ”— โฎ๏ธ ๐Ÿ“•](help-fastapi.md#connect-with-the-author){.internal-link target=_blank}.
...โœ‹๏ธ ๐Ÿ“ฅ ๐Ÿ‘ค ๐Ÿ’š ๐ŸŽฆ ๐Ÿ‘† ๐Ÿ‘ช.
---
**FastAPI** ๐Ÿ“จ ๐Ÿ“š ๐Ÿ•โ€๐Ÿฆบ โšช๏ธโžก๏ธ ๐Ÿ‘ช. &amp; ๐Ÿ‘ค ๐Ÿ’š ๐ŸŽฆ ๐Ÿ‘ซ ๐Ÿ’ฐ.
๐Ÿ‘ซ ๐Ÿ‘ซ๐Ÿ‘ซ ๐Ÿ‘ˆ:
* [โ„น ๐ŸŽ โฎ๏ธ โ” ๐Ÿ“‚](help-fastapi.md#help-others-with-questions-in-github){.internal-link target=_blank}.
* [โœ ๐Ÿšฒ ๐Ÿ“จ](help-fastapi.md#create-a-pull-request){.internal-link target=_blank}.
* ๐Ÿ“„ ๐Ÿšฒ ๐Ÿ“จ, [โœด๏ธ โš  โœ](contributing.md#translations){.internal-link target=_blank}.
๐Ÿ‘ ๐Ÿ‘ซ. ๐Ÿ‘ถ ๐Ÿ‘ถ
## ๐ŸŒ… ๐Ÿฆ ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ ๐Ÿ—“๏ธ
๐Ÿ‘ซ ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ‘ˆ โœ”๏ธ [๐Ÿค ๐ŸŽ ๐Ÿ† โฎ๏ธ โ” ๐Ÿ“‚](help-fastapi.md#help-others-with-questions-in-github){.internal-link target=_blank} โฎ๏ธ ๐Ÿ ๐Ÿ—“๏ธ. ๐Ÿ‘ถ
{% if people %}
<div class="user-list user-list-center">
{% for user in people.last_month_active %}
<div class="user"><a href="{{ user.url }}" target="_blank"><div class="avatar-wrapper"><img src="{{ user.avatarUrl }}"/></div><div class="title">@{{ user.login }}</div></a> <div class="count">โ” ๐Ÿ“จ: {{ user.count }}</div></div>
{% endfor %}
</div>
{% endif %}
## ๐Ÿ•ด
๐Ÿ“ฅ **FastAPI ๐Ÿ•ด**. ๐Ÿ‘ถ
๐Ÿ‘ซ ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ‘ˆ โœ”๏ธ [โ„น ๐ŸŽ ๐Ÿ† โฎ๏ธ โ” ๐Ÿ“‚](help-fastapi.md#help-others-with-questions-in-github){.internal-link target=_blank} ๐Ÿ”˜ *๐ŸŒ ๐Ÿ•ฐ*.
๐Ÿ‘ซ โœ”๏ธ ๐ŸŽฆ ๐Ÿ•ด ๐Ÿค ๐Ÿ“š ๐ŸŽ. ๐Ÿ‘ถ
{% if people %}
<div class="user-list user-list-center">
{% for user in people.experts %}
<div class="user"><a href="{{ user.url }}" target="_blank"><div class="avatar-wrapper"><img src="{{ user.avatarUrl }}"/></div><div class="title">@{{ user.login }}</div></a> <div class="count">โ” ๐Ÿ“จ: {{ user.count }}</div></div>
{% endfor %}
</div>
{% endif %}
## ๐Ÿ” ๐Ÿ‘จโ€๐Ÿ”ฌ
๐Ÿ“ฅ **๐Ÿ” ๐Ÿ‘จโ€๐Ÿ”ฌ**. ๐Ÿ‘ถ
๐Ÿ‘‰ ๐Ÿ‘ฉโ€๐Ÿ’ป โœ”๏ธ [โœ ๐Ÿ† ๐Ÿšฒ ๐Ÿ“จ](help-fastapi.md#create-a-pull-request){.internal-link target=_blank} ๐Ÿ‘ˆ โœ”๏ธ *๐Ÿ”—*.
๐Ÿ‘ซ โœ”๏ธ ๐Ÿ“‰ โ„น ๐Ÿ“Ÿ, ๐Ÿงพ, โœ, โ™’๏ธ. ๐Ÿ‘ถ
{% if people %}
<div class="user-list user-list-center">
{% for user in people.top_contributors %}
<div class="user"><a href="{{ user.url }}" target="_blank"><div class="avatar-wrapper"><img src="{{ user.avatarUrl }}"/></div><div class="title">@{{ user.login }}</div></a> <div class="count">๐Ÿšฒ ๐Ÿ“จ: {{ user.count }}</div></div>
{% endfor %}
</div>
{% endif %}
๐Ÿ“ค ๐Ÿ“š ๐ŸŽ ๐Ÿ‘จโ€๐Ÿ”ฌ (๐ŸŒ… ๐ŸŒ˜ ๐Ÿ’ฏ), ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ‘€ ๐Ÿ‘ซ ๐ŸŒ <a href="https://github.com/tiangolo/fastapi/graphs/contributors" class="external-link" target="_blank">FastAPI ๐Ÿ“‚ ๐Ÿ‘จโ€๐Ÿ”ฌ ๐Ÿ“ƒ</a>. ๐Ÿ‘ถ
## ๐Ÿ” ๐Ÿ‘จโ€๐Ÿ”ฌ
๐Ÿ‘ซ ๐Ÿ‘ฉโ€๐Ÿ’ป **๐Ÿ” ๐Ÿ‘จโ€๐Ÿ”ฌ**. ๐Ÿ‘ถ ๐Ÿ‘ถ
### ๐Ÿ“„ โœ
๐Ÿ‘ค ๐Ÿ•ด ๐Ÿ’ฌ ๐Ÿ‘ฉโ€โคโ€๐Ÿ‘จ ๐Ÿ‡ช๐Ÿ‡ธ (&amp; ๐Ÿšซ ๐Ÿ“ถ ๐Ÿ‘ ๐Ÿ‘ถ). , ๐Ÿ‘จโ€๐Ÿ”ฌ ๐Ÿ• ๐Ÿ‘ˆ โœ”๏ธ [**๐Ÿ‹๏ธ โœ” โœ**](contributing.md#translations){.internal-link target=_blank} ๐Ÿงพ. ๐Ÿต ๐Ÿ‘ซ, ๐Ÿ“ค ๐Ÿšซ๐Ÿ”œ ๐Ÿงพ ๐Ÿ“š ๐ŸŽ ๐Ÿ‡ช๐Ÿ‡ธ.
---
**๐Ÿ” ๐Ÿ‘จโ€๐Ÿ”ฌ** ๐Ÿ‘ถ ๐Ÿ‘ถ โœ”๏ธ ๐Ÿ“„ ๐Ÿ† ๐Ÿšฒ ๐Ÿ“จ โšช๏ธโžก๏ธ ๐ŸŽ, ๐Ÿšš ๐Ÿ”† ๐Ÿ“Ÿ, ๐Ÿงพ, &amp; โœด๏ธ, **โœ**.
{% if people %}
<div class="user-list user-list-center">
{% for user in people.top_reviewers %}
<div class="user"><a href="{{ user.url }}" target="_blank"><div class="avatar-wrapper"><img src="{{ user.avatarUrl }}"/></div><div class="title">@{{ user.login }}</div></a> <div class="count">๐Ÿ“„: {{ user.count }}</div></div>
{% endfor %}
</div>
{% endif %}
## ๐Ÿ’ฐ
๐Ÿ‘ซ **๐Ÿ’ฐ**. ๐Ÿ‘ถ
๐Ÿ‘ซ ๐Ÿ”— ๐Ÿ‘‡ ๐Ÿ‘ท โฎ๏ธ **FastAPI** (&amp; ๐ŸŽ), โœด๏ธ ๐Ÿ”˜ <a href="https://github.com/sponsors/tiangolo" class="external-link" target="_blank">๐Ÿ“‚ ๐Ÿ’ฐ</a>.
{% if sponsors %}
{% if sponsors.gold %}
### ๐ŸŒŸ ๐Ÿ’ฐ
{% for sponsor in sponsors.gold -%}
<a href="{{ sponsor.url }}" target="_blank" title="{{ sponsor.title }}"><img src="{{ sponsor.img }}" style="border-radius:15px"></a>
{% endfor %}
{% endif %}
{% if sponsors.silver %}
### ๐Ÿฅ‡1st ๐Ÿ’ฐ
{% for sponsor in sponsors.silver -%}
<a href="{{ sponsor.url }}" target="_blank" title="{{ sponsor.title }}"><img src="{{ sponsor.img }}" style="border-radius:15px"></a>
{% endfor %}
{% endif %}
{% if sponsors.bronze %}
### ๐Ÿฅˆ2nd ๐Ÿ’ฐ
{% for sponsor in sponsors.bronze -%}
<a href="{{ sponsor.url }}" target="_blank" title="{{ sponsor.title }}"><img src="{{ sponsor.img }}" style="border-radius:15px"></a>
{% endfor %}
{% endif %}
{% endif %}
### ๐ŸŽฏ ๐Ÿ’ฐ
{% if github_sponsors %}
{% for group in github_sponsors.sponsors %}
<div class="user-list user-list-center">
{% for user in group %}
{% if user.login not in sponsors_badge.logins %}
<div class="user"><a href="{{ user.url }}" target="_blank"><div class="avatar-wrapper"><img src="{{ user.avatarUrl }}"/></div><div class="title">@{{ user.login }}</div></a></div>
{% endif %}
{% endfor %}
</div>
{% endfor %}
{% endif %}
## ๐Ÿ”ƒ ๐Ÿ“Š - ๐Ÿ“ก โ„น
๐Ÿ‘‘ ๐ŸŽฏ ๐Ÿ‘‰ ๐Ÿ“ƒ ๐ŸŽฆ ๐ŸŽฏ ๐Ÿ‘ช โ„น ๐ŸŽ.
โœด๏ธ โœ… ๐ŸŽฏ ๐Ÿ‘ˆ ๐Ÿ›Ž ๐ŸŒ˜ โญ, &amp; ๐Ÿ“š ๐Ÿ’ผ ๐ŸŒ… ๐Ÿ˜ฉ, ๐Ÿ’– ๐Ÿค ๐ŸŽ โฎ๏ธ โ” &amp; โš– ๐Ÿšฒ ๐Ÿ“จ โฎ๏ธ โœ.
๐Ÿ’ฝ โš– ๐Ÿ”  ๐Ÿ—“๏ธ, ๐Ÿ‘† ๐Ÿ’ช โœ <a href="https://github.com/tiangolo/fastapi/blob/master/.github/actions/people/app/main.py" class="external-link" target="_blank">โ„น ๐Ÿ“Ÿ ๐Ÿ“ฅ</a>.
๐Ÿ“ฅ ๐Ÿ‘ค ๐ŸŽฆ ๐Ÿ’ฐ โšช๏ธโžก๏ธ ๐Ÿ’ฐ.
๐Ÿ‘ค ๐Ÿฆ โ–ถ๏ธ๏ธ โ„น ๐Ÿ“Š, ๐Ÿ“„, โšก, โ™’๏ธ (๐Ÿ’ผ ๐Ÿคท).

200
docs/em/docs/features.md

@ -0,0 +1,200 @@
# โš’
## FastAPI โš’
**FastAPI** ๐Ÿค ๐Ÿ‘† ๐Ÿ“„:
### โš“๏ธ ๐Ÿ”› ๐Ÿ“‚ ๐Ÿฉ
* <a href="https://github.com/OAI/OpenAPI-Specification" class="external-link" target="_blank"><strong>๐Ÿ—„</strong></a> ๐Ÿ› ๏ธ ๐Ÿ—, โœ… ๐Ÿ“„ <abbr title="also known as: endpoints, routes">โžก</abbr> <abbr title="also known as HTTP methods, as POST, GET, PUT, DELETE">๐Ÿ› ๏ธ</abbr>, ๐Ÿ”ข, ๐Ÿ’ช ๐Ÿ“จ, ๐Ÿ’‚โ€โ™‚, โ™’๏ธ.
* ๐Ÿง ๐Ÿ“Š ๐Ÿท ๐Ÿงพ โฎ๏ธ <a href="https://json-schema.org/" class="external-link" target="_blank"><strong>๐ŸŽป ๐Ÿ”—</strong></a> (๐Ÿ—„ โšซ๏ธ ๐Ÿงข ๐Ÿ”› ๐ŸŽป ๐Ÿ”—).
* ๐Ÿ”ง ๐Ÿคญ ๐Ÿ‘ซ ๐Ÿฉ, โฎ๏ธ ๐Ÿ˜” ๐Ÿ”ฌ. โ†ฉ๏ธ ๐Ÿ‘Ž ๐Ÿงฝ ๐Ÿ”› ๐Ÿ”.
* ๐Ÿ‘‰ โœ” โš™๏ธ ๐Ÿง **๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ“Ÿ โšก** ๐Ÿ“š ๐Ÿ‡ช๐Ÿ‡ธ.
### ๐Ÿง ๐Ÿฉบ
๐ŸŽ“ ๐Ÿ› ๏ธ ๐Ÿงพ &amp; ๐Ÿ”ฌ ๐Ÿ•ธ ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ”ข. ๐Ÿ› ๏ธ โš“๏ธ ๐Ÿ”› ๐Ÿ—„, ๐Ÿ“ค ๐Ÿ’— ๐ŸŽ›, 2๏ธโƒฃ ๐Ÿ”Œ ๐Ÿ”ข.
* <a href="https://github.com/swagger-api/swagger-ui" class="external-link" target="_blank"><strong>๐Ÿฆ ๐ŸŽš</strong></a>, โฎ๏ธ ๐ŸŽ“ ๐Ÿ”ฌ, ๐Ÿค™ &amp; ๐Ÿ’ฏ ๐Ÿ‘† ๐Ÿ› ๏ธ ๐Ÿ”— โšช๏ธโžก๏ธ ๐Ÿ–ฅ.
![Swagger UI interaction](https://fastapi.tiangolo.com/img/index/index-03-swagger-02.png)
* ๐ŸŽ› ๐Ÿ› ๏ธ ๐Ÿงพ โฎ๏ธ <a href="https://github.com/Rebilly/ReDoc" class="external-link" target="_blank"><strong>๐Ÿ“„</strong></a>.
![ReDoc](https://fastapi.tiangolo.com/img/index/index-06-redoc-02.png)
### ๐Ÿ› ๐Ÿ
โšซ๏ธ ๐ŸŒ โš“๏ธ ๐Ÿ”› ๐Ÿฉ **๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ ๐Ÿ†Ž** ๐Ÿ“„ (๐Ÿ‘ Pydantic). ๐Ÿ™…โ€โ™‚ ๐Ÿ†• โ• ๐Ÿ’ก. ๐Ÿฉ ๐Ÿ› ๐Ÿ.
๐Ÿšฅ ๐Ÿ‘† ๐Ÿ’ช 2๏ธโƒฃ โฒ โ†—๏ธ โ” โš™๏ธ ๐Ÿ ๐Ÿ†Ž (๐Ÿšฅ ๐Ÿ‘† ๐Ÿšซ โš™๏ธ FastAPI), โœ… ๐Ÿ“ ๐Ÿ”ฐ: [๐Ÿ ๐Ÿ†Ž](python-types.md){.internal-link target=_blank}.
๐Ÿ‘† โœ ๐Ÿฉ ๐Ÿ โฎ๏ธ ๐Ÿ†Ž:
```Python
from datetime import date
from pydantic import BaseModel
# Declare a variable as a str
# and get editor support inside the function
def main(user_id: str):
return user_id
# A Pydantic model
class User(BaseModel):
id: int
name: str
joined: date
```
๐Ÿ‘ˆ ๐Ÿ’ช โคด๏ธ โš™๏ธ ๐Ÿ’–:
```Python
my_user: User = User(id=3, name="John Doe", joined="2018-07-19")
second_user_data = {
"id": 4,
"name": "Mary",
"joined": "2018-11-30",
}
my_second_user: User = User(**second_user_data)
```
!!! info
`**second_user_data` โ›“:
๐Ÿšถโ€โ™€๏ธ ๐Ÿ”‘ &amp; ๐Ÿ’ฒ `second_user_data` #๏ธโƒฃ ๐Ÿ”— ๐Ÿ”‘-๐Ÿ’ฒ โŒ, ๐ŸŒ“: `User(id=4, name="Mary", joined="2018-11-30")`
### ๐Ÿ‘จโ€๐ŸŽจ ๐Ÿ•โ€๐Ÿฆบ
๐ŸŒ ๐Ÿ› ๏ธ ๐Ÿ— โฉ &amp; ๐Ÿ‹๏ธ โš™๏ธ, ๐ŸŒ ๐Ÿšซ ๐Ÿ’ฏ ๐Ÿ”› ๐Ÿ’— ๐Ÿ‘จโ€๐ŸŽจ โญ โ–ถ๏ธ ๐Ÿ› ๏ธ, ๐Ÿšš ๐Ÿ† ๐Ÿ› ๏ธ ๐Ÿ’ก.
๐Ÿ ๐Ÿ ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ”ฌ โšซ๏ธ ๐Ÿ†‘ <a href="https://www.jetbrains.com/research/python-developers-survey-2017/#tools-and-features" class="external-link" target="_blank">๐Ÿ‘ˆ ๐ŸŒ… โš™๏ธ โš’ "โœ"</a>.
๐ŸŽ‚ **FastAPI** ๐Ÿ› ๏ธ โš“๏ธ ๐Ÿ˜Œ ๐Ÿ‘ˆ. โœ ๐Ÿ‘ท ๐ŸŒ.
๐Ÿ‘† ๐Ÿ”œ ๐Ÿ›Ž ๐Ÿ’ช ๐Ÿ‘Ÿ ๐Ÿ”™ ๐Ÿฉบ.
๐Ÿ“ฅ โ” ๐Ÿ‘† ๐Ÿ‘จโ€๐ŸŽจ ๐Ÿ’ช โ„น ๐Ÿ‘†:
* <a href="https://code.visualstudio.com/" class="external-link" target="_blank">๐ŸŽ™ ๐ŸŽ™ ๐Ÿ“Ÿ</a>:
![editor support](https://fastapi.tiangolo.com/img/vscode-completion.png)
* <a href="https://www.jetbrains.com/pycharm/" class="external-link" target="_blank">๐Ÿ—’</a>:
![editor support](https://fastapi.tiangolo.com/img/pycharm-completion.png)
๐Ÿ‘† ๐Ÿ”œ ๐Ÿคš ๐Ÿ› ๏ธ ๐Ÿ“Ÿ ๐Ÿ‘† 5๏ธโƒฃ๐Ÿ“† ๐Ÿค” ๐Ÿ’ช โญ. ๐Ÿ–ผ, `price` ๐Ÿ”‘ ๐Ÿ”˜ ๐ŸŽป ๐Ÿ’ช (๐Ÿ‘ˆ ๐Ÿ’ช โœ”๏ธ ๐Ÿฆ) ๐Ÿ‘ˆ ๐Ÿ‘Ÿ โšช๏ธโžก๏ธ ๐Ÿ“จ.
๐Ÿ™…โ€โ™‚ ๐ŸŒ– โŒจ โŒ ๐Ÿ”‘ ๐Ÿ“›, ๐Ÿ‘Ÿ ๐Ÿ”™ &amp; โžก ๐Ÿ–– ๐Ÿฉบ, โš–๏ธ ๐Ÿ“œ ๐Ÿ†™ &amp; ๐Ÿ”ฝ ๐Ÿ”Ž ๐Ÿšฅ ๐Ÿ‘† ๐Ÿ˜’ โš™๏ธ `username` โš–๏ธ `user_name`.
### ๐Ÿ“
โšซ๏ธ โœ”๏ธ ๐Ÿค” **๐Ÿ”ข** ๐ŸŒ, โฎ๏ธ ๐Ÿ“ฆ ๐Ÿ“ณ ๐ŸŒ. ๐ŸŒ ๐Ÿ”ข ๐Ÿ’ช ๐Ÿ‘Œ-๐ŸŽง โšซ๏ธโ” ๐Ÿ‘† ๐Ÿ’ช &amp; ๐Ÿ”ฌ ๐Ÿ› ๏ธ ๐Ÿ‘† ๐Ÿ’ช.
โœ‹๏ธ ๐Ÿ”ข, โšซ๏ธ ๐ŸŒ **"๐Ÿ‘ท"**.
### ๐Ÿ”ฌ
* ๐Ÿ”ฌ ๐ŸŒ… (โš–๏ธ ๐ŸŒ โ“) ๐Ÿ **๐Ÿ’ฝ ๐Ÿ†Ž**, ๐Ÿ”Œ:
* ๐ŸŽป ๐ŸŽš (`dict`).
* ๐ŸŽป ๐ŸŽป (`list`) โš– ๐Ÿฌ ๐Ÿ†Ž.
* ๐ŸŽป (`str`) ๐Ÿ‘, ๐Ÿ”ฌ ๐Ÿ•™ &amp; ๐Ÿ‘Ÿ ๐Ÿ“.
* ๐Ÿ”ข (`int`, `float`) โฎ๏ธ ๐Ÿ•™ &amp; ๐Ÿ‘Ÿ ๐Ÿ’ฒ, โ™’๏ธ.
* ๐Ÿ”ฌ ๐ŸŒ… ๐Ÿ˜ ๐Ÿ†Ž, ๐Ÿ’–:
* ๐Ÿ“›.
* ๐Ÿ“ง.
* ๐Ÿ†”.
* ...&amp; ๐ŸŽ.
๐ŸŒ ๐Ÿ”ฌ ๐Ÿต ๐Ÿ‘-๐Ÿ› &amp; ๐Ÿ‹๏ธ **Pydantic**.
### ๐Ÿ’‚โ€โ™‚ &amp; ๐Ÿค
๐Ÿ’‚โ€โ™‚ &amp; ๐Ÿค ๐Ÿ› ๏ธ. ๐Ÿต ๐Ÿ™† โš  โฎ๏ธ ๐Ÿ’ฝ โš–๏ธ ๐Ÿ“Š ๐Ÿท.
๐ŸŒ ๐Ÿ’‚โ€โ™‚ โš– ๐Ÿ”ฌ ๐Ÿ—„, ๐Ÿ”Œ:
* ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ” ๐Ÿ”ฐ.
* **Oauth2๏ธโƒฃ** (โฎ๏ธ **๐Ÿฅ™ ๐Ÿค**). โœ… ๐Ÿ”ฐ ๐Ÿ”› [Oauth2๏ธโƒฃ โฎ๏ธ ๐Ÿฅ™](tutorial/security/oauth2-jwt.md){.internal-link target=_blank}.
* ๐Ÿ› ๏ธ ๐Ÿ”‘:
* ๐ŸŽš.
* ๐Ÿ”ข ๐Ÿ”ข.
* ๐Ÿช, โ™’๏ธ.
โž• ๐ŸŒ ๐Ÿ’‚โ€โ™‚ โš’ โšช๏ธโžก๏ธ ๐Ÿ’ƒ (๐Ÿ”Œ **๐ŸŽ‰ ๐Ÿช**).
๐ŸŒ ๐Ÿ— โ™ป ๐Ÿงฐ &amp; ๐Ÿฆฒ ๐Ÿ‘ˆ โฉ ๐Ÿ› ๏ธ โฎ๏ธ ๐Ÿ‘† โš™๏ธ, ๐Ÿ“Š ๐Ÿช, ๐Ÿ”— &amp; โ˜ ๐Ÿ’ฝ, โ™’๏ธ.
### ๐Ÿ”— ๐Ÿ’‰
FastAPI ๐Ÿ”Œ ๐Ÿ“ถ โฉ โš™๏ธ, โœ‹๏ธ ๐Ÿ“ถ ๐Ÿ‹๏ธ <abbr title='also known as "components", "resources", "services", "providers"'><strong>๐Ÿ”— ๐Ÿ’‰</strong></abbr> โš™๏ธ.
* ๐Ÿ”— ๐Ÿ’ช โœ”๏ธ ๐Ÿ”—, ๐Ÿ— ๐Ÿ”— โš–๏ธ **"๐Ÿ“Š" ๐Ÿ”—**.
* ๐ŸŒ **๐Ÿ” ๐Ÿต** ๐Ÿ› ๏ธ.
* ๐ŸŒ ๐Ÿ”— ๐Ÿ’ช ๐Ÿšš ๐Ÿ’ฝ โšช๏ธโžก๏ธ ๐Ÿ“จ &amp; **โ†” โžก ๐Ÿ› ๏ธ** โš› &amp; ๐Ÿง ๐Ÿงพ.
* **๐Ÿง ๐Ÿ”ฌ** *โžก ๐Ÿ› ๏ธ* ๐Ÿ”ข ๐Ÿ”ฌ ๐Ÿ”—.
* ๐Ÿ•โ€๐Ÿฆบ ๐Ÿ— ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿค โš™๏ธ, **๐Ÿ’ฝ ๐Ÿ”—**, โ™’๏ธ.
* **๐Ÿ™…โ€โ™‚ โš ** โฎ๏ธ ๐Ÿ’ฝ, ๐Ÿ•ธ, โ™’๏ธ. โœ‹๏ธ โฉ ๐Ÿ› ๏ธ โฎ๏ธ ๐ŸŒ ๐Ÿ‘ซ.
### โ™พ "๐Ÿ”Œ-๐Ÿ”Œ"
โš–๏ธ ๐ŸŽ ๐ŸŒŒ, ๐Ÿ™…โ€โ™‚ ๐Ÿ’ช ๐Ÿ‘ซ, ๐Ÿ—„ &amp; โš™๏ธ ๐Ÿ“Ÿ ๐Ÿ‘† ๐Ÿ’ช.
๐Ÿ™† ๐Ÿ› ๏ธ ๐Ÿ— ๐Ÿ™… โš™๏ธ (โฎ๏ธ ๐Ÿ”—) ๐Ÿ‘ˆ ๐Ÿ‘† ๐Ÿ’ช โœ "๐Ÿ”Œ-" ๐Ÿ‘† ๐Ÿˆธ 2๏ธโƒฃ โธ ๐Ÿ“Ÿ โš™๏ธ ๐ŸŽ ๐Ÿ“Š &amp; โ• โš™๏ธ ๐Ÿ‘† *โžก ๐Ÿ› ๏ธ*.
### ๐Ÿ’ฏ
* 1๏ธโƒฃ0๏ธโƒฃ0๏ธโƒฃ ๐Ÿ’ฏ <abbr title="The amount of code that is automatically tested">๐Ÿ’ฏ ๐Ÿ’ฐ</abbr>.
* 1๏ธโƒฃ0๏ธโƒฃ0๏ธโƒฃ ๐Ÿ’ฏ <abbr title="Python type annotations, with this your editor and external tools can give you better support">๐Ÿ†Ž โœ</abbr> ๐Ÿ“Ÿ ๐Ÿงข.
* โš™๏ธ ๐Ÿญ ๐Ÿˆธ.
## ๐Ÿ’ƒ โš’
**FastAPI** ๐Ÿ• ๐Ÿ”— โฎ๏ธ (&amp; โš“๏ธ ๐Ÿ”›) <a href="https://www.starlette.io/" class="external-link" target="_blank"><strong>๐Ÿ’ƒ</strong></a>. , ๐Ÿ™† ๐ŸŒ– ๐Ÿ’ƒ ๐Ÿ“Ÿ ๐Ÿ‘† โœ”๏ธ, ๐Ÿ”œ ๐Ÿ‘ท.
`FastAPI` ๐Ÿค™ ๐ŸŽง-๐ŸŽ“ `Starlette`. , ๐Ÿšฅ ๐Ÿ‘† โช ๐Ÿ’ญ โš–๏ธ โš™๏ธ ๐Ÿ’ƒ, ๐ŸŒ… ๐Ÿ› ๏ธ ๐Ÿ”œ ๐Ÿ‘ท ๐ŸŽ ๐ŸŒŒ.
โฎ๏ธ **FastAPI** ๐Ÿ‘† ๐Ÿคš ๐ŸŒ **๐Ÿ’ƒ**'โ“‚ โš’ (FastAPI ๐Ÿ’ƒ ๐Ÿ”› ๐Ÿ’Š):
* ๐Ÿค™ ๐ŸŽ† ๐ŸŽญ. โšซ๏ธ <a href="https://github.com/encode/starlette#performance" class="external-link" target="_blank">1๏ธโƒฃ โฉ ๐Ÿ ๐Ÿ› ๏ธ ๐Ÿ’ช, ๐Ÿ”› ๐Ÿ‡ท๐Ÿ‡ช โฎ๏ธ **โœณ** &amp; **๐Ÿšถ**</a>.
* ** *๏ธโƒฃ ** ๐Ÿ•โ€๐Ÿฆบ.
* -๐Ÿ› ๏ธ ๐Ÿ–ฅ ๐Ÿ“‹.
* ๐Ÿ•ด &amp; ๐Ÿคซ ๐ŸŽ‰.
* ๐Ÿ’ฏ ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ— ๐Ÿ”› ๐Ÿ‡ธ๐Ÿ‡ฒ.
* **โšœ**, ๐Ÿ—œ, ๐ŸŽป ๐Ÿ“, ๐ŸŽ ๐Ÿ“จ.
* **๐ŸŽ‰ &amp; ๐Ÿช** ๐Ÿ•โ€๐Ÿฆบ.
* 1๏ธโƒฃ0๏ธโƒฃ0๏ธโƒฃ ๐Ÿ’ฏ ๐Ÿ’ฏ ๐Ÿ’ฐ.
* 1๏ธโƒฃ0๏ธโƒฃ0๏ธโƒฃ ๐Ÿ’ฏ ๐Ÿ†Ž โœ โœ.
## Pydantic โš’
**FastAPI** ๐Ÿ• ๐Ÿ”— โฎ๏ธ (&amp; โš“๏ธ ๐Ÿ”›) <a href="https://pydantic-docs.helpmanual.io" class="external-link" target="_blank"><strong>Pydantic</strong></a>. , ๐Ÿ™† ๐ŸŒ– Pydantic ๐Ÿ“Ÿ ๐Ÿ‘† โœ”๏ธ, ๐Ÿ”œ ๐Ÿ‘ท.
โœ… ๐Ÿ”ข ๐Ÿ—ƒ โš“๏ธ ๐Ÿ”› Pydantic, <abbr title="Object-Relational Mapper">๐Ÿœ</abbr>โ“‚, <abbr title="Object-Document Mapper">๐Ÿญ</abbr>โ“‚ ๐Ÿ’ฝ.
๐Ÿ‘‰ โ›“ ๐Ÿ‘ˆ ๐Ÿ“š ๐Ÿ’ผ ๐Ÿ‘† ๐Ÿ’ช ๐Ÿšถโ€โ™€๏ธ ๐ŸŽ ๐ŸŽš ๐Ÿ‘† ๐Ÿคš โšช๏ธโžก๏ธ ๐Ÿ“จ **๐Ÿ”— ๐Ÿ’ฝ**, ๐ŸŒ โœ” ๐Ÿ”.
๐ŸŽ โœ” ๐ŸŽ ๐ŸŒŒ ๐Ÿคญ, ๐Ÿ“š ๐Ÿ’ผ ๐Ÿ‘† ๐Ÿ’ช ๐Ÿšถโ€โ™€๏ธ ๐ŸŽš ๐Ÿ‘† ๐Ÿคš โšช๏ธโžก๏ธ ๐Ÿ’ฝ **๐Ÿ”— ๐Ÿ‘ฉโ€๐Ÿ’ป**.
โฎ๏ธ **FastAPI** ๐Ÿ‘† ๐Ÿคš ๐ŸŒ **Pydantic**'โ“‚ โš’ (FastAPI โš“๏ธ ๐Ÿ”› Pydantic ๐ŸŒ ๐Ÿ’ฝ ๐Ÿšš):
* **๐Ÿ™…โ€โ™‚ ๐Ÿ” **:
* ๐Ÿ™…โ€โ™‚ ๐Ÿ†• ๐Ÿ”— ๐Ÿ”‘ โ—พ-๐Ÿ‡ช๐Ÿ‡ธ ๐Ÿ’ก.
* ๐Ÿšฅ ๐Ÿ‘† ๐Ÿ’ญ ๐Ÿ ๐Ÿ†Ž ๐Ÿ‘† ๐Ÿ’ญ โ” โš™๏ธ Pydantic.
* ๐Ÿคพ ๐ŸŽ† โฎ๏ธ ๐Ÿ‘† **<abbr title="Integrated Development Environment, similar to a code editor">๐Ÿ’พ</abbr>/<abbr title="A program that checks for code errors">๐Ÿงถ</abbr>/๐Ÿง **:
* โ†ฉ๏ธ Pydantic ๐Ÿ“Š ๐Ÿ“Š ๐Ÿ‘ ๐ŸŽ“ ๐Ÿ‘† ๐Ÿ”ฌ; ๐Ÿš˜-๐Ÿ› ๏ธ, ๐Ÿงฝ, โœ &amp; ๐Ÿ‘† ๐Ÿค” ๐Ÿ”œ ๐ŸŒ ๐Ÿ‘ท โ˜‘ โฎ๏ธ ๐Ÿ‘† โœ” ๐Ÿ’ฝ.
* **โฉ**:
* <a href="https://pydantic-docs.helpmanual.io/benchmarks/" class="external-link" target="_blank">๐Ÿ“‡</a> Pydantic โฉ ๐ŸŒ˜ ๐ŸŒ ๐ŸŽ ๐Ÿ’ฏ ๐Ÿ—ƒ.
* โœ” **๐Ÿ— ๐Ÿ“Š**:
* โš™๏ธ ๐Ÿ”— Pydantic ๐Ÿท, ๐Ÿ `typing`'โ“‚ `List` &amp; `Dict`, โ™’๏ธ.
* &amp; ๐Ÿ’ณ โœ” ๐Ÿ— ๐Ÿ’ฝ ๐Ÿ”— ๐ŸŽฏ &amp; ๐Ÿ’ช ๐Ÿ”ฌ, โœ… &amp; ๐Ÿ“„ ๐ŸŽป ๐Ÿ”—.
* ๐Ÿ‘† ๐Ÿ’ช โœ”๏ธ ๐Ÿ™‡ **๐Ÿฆ ๐ŸŽป** ๐ŸŽš &amp; โœ”๏ธ ๐Ÿ‘ซ ๐ŸŒ โœ” &amp; โœ.
* **๐Ÿง**:
* Pydantic โœ” ๐Ÿ›ƒ ๐Ÿ“Š ๐Ÿ†Ž ๐Ÿ”ฌ โš–๏ธ ๐Ÿ‘† ๐Ÿ’ช โ†” ๐Ÿ”ฌ โฎ๏ธ ๐Ÿ‘ฉโ€๐Ÿ”ฌ ๐Ÿ”› ๐Ÿท ๐ŸŽ€ โฎ๏ธ ๐Ÿ’ณ ๐Ÿ‘จโ€๐ŸŽจ.
* 1๏ธโƒฃ0๏ธโƒฃ0๏ธโƒฃ ๐Ÿ’ฏ ๐Ÿ’ฏ ๐Ÿ’ฐ.

265
docs/em/docs/help-fastapi.md

@ -0,0 +1,265 @@
# โ„น FastAPI - ๐Ÿคš โ„น
๐Ÿ‘† ๐Ÿ’– **FastAPI**โ“
๐Ÿ”œ ๐Ÿ‘† ๐Ÿ’– โ„น FastAPI, ๐ŸŽ ๐Ÿ‘ฉโ€๐Ÿ’ป, &amp; ๐Ÿ“• โ“
โš–๏ธ ๐Ÿ”œ ๐Ÿ‘† ๐Ÿ’– ๐Ÿคš โ„น โฎ๏ธ **FastAPI**โ“
๐Ÿ“ค ๐Ÿ“ถ ๐Ÿ™… ๐ŸŒŒ โ„น (๐Ÿ“š ๐Ÿ”Œ 1๏ธโƒฃ โš–๏ธ 2๏ธโƒฃ ๐Ÿ–Š).
&amp; ๐Ÿ“ค ๐Ÿ“š ๐ŸŒŒ ๐Ÿคš โ„น ๐Ÿ’โ€โ™‚๏ธ.
## ๐Ÿ‘ฑ๐Ÿ“” ๐Ÿ“ฐ
๐Ÿ‘† ๐Ÿ’ช ๐Ÿ‘ฑ๐Ÿ“” (๐ŸŒ) [**FastAPI &amp; ๐Ÿ‘จโ€๐Ÿ‘งโ€๐Ÿ‘ฆ** ๐Ÿ“ฐ](/newsletter/){.internal-link target=_blank} ๐Ÿšง โ„น ๐Ÿ”ƒ:
* ๐Ÿ“ฐ ๐Ÿ”ƒ FastAPI &amp; ๐Ÿ‘จโ€๐Ÿ‘งโ€๐Ÿ‘ฆ ๐Ÿ‘ถ
* ๐Ÿฆฎ ๐Ÿ‘ถ
* โš’ ๐Ÿ‘ถ
* ๐Ÿ’” ๐Ÿ”€ ๐Ÿ‘ถ
* ๐Ÿ’โ€โ™‚ &amp; ๐ŸŽฑ ๐Ÿ‘ถ
## โฉ FastAPI ๐Ÿ”› ๐Ÿ‘ฑ๐Ÿ“”
<a href="https://twitter.com/fastapi" class="external-link" target="_blank">โฉ ๐Ÿถ Fastapi ๐Ÿ”› **๐Ÿ‘ฑ๐Ÿ“”**</a> ๐Ÿคš ๐Ÿ“ฐ ๐Ÿ“ฐ ๐Ÿ”ƒ **FastAPI**. ๐Ÿ‘ถ
## โœด **FastAPI** ๐Ÿ“‚
๐Ÿ‘† ๐Ÿ’ช "โœด" FastAPI ๐Ÿ“‚ (๐Ÿ–Š โœด ๐Ÿ”ผ ๐Ÿ” โ–ถ๏ธ๏ธ): <a href="https://github.com/tiangolo/fastapi" class="external-link" target="_blank">https://github.com/tiangolo/fastapi</a>. ๐Ÿ‘ถ ๐Ÿ‘ถ
โŽ โœด, ๐ŸŽ ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ”œ ๐Ÿ’ช ๐Ÿ”Ž โšซ๏ธ ๐ŸŒ… ๐Ÿ’ช &amp; ๐Ÿ‘€ ๐Ÿ‘ˆ โšซ๏ธ โœ”๏ธ โช โš  ๐ŸŽ.
## โŒš ๐Ÿ“‚ ๐Ÿ—ƒ ๐Ÿš€
๐Ÿ‘† ๐Ÿ’ช "โŒš" FastAPI ๐Ÿ“‚ (๐Ÿ–Š "โŒš" ๐Ÿ”ผ ๐Ÿ” โ–ถ๏ธ๏ธ): <a href="https://github.com/tiangolo/fastapi" class="external-link" target="_blank">https://github.com/tiangolo/fastapi</a>. ๐Ÿ‘ถ
๐Ÿ“ค ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ–Š "๐Ÿš€ ๐Ÿ•ด".
๐Ÿ”จ โšซ๏ธ, ๐Ÿ‘† ๐Ÿ”œ ๐Ÿ“จ ๐Ÿ“จ (๐Ÿ‘† ๐Ÿ“ง) ๐Ÿ•โ” ๐Ÿ“ค ๐Ÿ†• ๐Ÿš€ (๐Ÿ†• โฌ) **FastAPI** โฎ๏ธ ๐Ÿ› ๐Ÿ”ง &amp; ๐Ÿ†• โš’.
## ๐Ÿ”— โฎ๏ธ ๐Ÿ“•
๐Ÿ‘† ๐Ÿ’ช ๐Ÿ”— โฎ๏ธ <a href="https://tiangolo.com" class="external-link" target="_blank">๐Ÿ‘ค (๐Ÿ‡น๐Ÿ‡ฆ ๐Ÿ‡ฉ๐Ÿ‡ฌ / `tiangolo`)</a>, ๐Ÿ“•.
๐Ÿ‘† ๐Ÿ’ช:
* <a href="https://github.com/tiangolo" class="external-link" target="_blank">โฉ ๐Ÿ‘ค ๐Ÿ”› **๐Ÿ“‚**</a>.
* ๐Ÿ‘€ ๐ŸŽ ๐Ÿ“‚ โ„น ๐Ÿ— ๐Ÿ‘ค โœ”๏ธ โœ ๐Ÿ‘ˆ ๐Ÿ’ช โ„น ๐Ÿ‘†.
* โฉ ๐Ÿ‘ค ๐Ÿ‘€ ๐Ÿ•โ” ๐Ÿ‘ค โœ ๐Ÿ†• ๐Ÿ“‚ โ„น ๐Ÿ—.
* <a href="https://twitter.com/tiangolo" class="external-link" target="_blank">โฉ ๐Ÿ‘ค ๐Ÿ”› **๐Ÿ‘ฑ๐Ÿ“”**</a> โš–๏ธ <a href="https://fosstodon.org/@tiangolo" class="external-link" target="_blank">โ˜ </a>.
* ๐Ÿ’ฌ ๐Ÿ‘ค โ” ๐Ÿ‘† โš™๏ธ FastAPI (๐Ÿ‘ค ๐Ÿ’Œ ๐Ÿ‘‚ ๐Ÿ‘ˆ).
* ๐Ÿ‘‚ ๐Ÿ•โ” ๐Ÿ‘ค โš’ ๐ŸŽ‰ โš–๏ธ ๐Ÿš€ ๐Ÿ†• ๐Ÿงฐ.
* ๐Ÿ‘† ๐Ÿ’ช <a href="https://twitter.com/fastapi" class="external-link" target="_blank">โฉ ๐Ÿถ Fastapi ๐Ÿ”› ๐Ÿ‘ฑ๐Ÿ“”</a> (๐ŸŽ ๐Ÿง).
* <a href="https://www.linkedin.com/in/tiangolo/" class="external-link" target="_blank">๐Ÿ”— โฎ๏ธ ๐Ÿ‘ค ๐Ÿ”› **๐Ÿ‘ฑ๐Ÿ“”**</a>.
* ๐Ÿ‘‚ ๐Ÿ•โ” ๐Ÿ‘ค โš’ ๐ŸŽ‰ โš–๏ธ ๐Ÿš€ ๐Ÿ†• ๐Ÿงฐ (๐Ÿ‘ ๐Ÿ‘ค โš™๏ธ ๐Ÿ‘ฑ๐Ÿ“” ๐ŸŒ– ๐Ÿ›Ž ๐Ÿคท โ™‚).
* โœ โšซ๏ธโ” ๐Ÿ‘ค โœ (โš–๏ธ โฉ ๐Ÿ‘ค) ๐Ÿ”› <a href="https://dev.to/tiangolo" class="external-link" target="_blank">**๐Ÿ‡ธ๐Ÿ‡ฒ.**</a> โš–๏ธ <a href="https://medium.com/@tiangolo" class="external-link" target="_blank">**๐Ÿ”‰**</a>.
* โœ ๐ŸŽ ๐Ÿ’ญ, ๐Ÿ“„, &amp; โœ ๐Ÿ”ƒ ๐Ÿงฐ ๐Ÿ‘ค โœ”๏ธ โœ.
* โฉ ๐Ÿ‘ค โœ ๐Ÿ•โ” ๐Ÿ‘ค โœ ๐Ÿ•ณ ๐Ÿ†•.
## ๐Ÿ‘ฑ๐Ÿ“” ๐Ÿ”ƒ **FastAPI**
<a href="https://twitter.com/compose/tweet?text=I'm loving @fastapi because... https://github.com/tiangolo/fastapi" class="external-link" target="_blank">๐Ÿ‘ฑ๐Ÿ“” ๐Ÿ”ƒ **FastAPI**</a> &amp; โžก๏ธ ๐Ÿ‘ค &amp; ๐ŸŽ ๐Ÿ’ญ โšซ๏ธโ” ๐Ÿ‘† ๐Ÿ’– โšซ๏ธ. ๐Ÿ‘ถ
๐Ÿ‘ค ๐Ÿ’Œ ๐Ÿ‘‚ ๐Ÿ”ƒ โ” **FastAPI** ๐Ÿ’†โ€โ™‚ โš™๏ธ, โšซ๏ธโ” ๐Ÿ‘† โœ”๏ธ ๐Ÿ’– โšซ๏ธ, โ” ๐Ÿ—/๐Ÿข ๐Ÿ‘† โš™๏ธ โšซ๏ธ, โ™’๏ธ.
## ๐Ÿ—ณ FastAPI
* <a href="https://www.slant.co/options/34241/~fastapi-review" class="external-link" target="_blank">๐Ÿ—ณ **FastAPI** ๐Ÿ“</a>.
* <a href="https://alternativeto.net/software/fastapi/" class="external-link" target="_blank">๐Ÿ—ณ **FastAPI** ๐Ÿ“ฑ</a>.
* <a href="https://stackshare.io/pypi-fastapi" class="external-link" target="_blank">๐Ÿ’ฌ ๐Ÿ‘† โš™๏ธ **FastAPI** ๐Ÿ”› โ„น</a>.
## โ„น ๐ŸŽ โฎ๏ธ โ” ๐Ÿ“‚
๐Ÿ‘† ๐Ÿ’ช ๐Ÿ”„ &amp; โ„น ๐ŸŽ โฎ๏ธ ๐Ÿ‘ซ โ”:
* <a href="https://github.com/tiangolo/fastapi/discussions/categories/questions?discussions_q=category%3AQuestions+is%3Aunanswered" class="external-link" target="_blank">๐Ÿ“‚ ๐Ÿ’ฌ</a>
* <a href="https://github.com/tiangolo/fastapi/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc+label%3Aquestion+-label%3Aanswered+" class="external-link" target="_blank">๐Ÿ“‚ โ”</a>
๐Ÿ“š ๐Ÿ’ผ ๐Ÿ‘† 5๏ธโƒฃ๐Ÿ“† โช ๐Ÿ’ญ โ” ๐Ÿ“š โ”. ๐Ÿ‘ถ
๐Ÿšฅ ๐Ÿ‘† ๐Ÿค ๐Ÿ“š ๐Ÿ‘ซ๐Ÿ‘ซ โฎ๏ธ ๐Ÿ‘ซ โ”, ๐Ÿ‘† ๐Ÿ”œ โ–ถ๏ธ๏ธ ๐Ÿ›‚ [FastAPI ๐Ÿ•ด](fastapi-people.md#experts){.internal-link target=_blank}. ๐Ÿ‘ถ
๐Ÿ’ญ, ๐Ÿ† โš  โ˜: ๐Ÿ”„ ๐Ÿ˜‡. ๐Ÿ‘ซ๐Ÿ‘ซ ๐Ÿ‘Ÿ โฎ๏ธ ๐Ÿ‘ซ ๐Ÿ˜ฉ &amp; ๐Ÿ“š ๐Ÿ’ผ ๐Ÿšซ ๐Ÿ’ญ ๐Ÿ† ๐ŸŒŒ, โœ‹๏ธ ๐Ÿ”„ ๐Ÿ† ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ˜‡. ๐Ÿ‘ถ
๐Ÿ’ญ **FastAPI** ๐Ÿ‘ช ๐Ÿ˜‡ &amp; ๐Ÿ‘. ๐ŸŽ ๐Ÿ•ฐ, ๐Ÿšซ ๐Ÿšซ ๐ŸŽญ โš–๏ธ ๐Ÿ˜› ๐ŸŽญ โคต ๐ŸŽ. ๐Ÿ‘ฅ โœ”๏ธ โœŠ ๐Ÿ’… ๐Ÿ”  ๐ŸŽ.
---
๐Ÿ“ฅ โ” โ„น ๐ŸŽ โฎ๏ธ โ” (๐Ÿ’ฌ โš–๏ธ โ”):
### ๐Ÿค” โ”
* โœ… ๐Ÿšฅ ๐Ÿ‘† ๐Ÿ’ช ๐Ÿค” โšซ๏ธโ” **๐ŸŽฏ** &amp; โš™๏ธ ๐Ÿ’ผ ๐Ÿ‘จโ€๐Ÿ’ผ ๐Ÿ’ฌ.
* โคด๏ธ โœ… ๐Ÿšฅ โ” (โญ• ๐Ÿ‘ช โ”) **๐Ÿ†‘**.
* ๐Ÿ“š ๐Ÿ’ผ โ” ๐Ÿ’ญ ๐Ÿ”ƒ ๐Ÿ‘ฝ โš— โšช๏ธโžก๏ธ ๐Ÿ‘ฉโ€๐Ÿ’ป, โœ‹๏ธ ๐Ÿ“ค ๐Ÿ’ช **๐Ÿ‘** 1๏ธโƒฃ. ๐Ÿšฅ ๐Ÿ‘† ๐Ÿ’ช ๐Ÿค” โš  &amp; โš™๏ธ ๐Ÿ’ผ ๐Ÿ‘, ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ’ช ๐Ÿค” ๐Ÿ‘ **๐ŸŽ› โš—**.
* ๐Ÿšฅ ๐Ÿ‘† ๐Ÿ’ช ๐Ÿšซ ๐Ÿค” โ”, ๐Ÿ’ญ ๐ŸŒ– **โ„น**.
### ๐Ÿ”ฌ โš 
๐ŸŒ… ๐Ÿ’ผ &amp; ๐Ÿ† โ” ๐Ÿ“ค ๐Ÿ•ณ ๐Ÿ”— ๐Ÿ‘จโ€๐Ÿ’ผ **โฎ๏ธ ๐Ÿ“Ÿ**.
๐Ÿ“š ๐Ÿ’ผ ๐Ÿ‘ซ ๐Ÿ”œ ๐Ÿ•ด ๐Ÿ“ ๐Ÿงฌ ๐Ÿ“Ÿ, โœ‹๏ธ ๐Ÿ‘ˆ ๐Ÿšซ ๐Ÿฅƒ **๐Ÿ”ฌ โš **.
* ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ’ญ ๐Ÿ‘ซ ๐Ÿšš <a href="https://stackoverflow.com/help/minimal-reproducible-example" class="external-link" target="_blank">โญ, ๐Ÿ”ฌ, ๐Ÿ–ผ</a>, ๐Ÿ‘ˆ ๐Ÿ‘† ๐Ÿ’ช **๐Ÿ“-๐Ÿ“‹** &amp; ๐Ÿƒ ๐ŸŒ ๐Ÿ‘€ ๐ŸŽ โŒ โš–๏ธ ๐ŸŽญ ๐Ÿ‘ซ ๐Ÿ‘€, โš–๏ธ ๐Ÿค” ๐Ÿ‘ซ โš™๏ธ ๐Ÿ’ผ ๐Ÿ‘.
* ๐Ÿšฅ ๐Ÿ‘† ๐Ÿ˜Ÿ ๐Ÿ’โ€โ™‚๏ธ ๐Ÿ‘, ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ”„ **โœ ๐Ÿ–ผ** ๐Ÿ’– ๐Ÿ‘ˆ ๐Ÿ‘†, ๐Ÿงข ๐Ÿ”› ๐Ÿ“› โš . โœ”๏ธ ๐Ÿคฏ ๐Ÿ‘ˆ ๐Ÿ‘‰ ๐Ÿ’ช โœŠ ๐Ÿ“š ๐Ÿ•ฐ &amp; โšซ๏ธ ๐Ÿ’ช ๐Ÿ‘ป ๐Ÿ’ญ ๐Ÿ‘ซ โœ โš  ๐Ÿฅ‡.
### ๐Ÿค” โš—
* โฎ๏ธ ๐Ÿ’†โ€โ™‚ ๐Ÿ’ช ๐Ÿค” โ”, ๐Ÿ‘† ๐Ÿ’ช ๐Ÿค ๐Ÿ‘ซ ๐Ÿ’ช **โ”**.
* ๐Ÿ“š ๐Ÿ’ผ, โšซ๏ธ ๐Ÿ‘ ๐Ÿค” ๐Ÿ‘ซ **๐Ÿ“ˆ โš  โš–๏ธ โš™๏ธ ๐Ÿ’ผ**, โ†ฉ๏ธ ๐Ÿ“ค 5๏ธโƒฃ๐Ÿ“† ๐Ÿ‘ ๐ŸŒŒ โŽ โšซ๏ธ ๐ŸŒ˜ โšซ๏ธโ” ๐Ÿ‘ซ ๐Ÿ”„.
### ๐Ÿ’ญ ๐Ÿ”
๐Ÿšฅ ๐Ÿ‘ซ ๐Ÿ“จ, ๐Ÿ“ค โ†• ๐Ÿคž ๐Ÿ‘† ๐Ÿ”œ โœ”๏ธ โŽ ๐Ÿ‘ซ โš , ใŠ—, **๐Ÿ‘† ๐Ÿ’‚**โ— ๐Ÿฆธ
* ๐Ÿ”œ, ๐Ÿšฅ ๐Ÿ‘ˆ โŽ ๐Ÿ‘ซ โš , ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ’ญ ๐Ÿ‘ซ:
* ๐Ÿ“‚ ๐Ÿ’ฌ: โ„ข ๐Ÿค **โ”**.
* ๐Ÿ“‚ โ”: **๐Ÿ”** โ”**.
## โŒš ๐Ÿ“‚ ๐Ÿ—ƒ
๐Ÿ‘† ๐Ÿ’ช "โŒš" FastAPI ๐Ÿ“‚ (๐Ÿ–Š "โŒš" ๐Ÿ”ผ ๐Ÿ” โ–ถ๏ธ๏ธ): <a href="https://github.com/tiangolo/fastapi" class="external-link" target="_blank">https://github.com/tiangolo/fastapi</a>. ๐Ÿ‘ถ
๐Ÿšฅ ๐Ÿ‘† ๐Ÿ–Š "๐Ÿ‘€" โ†ฉ๏ธ "๐Ÿš€ ๐Ÿ•ด" ๐Ÿ‘† ๐Ÿ”œ ๐Ÿ“จ ๐Ÿ“จ ๐Ÿ•โ” ๐Ÿ‘ฑ โœ ๐Ÿ†• โ” โš–๏ธ โ”. ๐Ÿ‘† ๐Ÿ’ช โœ” ๐Ÿ‘ˆ ๐Ÿ‘† ๐Ÿ•ด ๐Ÿ’š ๐Ÿšจ ๐Ÿ”ƒ ๐Ÿ†• โ”, โš–๏ธ ๐Ÿ’ฌ, โš–๏ธ ๐ŸŽธ, โ™’๏ธ.
โคด๏ธ ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ”„ &amp; โ„น ๐Ÿ‘ซ โŽ ๐Ÿ‘ˆ โ”.
## ๐Ÿ’ญ โ”
๐Ÿ‘† ๐Ÿ’ช <a href="https://github.com/tiangolo/fastapi/discussions/new?category=questions" class="external-link" target="_blank">โœ ๐Ÿ†• โ”</a> ๐Ÿ“‚ ๐Ÿ—ƒ, ๐Ÿ–ผ:
* ๐Ÿ’ญ **โ”** โš–๏ธ ๐Ÿ’ญ ๐Ÿ”ƒ **โš **.
* ๐Ÿค” ๐Ÿ†• **โš’**.
**๐Ÿ—’**: ๐Ÿšฅ ๐Ÿ‘† โšซ๏ธ, โคด๏ธ ๐Ÿ‘ค ๐Ÿ”œ ๐Ÿ’ญ ๐Ÿ‘† โ„น ๐ŸŽ. ๐Ÿ‘ถ
## ๐Ÿ“„ ๐Ÿšฒ ๐Ÿ“จ
๐Ÿ‘† ๐Ÿ’ช โ„น ๐Ÿ‘ค ๐Ÿ“„ ๐Ÿšฒ ๐Ÿ“จ โšช๏ธโžก๏ธ ๐ŸŽ.
๐Ÿ”„, ๐Ÿ™ ๐Ÿ”„ ๐Ÿ‘† ๐Ÿ† ๐Ÿ˜‡. ๐Ÿ‘ถ
---
๐Ÿ“ฅ โšซ๏ธโ” โœ”๏ธ ๐Ÿคฏ &amp; โ” ๐Ÿ“„ ๐Ÿšฒ ๐Ÿ“จ:
### ๐Ÿค” โš 
* ๐Ÿฅ‡, โš’ ๐Ÿ’ญ ๐Ÿ‘† **๐Ÿค” โš ** ๐Ÿ‘ˆ ๐Ÿšฒ ๐Ÿ“จ ๐Ÿ”„ โŽ. โšซ๏ธ ๐Ÿ’ช โœ”๏ธ ๐Ÿ“ ๐Ÿ’ฌ ๐Ÿ“‚ ๐Ÿ’ฌ โš–๏ธ โ”.
* ๐Ÿ“ค ๐Ÿ‘ ๐Ÿคž ๐Ÿ‘ˆ ๐Ÿšฒ ๐Ÿ“จ ๐Ÿšซ ๐Ÿค™ ๐Ÿ’ช โ†ฉ๏ธ โš  ๐Ÿ’ช โŽ **๐ŸŽ ๐ŸŒŒ**. โคด๏ธ ๐Ÿ‘† ๐Ÿ’ช ๐Ÿค” โš–๏ธ ๐Ÿ’ญ ๐Ÿ”ƒ ๐Ÿ‘ˆ.
### ๐Ÿšซ ๐Ÿ˜Ÿ ๐Ÿ”ƒ ๐Ÿ‘—
* ๐Ÿšซ ๐Ÿ˜Ÿ ๐Ÿ’โ€โ™‚๏ธ ๐ŸŒ… ๐Ÿ”ƒ ๐Ÿ‘œ ๐Ÿ’– ๐Ÿ’• ๐Ÿ“ง ๐Ÿ‘—, ๐Ÿ‘ค ๐Ÿ”œ ๐Ÿฅฌ &amp; ๐Ÿ”— ๐Ÿ›ƒ ๐Ÿ’• โŽ.
* ๐Ÿšซ ๐Ÿ˜Ÿ ๐Ÿ”ƒ ๐Ÿ‘— ๐Ÿšซ, ๐Ÿ“ค โช ๐Ÿง ๐Ÿงฐ โœ… ๐Ÿ‘ˆ.
&amp; ๐Ÿšฅ ๐Ÿ“ค ๐Ÿ™† ๐ŸŽ ๐Ÿ‘— โš–๏ธ โš– ๐Ÿ’ช, ๐Ÿ‘ค ๐Ÿ”œ ๐Ÿ’ญ ๐Ÿ”— ๐Ÿ‘ˆ, โš–๏ธ ๐Ÿ‘ค ๐Ÿ”œ ๐Ÿšฎ ๐Ÿ’• ๐Ÿ”› ๐Ÿ” โฎ๏ธ ๐Ÿ’ช ๐Ÿ”€.
### โœ… ๐Ÿ“Ÿ
* โœ… &amp; โœ ๐Ÿ“Ÿ, ๐Ÿ‘€ ๐Ÿšฅ โšซ๏ธ โš’ ๐Ÿ”‘, **๐Ÿƒ โšซ๏ธ ๐ŸŒ** &amp; ๐Ÿ‘€ ๐Ÿšฅ โšซ๏ธ ๐Ÿค™ โŽ โš .
* โคด๏ธ **๐Ÿค** ๐Ÿ’ฌ ๐Ÿ‘ˆ ๐Ÿ‘† ๐Ÿ‘ˆ, ๐Ÿ‘ˆ โ” ๐Ÿ‘ค ๐Ÿ”œ ๐Ÿ’ญ ๐Ÿ‘† ๐Ÿค™ โœ… โšซ๏ธ.
!!! info
๐Ÿ‘, ๐Ÿ‘ค ๐Ÿ’ช ๐Ÿšซ ๐ŸŽฏ ๐Ÿ’™ ๐ŸŽธ ๐Ÿ‘ˆ โœ”๏ธ ๐Ÿ“š โœ”.
๐Ÿ“š ๐Ÿ•ฐ โšซ๏ธ โœ”๏ธ ๐Ÿ”จ ๐Ÿ‘ˆ ๐Ÿ“ค ๐ŸŽธ โฎ๏ธ 3๏ธโƒฃ, 5๏ธโƒฃ โš–๏ธ ๐ŸŒ… โœ”, ๐ŸŽฒ โ†ฉ๏ธ ๐Ÿ“› ๐Ÿ˜Œ, โœ‹๏ธ ๐Ÿ•โ” ๐Ÿ‘ค โœ… ๐ŸŽธ, ๐Ÿ‘ซ ๐Ÿค™ ๐Ÿ’”, โœ”๏ธ ๐Ÿ›, โš–๏ธ ๐Ÿšซ โŽ โš  ๐Ÿ‘ซ ๐Ÿ›„ โŽ. ๐Ÿ‘ถ
, โšซ๏ธ ๐Ÿค™ โš  ๐Ÿ‘ˆ ๐Ÿ‘† ๐Ÿค™ โœ &amp; ๐Ÿƒ ๐Ÿ“Ÿ, &amp; โžก๏ธ ๐Ÿ‘ค ๐Ÿ’ญ ๐Ÿค ๐Ÿ‘ˆ ๐Ÿ‘†. ๐Ÿ‘ถ
* ๐Ÿšฅ ๐Ÿ‡ต๐Ÿ‡ท ๐Ÿ’ช ๐Ÿ“‰ ๐ŸŒŒ, ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ’ญ ๐Ÿ‘ˆ, โœ‹๏ธ ๐Ÿ“ค ๐Ÿ™…โ€โ™‚ ๐Ÿ’ช ๐Ÿ’โ€โ™‚๏ธ ๐Ÿ˜Ÿ, ๐Ÿ“ค 5๏ธโƒฃ๐Ÿ“† ๐Ÿ“š ๐Ÿค” โ˜ ๐ŸŽ‘ (&amp; ๐Ÿ‘ค ๐Ÿ”œ โœ”๏ธ ๐Ÿ‘‡ ๐Ÿ‘ ๐Ÿ‘ ๐Ÿ‘ถ), โšซ๏ธ ๐Ÿ‘ป ๐Ÿšฅ ๐Ÿ‘† ๐Ÿ’ช ๐ŸŽฏ ๐Ÿ”› โš› ๐Ÿ‘œ.
### ๐Ÿ’ฏ
* โ„น ๐Ÿ‘ค โœ… ๐Ÿ‘ˆ ๐Ÿ‡ต๐Ÿ‡ท โœ”๏ธ **๐Ÿ’ฏ**.
* โœ… ๐Ÿ‘ˆ ๐Ÿ’ฏ **โŒ** โญ ๐Ÿ‡ต๐Ÿ‡ท. ๐Ÿ‘ถ
* โคด๏ธ โœ… ๐Ÿ‘ˆ ๐Ÿ’ฏ **๐Ÿšถโ€โ™€๏ธ** โฎ๏ธ ๐Ÿ‡ต๐Ÿ‡ท. ๐Ÿ‘ถ
* ๐Ÿ“š ๐ŸŽธ ๐Ÿšซ โœ”๏ธ ๐Ÿ’ฏ, ๐Ÿ‘† ๐Ÿ’ช **๐ŸŽ—** ๐Ÿ‘ซ ๐Ÿšฎ ๐Ÿ’ฏ, โš–๏ธ ๐Ÿ‘† ๐Ÿ’ช **๐Ÿค”** ๐Ÿ’ฏ ๐Ÿ‘†. ๐Ÿ‘ˆ 1๏ธโƒฃ ๐Ÿ‘œ ๐Ÿ‘ˆ ๐Ÿด ๐ŸŒ… ๐Ÿ•ฐ &amp; ๐Ÿ‘† ๐Ÿ’ช โ„น ๐Ÿ“š โฎ๏ธ ๐Ÿ‘ˆ.
* โคด๏ธ ๐Ÿค โšซ๏ธโ” ๐Ÿ‘† ๐Ÿ”„, ๐Ÿ‘ˆ ๐ŸŒŒ ๐Ÿ‘ค ๐Ÿ”œ ๐Ÿ’ญ ๐Ÿ‘ˆ ๐Ÿ‘† โœ… โšซ๏ธ. ๐Ÿ‘ถ
## โœ ๐Ÿšฒ ๐Ÿ“จ
๐Ÿ‘† ๐Ÿ’ช [๐Ÿ“‰](contributing.md){.internal-link target=_blank} โ„น ๐Ÿ“Ÿ โฎ๏ธ ๐Ÿšฒ ๐Ÿ“จ, ๐Ÿ–ผ:
* ๐Ÿ”ง ๐Ÿคญ ๐Ÿ‘† ๐Ÿ”Ž ๐Ÿ”› ๐Ÿงพ.
* ๐Ÿ’ฐ ๐Ÿ“„, ๐Ÿ“น, โš–๏ธ ๐Ÿ“ป ๐Ÿ‘† โœ โš–๏ธ ๐Ÿ”Ž ๐Ÿ”ƒ FastAPI <a href="https://github.com/tiangolo/fastapi/edit/master/docs/en/data/external_links.yml" class="external-link" target="_blank">โœ ๐Ÿ‘‰ ๐Ÿ“</a>.
* โš’ ๐Ÿ’ญ ๐Ÿ‘† ๐Ÿšฎ ๐Ÿ‘† ๐Ÿ”— โ–ถ๏ธ ๐Ÿ”— ๐Ÿ“„.
* โ„น [๐Ÿ’ฌ ๐Ÿงพ](contributing.md#translations){.internal-link target=_blank} ๐Ÿ‘† ๐Ÿ‡ช๐Ÿ‡ธ.
* ๐Ÿ‘† ๐Ÿ’ช โ„น ๐Ÿ“„ โœ โœ ๐ŸŽ.
* ๐Ÿ› ๏ธ ๐Ÿ†• ๐Ÿงพ ๐Ÿ“„.
* ๐Ÿ”ง โ™ป โ”/๐Ÿ›.
* โš’ ๐Ÿ’ญ ๐Ÿšฎ ๐Ÿ’ฏ.
* ๐Ÿšฎ ๐Ÿ†• โš’.
* โš’ ๐Ÿ’ญ ๐Ÿšฎ ๐Ÿ’ฏ.
* โš’ ๐Ÿ’ญ ๐Ÿšฎ ๐Ÿงพ ๐Ÿšฅ โšซ๏ธ ๐Ÿ”—.
## โ„น ๐Ÿšง FastAPI
โ„น ๐Ÿ‘ค ๐Ÿšง **FastAPI**โ— ๐Ÿ‘ถ
๐Ÿ“ค ๐Ÿ“š ๐Ÿ‘ท, &amp; ๐Ÿ† โšซ๏ธ, **๐Ÿ‘†** ๐Ÿ’ช โšซ๏ธ.
๐Ÿ‘‘ ๐Ÿ“‹ ๐Ÿ‘ˆ ๐Ÿ‘† ๐Ÿ’ช โ–ถ๏ธ๏ธ ๐Ÿ”œ:
* [โ„น ๐ŸŽ โฎ๏ธ โ” ๐Ÿ“‚](#help-others-with-questions-in-github){.internal-link target=_blank} (๐Ÿ‘€ ๐Ÿ“„ ๐Ÿ”›).
* [๐Ÿ“„ ๐Ÿšฒ ๐Ÿ“จ](#review-pull-requests){.internal-link target=_blank} (๐Ÿ‘€ ๐Ÿ“„ ๐Ÿ”›).
๐Ÿ‘ˆ 2๏ธโƒฃ ๐Ÿ“‹ โšซ๏ธโ” **๐Ÿด ๐Ÿ•ฐ ๐Ÿ†**. ๐Ÿ‘ˆ ๐Ÿ‘‘ ๐Ÿ‘ท ๐Ÿ† FastAPI.
๐Ÿšฅ ๐Ÿ‘† ๐Ÿ’ช โ„น ๐Ÿ‘ค โฎ๏ธ ๐Ÿ‘ˆ, **๐Ÿ‘† ๐Ÿค ๐Ÿ‘ค ๐Ÿšง FastAPI** &amp; โš’ ๐Ÿ’ญ โšซ๏ธ ๐Ÿšง **๐Ÿ› ๏ธ โฉ &amp; ๐Ÿ‘ป**. ๐Ÿ‘ถ
## ๐Ÿ›‘ ๐Ÿ’ฌ
๐Ÿ›‘ ๐Ÿ‘ถ <a href="https://discord.gg/VQjSZaeJmf" class="external-link" target="_blank">๐Ÿ˜ง ๐Ÿ’ฌ ๐Ÿ’ฝ</a> ๐Ÿ‘ถ &amp; ๐Ÿค™ ๐Ÿ‘… โฎ๏ธ ๐ŸŽ FastAPI ๐Ÿ‘ช.
!!! tip
โ”, ๐Ÿ’ญ ๐Ÿ‘ซ <a href="https://github.com/tiangolo/fastapi/discussions/new?category=questions" class="external-link" target="_blank">๐Ÿ“‚ ๐Ÿ’ฌ</a>, ๐Ÿ“ค ๐ŸŒ… ๐Ÿ‘ ๐Ÿคž ๐Ÿ‘† ๐Ÿ”œ ๐Ÿ“จ โ„น [FastAPI ๐Ÿ•ด](fastapi-people.md#experts){.internal-link target=_blank}.
โš™๏ธ ๐Ÿ’ฌ ๐Ÿ•ด ๐ŸŽ ๐Ÿข ๐Ÿ’ฌ.
๐Ÿ“ค โฎ๏ธ <a href="https://gitter.im/tiangolo/fastapi" class="external-link" target="_blank">๐ŸฅŠ ๐Ÿ’ฌ</a>, โœ‹๏ธ โšซ๏ธ ๐Ÿšซ โœ”๏ธ ๐Ÿ“ป &amp; ๐Ÿง โš’, ๐Ÿ’ฌ ๐ŸŒ– โš , ๐Ÿ˜ง ๐Ÿ”œ ๐Ÿ‘ โš™๏ธ.
### ๐Ÿšซ โš™๏ธ ๐Ÿ’ฌ โ”
โœ”๏ธ ๐Ÿคฏ ๐Ÿ‘ˆ ๐Ÿ’ฌ โœ” ๐ŸŒ… "๐Ÿ†“ ๐Ÿ’ฌ", โšซ๏ธ โฉ ๐Ÿ’ญ โ” ๐Ÿ‘ˆ ๐Ÿ’โ€โ™‚๏ธ ๐Ÿข &amp; ๐ŸŒ… โš  โ”,, ๐Ÿ‘† ๐Ÿ’ช ๐Ÿšซ ๐Ÿ“จ โ”.
๐Ÿ“‚, ๐Ÿ“„ ๐Ÿ”œ ๐Ÿฆฎ ๐Ÿ‘† โœ โ–ถ๏ธ๏ธ โ” ๐Ÿ‘ˆ ๐Ÿ‘† ๐Ÿ’ช ๐ŸŒ– ๐Ÿ’ช ๐Ÿคš ๐Ÿ‘ โ”, โš–๏ธ โŽ โš  ๐Ÿ‘† โญ ๐Ÿ’ฌ. &amp; ๐Ÿ“‚ ๐Ÿ‘ค ๐Ÿ’ช โš’ ๐Ÿ’ญ ๐Ÿ‘ค ๐Ÿ•ง โ” ๐ŸŒ, ๐Ÿšฅ โšซ๏ธ โœŠ ๐Ÿ•ฐ. ๐Ÿ‘ค ๐Ÿ’ช ๐Ÿšซ ๐Ÿค™ ๐Ÿ‘ˆ โฎ๏ธ ๐Ÿ’ฌ โš™๏ธ. ๐Ÿ‘ถ
๐Ÿ’ฌ ๐Ÿ’ฌ โš™๏ธ ๐Ÿšซ ๐Ÿ’ช ๐Ÿ“‡ ๐Ÿ“‚, โ” &amp; โ” 5๏ธโƒฃ๐Ÿ“† ๐Ÿคš ๐Ÿ’ธ ๐Ÿ’ฌ. &amp; ๐Ÿ•ด ๐Ÿ• ๐Ÿ“‚ ๐Ÿ’ฏ โ–ถ๏ธ๏ธ [FastAPI ๐Ÿ•ด](fastapi-people.md#experts){.internal-link target=_blank}, ๐Ÿ‘† ๐Ÿ”œ ๐ŸŒ… ๐ŸŽฒ ๐Ÿ“จ ๐ŸŒ… ๐Ÿ™‹ ๐Ÿ“‚.
๐Ÿ”› ๐ŸŽ ๐Ÿš„, ๐Ÿ“ค ๐Ÿ’ฏ ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ’ฌ โš™๏ธ, ๐Ÿ“ค โ†• ๐Ÿคž ๐Ÿ‘† ๐Ÿ”œ ๐Ÿ”Ž ๐Ÿ‘ฑ ๐Ÿ’ฌ ๐Ÿ“ค, ๐ŸŒ– ๐ŸŒ ๐Ÿ•ฐ. ๐Ÿ‘ถ
## ๐Ÿ’ฐ ๐Ÿ“•
๐Ÿ‘† ๐Ÿ’ช ๐Ÿ’ฐ ๐Ÿ•โ€๐Ÿฆบ ๐Ÿ“• (๐Ÿ‘ค) ๐Ÿ”˜ <a href="https://github.com/sponsors/tiangolo" class="external-link" target="_blank">๐Ÿ“‚ ๐Ÿ’ฐ</a>.
๐Ÿ“ค ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ› ๐Ÿ‘ค โ˜• ๐Ÿ‘ถ ๐Ÿ‘ถ ๐Ÿ’ฌ ๐Ÿ‘. ๐Ÿ‘ถ
&amp; ๐Ÿ‘† ๐Ÿ’ช โ–ถ๏ธ๏ธ ๐Ÿฅ‡1st โš–๏ธ ๐ŸŒŸ ๐Ÿ’ฐ FastAPI. ๐Ÿ‘ถ ๐Ÿ‘ถ
## ๐Ÿ’ฐ ๐Ÿงฐ ๐Ÿ‘ˆ ๐Ÿ‹๏ธ FastAPI
๐Ÿ‘† โœ”๏ธ ๐Ÿ‘€ ๐Ÿงพ, FastAPI ๐Ÿง ๐Ÿ”› โŒš ๐Ÿ˜, ๐Ÿ’ƒ &amp; Pydantic.
๐Ÿ‘† ๐Ÿ’ช ๐Ÿ’ฐ:
* <a href="https://github.com/sponsors/samuelcolvin" class="external-link" target="_blank">โœก ๐Ÿ (Pydantic)</a>
* <a href="https://github.com/sponsors/encode" class="external-link" target="_blank">๐Ÿ—œ (๐Ÿ’ƒ, Uvicorn)</a>
---
๐Ÿ‘ โ— ๐Ÿ‘ถ

79
docs/em/docs/history-design-future.md

@ -0,0 +1,79 @@
# ๐Ÿ“–, ๐Ÿ”ง &amp; ๐Ÿ”ฎ
๐Ÿ•ฐ ๐Ÿ, <a href="https://github.com/tiangolo/fastapi/issues/3#issuecomment-454956920" class="external-link" target="_blank"> **FastAPI** ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ’ญ</a>:
&gt; โšซ๏ธโ” ๐Ÿ“– ๐Ÿ‘‰ ๐Ÿ— โ“ โšซ๏ธ ๐Ÿ˜‘ โœ”๏ธ ๐Ÿ‘Ÿ โšช๏ธโžก๏ธ ๐Ÿ•ณ ๐Ÿ‘Œ ๐Ÿ‘ฉโ€โคโ€๐Ÿ‘จ ๐Ÿ—“๏ธ [...]
๐Ÿ“ฅ ๐Ÿฅ ๐Ÿ– ๐Ÿ‘ˆ ๐Ÿ“–.
## ๐ŸŽ›
๐Ÿ‘ค โœ”๏ธ ๐Ÿ— ๐Ÿ”— โฎ๏ธ ๐Ÿ— ๐Ÿ“„ ๐Ÿ“š 1๏ธโƒฃ2๏ธโƒฃ๐Ÿ—“๏ธ (๐ŸŽฐ ๐Ÿซ, ๐Ÿ“Ž โš™๏ธ, ๐Ÿ” ๐Ÿ‘จโ€๐Ÿญ, โ˜ ๐Ÿ’ฝ, โ™’๏ธ), โ†˜๏ธ ๐Ÿ“š ๐Ÿ‰ ๐Ÿ‘ฉโ€๐Ÿ’ป.
๐Ÿ• ๐Ÿ‘ˆ, ๐Ÿ‘ค ๐Ÿ’ช ๐Ÿ”ฌ, ๐Ÿ’ฏ &amp; โš™๏ธ ๐Ÿ“š ๐ŸŽ›.
๐Ÿ“– **FastAPI** ๐Ÿ‘‘ ๐Ÿ• ๐Ÿ“– ๐Ÿšฎ โช.
๐Ÿ™†โ€โ™€ ๐Ÿ“„ [๐ŸŽ›](alternatives.md){.internal-link target=_blank}:
<blockquote markdown="1">
**FastAPI** ๐Ÿšซ๐Ÿ”œ ๐Ÿ”€ ๐Ÿšฅ ๐Ÿšซ โฎ๏ธ ๐Ÿ‘ท ๐ŸŽ.
๐Ÿ“ค โœ”๏ธ ๐Ÿ“š ๐Ÿงฐ โœ โญ ๐Ÿ‘ˆ โœ”๏ธ โ„น ๐Ÿ˜ฎ ๐Ÿšฎ ๐Ÿ—.
๐Ÿ‘ค โœ”๏ธ โŽ ๐Ÿ— ๐Ÿ†• ๐Ÿ› ๏ธ ๐Ÿ“š 1๏ธโƒฃ2๏ธโƒฃ๐Ÿ—“๏ธ. ๐Ÿฅ‡ ๐Ÿ‘ค ๐Ÿ”„ โŽ ๐ŸŒ โš’ ๐Ÿ“” **FastAPI** โš™๏ธ ๐Ÿ“š ๐ŸŽ ๐Ÿ› ๏ธ, ๐Ÿ”Œ-๐Ÿ”Œ, &amp; ๐Ÿงฐ.
โœ‹๏ธ โ˜, ๐Ÿ“ค ๐Ÿ™…โ€โ™‚ ๐ŸŽ ๐ŸŽ› ๐ŸŒ˜ ๐Ÿ— ๐Ÿ•ณ ๐Ÿ‘ˆ ๐Ÿšš ๐ŸŒ ๐Ÿ‘ซ โš’, โœŠ ๐Ÿ† ๐Ÿ’ญ โšช๏ธโžก๏ธ โฎ๏ธ ๐Ÿงฐ, &amp; ๐ŸŒ€ ๐Ÿ‘ซ ๐Ÿ† ๐ŸŒŒ ๐Ÿ’ช, โš™๏ธ ๐Ÿ‡ช๐Ÿ‡ธ โš’ ๐Ÿ‘ˆ โž–๐Ÿšซ ๐Ÿ’ช โญ (๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ โž• ๐Ÿ†Ž ๐Ÿ”‘).
</blockquote>
## ๐Ÿ”ฌ
โš™๏ธ ๐ŸŒ โฎ๏ธ ๐ŸŽ› ๐Ÿ‘ค โœ”๏ธ ๐Ÿคž ๐Ÿ’ก โšช๏ธโžก๏ธ ๐ŸŒ ๐Ÿ‘ซ, โœŠ ๐Ÿ’ญ, &amp; ๐ŸŒ€ ๐Ÿ‘ซ ๐Ÿ† ๐ŸŒŒ ๐Ÿ‘ค ๐Ÿ’ช ๐Ÿ”Ž ๐Ÿ‘ค &amp; ๐Ÿ‰ ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ‘ค โœ”๏ธ ๐Ÿ‘ท โฎ๏ธ.
๐Ÿ–ผ, โšซ๏ธ ๐Ÿ†‘ ๐Ÿ‘ˆ ๐ŸŽฒ โšซ๏ธ ๐Ÿ”œ โš“๏ธ ๐Ÿ”› ๐Ÿฉ ๐Ÿ ๐Ÿ†Ž ๐Ÿ”‘.
, ๐Ÿ† ๐ŸŽฏ โš™๏ธ โช โ™ป ๐Ÿฉ.
, โญ โ–ถ๏ธ ๐Ÿ“Ÿ **FastAPI**, ๐Ÿ‘ค ๐Ÿ’ธ ๐Ÿ“š ๐Ÿ—“๏ธ ๐ŸŽ“ ๐Ÿ”Œ ๐Ÿ—„, ๐ŸŽป ๐Ÿ”—, Oauth2๏ธโƒฃ, โ™’๏ธ. ๐ŸŽฏ ๐Ÿ‘ซ ๐Ÿ’›, ๐Ÿ”€, &amp; ๐Ÿ”บ.
## ๐Ÿ”ง
โคด๏ธ ๐Ÿ‘ค ๐Ÿ’ธ ๐Ÿ•ฐ ๐Ÿ”ง ๐Ÿ‘ฉโ€๐Ÿ’ป "๐Ÿ› ๏ธ" ๐Ÿ‘ค ๐Ÿ’š โœ”๏ธ ๐Ÿ‘ฉโ€๐Ÿ’ป (๐Ÿ‘ฉโ€๐Ÿ’ป โš™๏ธ FastAPI).
๐Ÿ‘ค ๐Ÿ’ฏ ๐Ÿ“š ๐Ÿ’ญ ๐Ÿ† ๐ŸŒŸ ๐Ÿ ๐Ÿ‘จโ€๐ŸŽจ: ๐Ÿ—’, ๐Ÿ†š ๐Ÿ“Ÿ, ๐ŸŽ  ๐Ÿงข ๐Ÿ‘จโ€๐ŸŽจ.
๐Ÿ <a href="https://www.jetbrains.com/research/python-developers-survey-2018/#development-tools" class="external-link" target="_blank">๐Ÿ ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ”ฌ</a>, ๐Ÿ‘ˆ ๐Ÿ“” ๐Ÿ”ƒ 8๏ธโƒฃ0๏ธโƒฃ ๐Ÿ’ฏ ๐Ÿ‘ฉโ€๐Ÿ’ป.
โšซ๏ธ โ›“ ๐Ÿ‘ˆ **FastAPI** ๐ŸŽฏ ๐Ÿ’ฏ โฎ๏ธ ๐Ÿ‘จโ€๐ŸŽจ โš™๏ธ 8๏ธโƒฃ0๏ธโƒฃ ๐Ÿ’ฏ ๐Ÿ ๐Ÿ‘ฉโ€๐Ÿ’ป. &amp; ๐Ÿ† ๐ŸŽ ๐Ÿ‘จโ€๐ŸŽจ ๐Ÿ˜‘ ๐Ÿ‘ท โžก, ๐ŸŒ ๐Ÿšฎ ๐Ÿ’ฐ ๐Ÿ”œ ๐Ÿ‘ท ๐ŸŒ– ๐ŸŒ ๐Ÿ‘จโ€๐ŸŽจ.
๐Ÿ‘ˆ ๐ŸŒŒ ๐Ÿ‘ค ๐Ÿ’ช ๐Ÿ”Ž ๐Ÿ† ๐ŸŒŒ ๐Ÿ“‰ ๐Ÿ“Ÿ โŽ ๐ŸŒ… ๐Ÿ’ช, โœ”๏ธ ๐Ÿ› ๏ธ ๐ŸŒ, ๐Ÿ†Ž &amp; โŒ โœ…, โ™’๏ธ.
๐ŸŒ ๐ŸŒŒ ๐Ÿ‘ˆ ๐Ÿšš ๐Ÿ† ๐Ÿ› ๏ธ ๐Ÿ’ก ๐ŸŒ ๐Ÿ‘ฉโ€๐Ÿ’ป.
## ๐Ÿ“„
โฎ๏ธ ๐Ÿ”ฌ ๐Ÿ“š ๐ŸŽ›, ๐Ÿ‘ค ๐Ÿ’ญ ๐Ÿ‘ˆ ๐Ÿ‘ค ๐Ÿ”œ โš™๏ธ <a href="https://pydantic-docs.helpmanual.io/" class="external-link" target="_blank">**Pydantic**</a> ๐Ÿšฎ ๐Ÿ“ˆ.
โคด๏ธ ๐Ÿ‘ค ๐Ÿ“‰ โšซ๏ธ, โš’ โšซ๏ธ ๐Ÿ• ๐Ÿ› ๏ธ โฎ๏ธ ๐ŸŽป ๐Ÿ”—, ๐Ÿ•โ€๐Ÿฆบ ๐ŸŽ ๐ŸŒŒ ๐Ÿ”ฌ โš› ๐Ÿ“„, &amp; ๐Ÿ“‰ ๐Ÿ‘จโ€๐ŸŽจ ๐Ÿ•โ€๐Ÿฆบ (๐Ÿ†Ž โœ…, โœ) โš“๏ธ ๐Ÿ”› ๐Ÿ’ฏ ๐Ÿ“š ๐Ÿ‘จโ€๐ŸŽจ.
โฎ๏ธ ๐Ÿ› ๏ธ, ๐Ÿ‘ค ๐Ÿ“‰ <a href="https://www.starlette.io/" class="external-link" target="_blank">**๐Ÿ’ƒ**</a>, ๐ŸŽ ๐Ÿ”‘ ๐Ÿ“„.
## ๐Ÿ› ๏ธ
๐Ÿ•ฐ ๐Ÿ‘ค โ–ถ๏ธ ๐Ÿ— **FastAPI** โšซ๏ธ, ๐Ÿ† ๐Ÿ– โช ๐Ÿฅ‰, ๐Ÿ”ง ๐Ÿ”ฌ, ๐Ÿ“„ &amp; ๐Ÿงฐ ๐Ÿ”œ, &amp; ๐Ÿ’ก ๐Ÿ”ƒ ๐Ÿฉ &amp; ๐Ÿ”ง ๐Ÿ†‘ &amp; ๐Ÿ‹.
## ๐Ÿ”ฎ
๐Ÿ‘‰ โ˜, โšซ๏ธ โช ๐Ÿ†‘ ๐Ÿ‘ˆ **FastAPI** โฎ๏ธ ๐Ÿšฎ ๐Ÿ’ญ โž– โš  ๐Ÿ“š ๐Ÿ‘ซ๐Ÿ‘ซ.
โšซ๏ธ ๐Ÿ’†โ€โ™‚ ๐Ÿ‘ ๐Ÿคญ โฎ๏ธ ๐ŸŽ› โ™ฃ ๐Ÿ“š โš™๏ธ ๐Ÿ’ผ ๐Ÿ‘.
๐Ÿ“š ๐Ÿ‘ฉโ€๐Ÿ’ป &amp; ๐Ÿ‰ โช ๐Ÿช€ ๐Ÿ”› **FastAPI** ๐Ÿ‘ซ ๐Ÿ— (๐Ÿ”Œ ๐Ÿ‘ค &amp; ๐Ÿ‘‡ ๐Ÿ‰).
โœ‹๏ธ, ๐Ÿ“ค ๐Ÿ“š ๐Ÿ“ˆ &amp; โš’ ๐Ÿ‘Ÿ.
**FastAPI** โœ”๏ธ ๐Ÿ‘‘ ๐Ÿ”ฎ โคด๏ธ.
&amp; [๐Ÿ‘† โ„น](help-fastapi.md){.internal-link target=_blank} ๐Ÿ“‰ ๐Ÿ‘.

469
docs/em/docs/index.md

@ -0,0 +1,469 @@
<p align="center">
<a href="https://fastapi.tiangolo.com"><img src="https://fastapi.tiangolo.com/img/logo-margin/logo-teal.png" alt="FastAPI"></a>
</p>
<p align="center">
<em>FastAPI ๐Ÿ› ๏ธ, โ†• ๐ŸŽญ, โฉ ๐Ÿ’ก, โฉ ๐Ÿ“Ÿ, ๐Ÿ”œ ๐Ÿญ</em>
</p>
<p align="center">
<a href="https://github.com/tiangolo/fastapi/actions?query=workflow%3ATest+event%3Apush+branch%3Amaster" target="_blank">
<img src="https://github.com/tiangolo/fastapi/workflows/Test/badge.svg?event=push&branch=master" alt="Test">
</a>
<a href="https://coverage-badge.samuelcolvin.workers.dev/redirect/tiangolo/fastapi" target="_blank">
<img src="https://coverage-badge.samuelcolvin.workers.dev/tiangolo/fastapi.svg" alt="Coverage">
</a>
<a href="https://pypi.org/project/fastapi" target="_blank">
<img src="https://img.shields.io/pypi/v/fastapi?color=%2334D058&label=pypi%20package" alt="Package version">
</a>
<a href="https://pypi.org/project/fastapi" target="_blank">
<img src="https://img.shields.io/pypi/pyversions/fastapi.svg?color=%2334D058" alt="Supported Python versions">
</a>
</p>
---
**๐Ÿงพ**: <a href="https://fastapi.tiangolo.com" target="_blank">https://fastapi.tiangolo.com</a>
**โ„น ๐Ÿ“Ÿ**: <a href="https://github.com/tiangolo/fastapi" target="_blank">https://github.com/tiangolo/fastapi</a>
---
FastAPI ๐Ÿ›, โฉ (โ†•-๐ŸŽญ), ๐Ÿ•ธ ๐Ÿ› ๏ธ ๐Ÿ— ๐Ÿ› ๏ธ โฎ๏ธ ๐Ÿ 3๏ธโƒฃ.7๏ธโƒฃ โž• โš“๏ธ ๐Ÿ”› ๐Ÿฉ ๐Ÿ ๐Ÿ†Ž ๐Ÿ”‘.
๐Ÿ”‘ โš’:
* **โฉ**: ๐Ÿ“ถ โ†• ๐ŸŽญ, ๐Ÿ”› ๐Ÿ‡ท๐Ÿ‡ช โฎ๏ธ **โœณ** &amp; **๐Ÿšถ** (๐Ÿ‘ ๐Ÿ’ƒ &amp; Pydantic). [1๏ธโƒฃ โฉ ๐Ÿ ๐Ÿ› ๏ธ ๐Ÿ’ช](#performance).
* **โฉ ๐Ÿ“Ÿ**: ๐Ÿ“ˆ ๐Ÿš… ๐Ÿ› ๏ธ โš’ ๐Ÿ”ƒ 2๏ธโƒฃ0๏ธโƒฃ0๏ธโƒฃ ๐Ÿ’ฏ 3๏ธโƒฃ0๏ธโƒฃ0๏ธโƒฃ ๐Ÿ’ฏ. *
* **๐Ÿ‘ฉโ€โคโ€๐Ÿ‘จ ๐Ÿ›**: ๐Ÿ“‰ ๐Ÿ”ƒ 4๏ธโƒฃ0๏ธโƒฃ ๐Ÿ’ฏ ๐Ÿ—ฟ (๐Ÿ‘ฉโ€๐Ÿ’ป) ๐Ÿ“‰ โŒ. *
* **๐Ÿ‹๏ธ**: ๐Ÿ‘‘ ๐Ÿ‘จโ€๐ŸŽจ ๐Ÿ•โ€๐Ÿฆบ. <abbr title="also known as auto-complete, autocompletion, IntelliSense">๐Ÿ› ๏ธ</abbr> ๐ŸŒ. ๐ŸŒ˜ ๐Ÿ•ฐ ๐Ÿ› ๏ธ.
* **โฉ**: ๐Ÿ”ง โฉ โš™๏ธ &amp; ๐Ÿ’ก. ๐ŸŒ˜ ๐Ÿ•ฐ ๐Ÿ‘‚ ๐Ÿฉบ.
* **๐Ÿ“**: ๐Ÿ“‰ ๐Ÿ“Ÿ โŽ. ๐Ÿ’— โš’ โšช๏ธโžก๏ธ ๐Ÿ”  ๐Ÿ”ข ๐Ÿ“„. ๐Ÿ‘ฉโ€โคโ€๐Ÿ‘จ ๐Ÿ›.
* **๐Ÿ‹๏ธ**: ๐Ÿคš ๐Ÿญ-๐Ÿ”œ ๐Ÿ“Ÿ. โฎ๏ธ ๐Ÿง ๐ŸŽ“ ๐Ÿงพ.
* **๐Ÿฉ-โš“๏ธ**: โš“๏ธ ๐Ÿ”› (&amp; ๐Ÿ• ๐Ÿ”— โฎ๏ธ) ๐Ÿ“‚ ๐Ÿฉ ๐Ÿ”—: <a href="https://github.com/OAI/OpenAPI-Specification" class="external-link" target="_blank">๐Ÿ—„</a> (โช ๐Ÿ’ญ ๐Ÿฆ) &amp; <a href="https://json-schema.org/" class="external-link" target="_blank">๐ŸŽป ๐Ÿ”—</a>.
<small>* โš– โš“๏ธ ๐Ÿ”› ๐Ÿ’ฏ ๐Ÿ”› ๐Ÿ”— ๐Ÿ› ๏ธ ๐Ÿ‰, ๐Ÿ— ๐Ÿญ ๐Ÿˆธ.</small>
## ๐Ÿ’ฐ
<!-- sponsors -->
{% if sponsors %}
{% for sponsor in sponsors.gold -%}
<a href="{{ sponsor.url }}" target="_blank" title="{{ sponsor.title }}"><img src="{{ sponsor.img }}" style="border-radius:15px"></a>
{% endfor -%}
{%- for sponsor in sponsors.silver -%}
<a href="{{ sponsor.url }}" target="_blank" title="{{ sponsor.title }}"><img src="{{ sponsor.img }}" style="border-radius:15px"></a>
{% endfor %}
{% endif %}
<!-- /sponsors -->
<a href="https://fastapi.tiangolo.com/fastapi-people/#sponsors" class="external-link" target="_blank">๐ŸŽ ๐Ÿ’ฐ</a>
## ๐Ÿค”
"_[...] ๐Ÿ‘ค โš™๏ธ **FastAPI** ๐Ÿ“š ๐Ÿ‘ซ ๐Ÿ“†. [...] ๐Ÿ‘ค ๐Ÿค™ ๐Ÿ“† โš™๏ธ โšซ๏ธ ๐ŸŒ ๐Ÿ‘‡ ๐Ÿ‰ **โš— ๐Ÿ•โ€๐Ÿฆบ ๐Ÿคธโ€โ™‚**. ๐Ÿ‘ซ ๐Ÿ’†โ€โ™‚ ๐Ÿ› ๏ธ ๐Ÿ”˜ ๐Ÿš **๐Ÿ–ฅ** ๐Ÿฌ &amp; **๐Ÿ“ ** ๐Ÿฌ._"
<div style="text-align: right; margin-right: 10%;">๐Ÿงฟ ๐Ÿ‡ต๐Ÿ‡ฐ - <strong>๐Ÿคธโ€โ™‚</strong> <a href="https://github.com/tiangolo/fastapi/pull/26" target="_blank"><small>(๐Ÿ‡ฆ๐Ÿ‡ช)</small></a></div>
---
"_๐Ÿ‘ฅ ๐Ÿ› ๏ธ **FastAPI** ๐Ÿ—ƒ ๐Ÿค– **๐ŸŽ‚** ๐Ÿ’ฝ ๐Ÿ‘ˆ ๐Ÿ’ช ๐Ÿ”ข ๐Ÿšš **๐Ÿ”ฎ**. [๐Ÿ‘จ๐Ÿ“›]_"
<div style="text-align: right; margin-right: 10%;">๐Ÿ‡ฎ๐Ÿ‡น ๐Ÿ‡ธ๐Ÿ‡ป, ๐Ÿ‘จ๐Ÿ“› ๐Ÿ‘จ๐Ÿ“›, &amp; ๐Ÿ‡ฑ๐Ÿ‡ฐ ๐Ÿ•‰ ๐Ÿ•‰ - <strong>๐Ÿ™ƒ</strong> <a href="https://eng.uber.com/ludwig-v0-2/" target="_blank"><small>(๐Ÿ‡ฆ๐Ÿ‡ช)</small></a></div>
---
"_**๐Ÿ“บ** ๐Ÿ™ ๐Ÿ“ฃ ๐Ÿ“‚-โ„น ๐Ÿš€ ๐Ÿ‘† **โš” ๐Ÿงพ** ๐ŸŽถ ๐Ÿ› ๏ธ: **๐Ÿ“จ**โ— [๐Ÿ— โฎ๏ธ **FastAPI**]_"
<div style="text-align: right; margin-right: 10%;">โœก ๐Ÿ, ๐Ÿ‘– ๐Ÿ‡ช๐Ÿ‡ธ, ๐ŸŒฒ ๐Ÿ - <strong>๐Ÿ“บ</strong> <a href="https://netflixtechblog.com/introducing-dispatch-da4b8a2a8072" target="_blank"><small>(๐Ÿ‡ฆ๐Ÿ‡ช)</small></a></div>
---
"_๐Ÿ‘ค ๐Ÿคญ ๐ŸŒ• ๐Ÿ˜„ ๐Ÿ”ƒ **FastAPI**. โšซ๏ธ ๐ŸŽŠ โ—_"
<div style="text-align: right; margin-right: 10%;">โœก ๐Ÿ‡ญ๐Ÿ‡ฐ - <strong><a href="https://pythonbytes.fm/episodes/show/123/time-to-right-the-py-wrongs?time_in_sec=855" target="_blank">๐Ÿ ๐Ÿ”ข</a> ๐Ÿ“ป ๐Ÿฆ </strong> <a href="https://twitter.com/brianokken/status/1112220079972728832" target="_blank"><small>(๐Ÿ‡ฆ๐Ÿ‡ช)</small></a></div>
---
"_๐Ÿค™, โšซ๏ธโ” ๐Ÿ‘† โœ”๏ธ ๐Ÿ— ๐Ÿ‘€ ๐Ÿ’Ž ๐Ÿ’  &amp; ๐Ÿ‡ต๐Ÿ‡ฑ. ๐Ÿ“š ๐ŸŒŒ, โšซ๏ธ โšซ๏ธโ” ๐Ÿ‘ค ๐Ÿ’š **๐Ÿค—** - โšซ๏ธ ๐Ÿค™ ๐Ÿ˜ ๐Ÿ‘€ ๐Ÿ‘ฑ ๐Ÿ— ๐Ÿ‘ˆ._"
<div style="text-align: right; margin-right: 10%;">โœก ๐Ÿ—„ - <strong><a href="https://www.hug.rest/" target="_blank">๐Ÿค—</a> ๐Ÿ‘ผ</strong> <a href="https://news.ycombinator.com/item?id=19455465" target="_blank"><small>(๐Ÿ‡ฆ๐Ÿ‡ช)</small></a></div>
---
"_๐Ÿšฅ ๐Ÿ‘† ๐Ÿ‘€ ๐Ÿ’ก 1๏ธโƒฃ **๐Ÿ› ๐Ÿ› ๏ธ** ๐Ÿ— ๐ŸŽ‚ ๐Ÿ”—, โœ… ๐Ÿ‘… **FastAPI** [...] โšซ๏ธ โฉ, โฉ โš™๏ธ &amp; โฉ ๐Ÿ’ก [...]_"
"_๐Ÿ‘ฅ โœ”๏ธ ๐ŸŽ› ๐Ÿคญ **FastAPI** ๐Ÿ‘† **๐Ÿ”—** [...] ๐Ÿ‘ค ๐Ÿ’ญ ๐Ÿ‘† ๐Ÿ”œ ๐Ÿ’– โšซ๏ธ [...]_"
<div style="text-align: right; margin-right: 10%;">๐Ÿ‡ฑ๐Ÿ‡จ ๐Ÿ‡ธ๐Ÿ‡ฒ - โœก Honnibal - <strong><a href="https://explosion.ai" target="_blank">๐Ÿ’ฅ ๐Ÿ‘ฒ</a> ๐Ÿ•ด - <a href="https://spacy.io" target="_blank">๐ŸŒˆ</a> ๐Ÿ‘ผ</strong> <a href="https://twitter.com/_inesmontani/status/1144173225322143744" target="_blank"><small>(๐Ÿ‡ฆ๐Ÿ‡ช)</small></a> - <a href="https://twitter.com/honnibal/status/1144031421859655680" target="_blank"><small>(๐Ÿ‡ฆ๐Ÿ‡ช)</small></a></div>
---
"_๐Ÿšฅ ๐Ÿ™† ๐Ÿ‘€ ๐Ÿ— ๐Ÿญ ๐Ÿ ๐Ÿ› ๏ธ, ๐Ÿ‘ค ๐Ÿ”œ ๐Ÿ† ๐Ÿ‘ **FastAPI**. โšซ๏ธ **๐Ÿ’Ž ๐Ÿ—**, **๐Ÿ™… โš™๏ธ** &amp; **๐Ÿ† ๐Ÿ› ๏ธ**, โšซ๏ธ โœ”๏ธ โ–ถ๏ธ๏ธ **๐Ÿ”‘ ๐Ÿฆฒ** ๐Ÿ‘† ๐Ÿ› ๏ธ ๐Ÿฅ‡ ๐Ÿ› ๏ธ ๐ŸŽ› &amp; ๐Ÿš˜ ๐Ÿ“š ๐Ÿง &amp; ๐Ÿ•โ€๐Ÿฆบ โœ… ๐Ÿ‘† ๐Ÿ•น ๐Ÿ”ซ ๐Ÿ‘จโ€๐Ÿ’ป._"
<div style="text-align: right; margin-right: 10%;">๐Ÿ‡น๐Ÿ‡ฆ ๐Ÿฐ - <strong>๐Ÿ“ป</strong> <a href="https://www.linkedin.com/posts/deonpillsbury_cisco-cx-python-activity-6963242628536487936-trAp/" target="_blank"><small>(๐Ÿ‡ฆ๐Ÿ‡ช)</small></a></div>
---
## **๐ŸŽ**, FastAPI ๐Ÿ‡ณ๐Ÿ‡จ
<a href="https://typer.tiangolo.com" target="_blank"><img src="https://typer.tiangolo.com/img/logo-margin/logo-margin-vector.svg" style="width: 20%;"></a>
๐Ÿšฅ ๐Ÿ‘† ๐Ÿ— <abbr title="Command Line Interface">โœณ</abbr> ๐Ÿ“ฑ โš™๏ธ ๐Ÿ“ถ โ†ฉ๏ธ ๐Ÿ•ธ ๐Ÿ› ๏ธ, โœ… ๐Ÿ‘… <a href="https://typer.tiangolo.com/" class="external-link" target="_blank">**๐ŸŽ**</a>.
**๐ŸŽ** FastAPI ๐Ÿฅ ๐Ÿ‘ช. &amp; โšซ๏ธ ๐ŸŽฏ **FastAPI ๐Ÿ‡ณ๐Ÿ‡จ**. ๐Ÿ‘ถ ๐Ÿ‘ถ ๐Ÿ‘ถ
## ๐Ÿ“„
๐Ÿ 3๏ธโƒฃ.7๏ธโƒฃ โž•
FastAPI ๐Ÿง ๐Ÿ”› โŒš ๐Ÿ˜:
* <a href="https://www.starlette.io/" class="external-link" target="_blank">๐Ÿ’ƒ</a> ๐Ÿ•ธ ๐Ÿ•.
* <a href="https://pydantic-docs.helpmanual.io/" class="external-link" target="_blank">Pydantic</a> ๐Ÿ“Š ๐Ÿ•.
## ๐Ÿ‘ทโ€โ™‚
<div class="termy">
```console
$ pip install fastapi
---> 100%
```
</div>
๐Ÿ‘† ๐Ÿ”œ ๐Ÿ’ช ๐Ÿ”ซ ๐Ÿ’ฝ, ๐Ÿญ โœ… <a href="https://www.uvicorn.org" class="external-link" target="_blank">Uvicorn</a> โš–๏ธ <a href="https://github.com/pgjones/hypercorn" class="external-link" target="_blank">Hypercorn</a>.
<div class="termy">
```console
$ pip install "uvicorn[standard]"
---> 100%
```
</div>
## ๐Ÿ–ผ
### โœ โšซ๏ธ
* โœ ๐Ÿ“ `main.py` โฎ๏ธ:
```Python
from typing import Union
from fastapi import FastAPI
app = FastAPI()
@app.get("/")
def read_root():
return {"Hello": "World"}
@app.get("/items/{item_id}")
def read_item(item_id: int, q: Union[str, None] = None):
return {"item_id": item_id, "q": q}
```
<details markdown="1">
<summary>โš–๏ธ โš™๏ธ <code>async def</code>...</summary>
๐Ÿšฅ ๐Ÿ‘† ๐Ÿ“Ÿ โš™๏ธ `async` / `await`, โš™๏ธ `async def`:
```Python hl_lines="9 14"
from typing import Union
from fastapi import FastAPI
app = FastAPI()
@app.get("/")
async def read_root():
return {"Hello": "World"}
@app.get("/items/{item_id}")
async def read_item(item_id: int, q: Union[str, None] = None):
return {"item_id": item_id, "q": q}
```
**๐Ÿ—’**:
๐Ÿšฅ ๐Ÿ‘† ๐Ÿšซ ๐Ÿ’ญ, โœ… _"๐Ÿƒ โ“" _ ๐Ÿ“„ ๐Ÿ”ƒ <a href="https://fastapi.tiangolo.com/async/#in-a-hurry" target="_blank">`async` &amp; `await` ๐Ÿฉบ</a>.
</details>
### ๐Ÿƒ โšซ๏ธ
๐Ÿƒ ๐Ÿ’ฝ โฎ๏ธ:
<div class="termy">
```console
$ uvicorn main:app --reload
INFO: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
INFO: Started reloader process [28720]
INFO: Started server process [28722]
INFO: Waiting for application startup.
INFO: Application startup complete.
```
</div>
<details markdown="1">
<summary>๐Ÿ”ƒ ๐Ÿ“‹ <code>uvicorn main:app --reload</code>...</summary>
๐Ÿ“‹ `uvicorn main:app` ๐Ÿ”—:
* `main`: ๐Ÿ“ `main.py` (๐Ÿ "๐Ÿ•น").
* `app`: ๐ŸŽš โœ ๐Ÿ”˜ `main.py` โฎ๏ธ โธ `app = FastAPI()`.
* `--reload`: โš’ ๐Ÿ’ฝ โ โฎ๏ธ ๐Ÿ“Ÿ ๐Ÿ”€. ๐Ÿ•ด ๐Ÿ‘‰ ๐Ÿ› ๏ธ.
</details>
### โœ… โšซ๏ธ
๐Ÿ“‚ ๐Ÿ‘† ๐Ÿ–ฅ <a href="http://127.0.0.1:8000/items/5?q=somequery" class="external-link" target="_blank">http://127.0.0.1:8000/items/5?q=somequery</a>.
๐Ÿ‘† ๐Ÿ”œ ๐Ÿ‘€ ๐ŸŽป ๐Ÿ“จ:
```JSON
{"item_id": 5, "q": "somequery"}
```
๐Ÿ‘† โช โœ ๐Ÿ› ๏ธ ๐Ÿ‘ˆ:
* ๐Ÿ“จ ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ” ๐Ÿ“จ _โžก_ `/` &amp; `/items/{item_id}`.
* ๐Ÿ‘ฏโ€โ™‚๏ธ _โžก_ โœŠ `GET` <em>๐Ÿ› ๏ธ</em> (๐Ÿ’ญ ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ” _๐Ÿ‘ฉโ€๐Ÿ”ฌ_).
* _โžก_ `/items/{item_id}` โœ”๏ธ _โžก ๐Ÿ”ข_ `item_id` ๐Ÿ‘ˆ ๐Ÿ”œ `int`.
* _โžก_ `/items/{item_id}` โœ”๏ธ ๐Ÿ“ฆ `str` _๐Ÿ”ข = `q`.
### ๐ŸŽ“ ๐Ÿ› ๏ธ ๐Ÿฉบ
๐Ÿ”œ ๐Ÿšถ <a href="http://127.0.0.1:8000/docs" class="external-link" target="_blank">http://127.0.0.1:8000/docs</a>.
๐Ÿ‘† ๐Ÿ”œ ๐Ÿ‘€ ๐Ÿง ๐ŸŽ“ ๐Ÿ› ๏ธ ๐Ÿงพ (๐Ÿšš <a href="https://github.com/swagger-api/swagger-ui" class="external-link" target="_blank">๐Ÿฆ ๐ŸŽš</a>):
![Swagger UI](https://fastapi.tiangolo.com/img/index/index-01-swagger-ui-simple.png)
### ๐ŸŽ› ๐Ÿ› ๏ธ ๐Ÿฉบ
&amp; ๐Ÿ”œ, ๐Ÿšถ <a href="http://127.0.0.1:8000/redoc" class="external-link" target="_blank">http://127.0.0.1:8000/redoc</a>.
๐Ÿ‘† ๐Ÿ”œ ๐Ÿ‘€ ๐ŸŽ› ๐Ÿง ๐Ÿงพ (๐Ÿšš <a href="https://github.com/Rebilly/ReDoc" class="external-link" target="_blank">๐Ÿ“„</a>):
![ReDoc](https://fastapi.tiangolo.com/img/index/index-02-redoc-simple.png)
## ๐Ÿ–ผ โ™ป
๐Ÿ”œ ๐Ÿ”€ ๐Ÿ“ `main.py` ๐Ÿ“จ ๐Ÿ’ช โšช๏ธโžก๏ธ `PUT` ๐Ÿ“จ.
๐Ÿ“ฃ ๐Ÿ’ช โš™๏ธ ๐Ÿฉ ๐Ÿ ๐Ÿ†Ž, ๐Ÿ‘ Pydantic.
```Python hl_lines="4 9-12 25-27"
from typing import Union
from fastapi import FastAPI
from pydantic import BaseModel
app = FastAPI()
class Item(BaseModel):
name: str
price: float
is_offer: Union[bool, None] = None
@app.get("/")
def read_root():
return {"Hello": "World"}
@app.get("/items/{item_id}")
def read_item(item_id: int, q: Union[str, None] = None):
return {"item_id": item_id, "q": q}
@app.put("/items/{item_id}")
def update_item(item_id: int, item: Item):
return {"item_name": item.name, "item_id": item_id}
```
๐Ÿ’ฝ ๐Ÿ”œ ๐Ÿ”ƒ ๐Ÿ” (โ†ฉ๏ธ ๐Ÿ‘† ๐Ÿšฎ `--reload` `uvicorn` ๐Ÿ“‹ ๐Ÿ”›).
### ๐ŸŽ“ ๐Ÿ› ๏ธ ๐Ÿฉบ โ™ป
๐Ÿ”œ ๐Ÿšถ <a href="http://127.0.0.1:8000/docs" class="external-link" target="_blank">http://127.0.0.1:8000/docs</a>.
* ๐ŸŽ“ ๐Ÿ› ๏ธ ๐Ÿงพ ๐Ÿ”œ ๐Ÿ” โ„น, ๐Ÿ”Œ ๐Ÿ†• ๐Ÿ’ช:
![Swagger UI](https://fastapi.tiangolo.com/img/index/index-03-swagger-02.png)
* ๐Ÿ–Š ๐Ÿ”› ๐Ÿ”ผ "๐Ÿ”„ โšซ๏ธ ๐Ÿ‘…", โšซ๏ธ โœ” ๐Ÿ‘† ๐Ÿฅง ๐Ÿ”ข &amp; ๐Ÿ”— ๐Ÿ”— โฎ๏ธ ๐Ÿ› ๏ธ:
![Swagger UI interaction](https://fastapi.tiangolo.com/img/index/index-04-swagger-03.png)
* โคด๏ธ ๐Ÿ–Š ๐Ÿ”› "๐Ÿ› ๏ธ" ๐Ÿ”ผ, ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ”ข ๐Ÿ”œ ๐Ÿ”— โฎ๏ธ ๐Ÿ‘† ๐Ÿ› ๏ธ, ๐Ÿ“จ ๐Ÿ”ข, ๐Ÿคš ๐Ÿ &amp; ๐ŸŽฆ ๐Ÿ‘ซ ๐Ÿ”› ๐Ÿ–ฅ:
![Swagger UI interaction](https://fastapi.tiangolo.com/img/index/index-05-swagger-04.png)
### ๐ŸŽ› ๐Ÿ› ๏ธ ๐Ÿฉบ โ™ป
&amp; ๐Ÿ”œ, ๐Ÿšถ <a href="http://127.0.0.1:8000/redoc" class="external-link" target="_blank">http://127.0.0.1:8000/redoc</a>.
* ๐ŸŽ› ๐Ÿงพ ๐Ÿ”œ ๐ŸŽจ ๐Ÿ†• ๐Ÿ”ข ๐Ÿ”ข &amp; ๐Ÿ’ช:
![ReDoc](https://fastapi.tiangolo.com/img/index/index-06-redoc-02.png)
### ๐ŸŒƒ
๐Ÿ“„, ๐Ÿ‘† ๐Ÿ“ฃ **๐Ÿ•** ๐Ÿ†Ž ๐Ÿ”ข, ๐Ÿ’ช, โ™’๏ธ. ๐Ÿ”ข ๐Ÿ”ข.
๐Ÿ‘† ๐Ÿ‘ˆ โฎ๏ธ ๐Ÿฉ ๐Ÿ› ๐Ÿ ๐Ÿ†Ž.
๐Ÿ‘† ๐Ÿšซ โœ”๏ธ ๐Ÿ’ก ๐Ÿ†• โ•, ๐Ÿ‘ฉโ€๐Ÿ”ฌ โš–๏ธ ๐ŸŽ“ ๐ŸŽฏ ๐Ÿ—ƒ, โ™’๏ธ.
๐Ÿฉ **๐Ÿ 3๏ธโƒฃ.7๏ธโƒฃ โž•**.
๐Ÿ–ผ, `int`:
```Python
item_id: int
```
โš–๏ธ ๐ŸŒ– ๐Ÿ— `Item` ๐Ÿท:
```Python
item: Item
```
...&amp; โฎ๏ธ ๐Ÿ‘ˆ ๐Ÿ‘ ๐Ÿ“„ ๐Ÿ‘† ๐Ÿคš:
* ๐Ÿ‘จโ€๐ŸŽจ ๐Ÿ•โ€๐Ÿฆบ, ๐Ÿ”Œ:
* ๐Ÿ› ๏ธ.
* ๐Ÿ†Ž โœ….
* ๐Ÿ”ฌ ๐Ÿ’ฝ:
* ๐Ÿง &amp; ๐Ÿ†‘ โŒ ๐Ÿ•โ” ๐Ÿ“Š โŒ.
* ๐Ÿ”ฌ ๐Ÿ™‡ ๐Ÿฆ ๐ŸŽป ๐ŸŽš.
* <abbr title="also known as: serialization, parsing, marshalling">๐Ÿ› ๏ธ</abbr> ๐Ÿ”ข ๐Ÿ’ฝ: ๐Ÿ‘Ÿ โšช๏ธโžก๏ธ ๐Ÿ•ธ ๐Ÿ ๐Ÿ’ฝ &amp; ๐Ÿ†Ž. ๐Ÿ‘‚ โšช๏ธโžก๏ธ:
* ๐ŸŽป.
* โžก ๐Ÿ”ข.
* ๐Ÿ”ข ๐Ÿ”ข.
* ๐Ÿช.
* ๐ŸŽš.
* ๐Ÿ“จ.
* ๐Ÿ“.
* <abbr title="also known as: serialization, parsing, marshalling">๐Ÿ› ๏ธ</abbr> ๐Ÿ”ข ๐Ÿ“Š: ๐Ÿ—œ โšช๏ธโžก๏ธ ๐Ÿ ๐Ÿ’ฝ &amp; ๐Ÿ†Ž ๐Ÿ•ธ ๐Ÿ’ฝ (๐ŸŽป):
* ๐Ÿ—œ ๐Ÿ ๐Ÿ†Ž (`str`, `int`, `float`, `bool`, `list`, โ™’๏ธ).
* `datetime` ๐ŸŽš.
* `UUID` ๐ŸŽš.
* ๐Ÿ’ฝ ๐Ÿท.
* ...&amp; ๐Ÿ“š ๐ŸŒ–.
* ๐Ÿง ๐ŸŽ“ ๐Ÿ› ๏ธ ๐Ÿงพ, ๐Ÿ”Œ 2๏ธโƒฃ ๐ŸŽ› ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ”ข:
* ๐Ÿฆ ๐ŸŽš.
* ๐Ÿ“„.
---
๐Ÿ‘Ÿ ๐Ÿ”™ โฎ๏ธ ๐Ÿ“Ÿ ๐Ÿ–ผ, **FastAPI** ๐Ÿ”œ:
* โœ” ๐Ÿ‘ˆ ๐Ÿ“ค `item_id` โžก `GET` &amp; `PUT` ๐Ÿ“จ.
* โœ” ๐Ÿ‘ˆ `item_id` ๐Ÿ†Ž `int` `GET` &amp; `PUT` ๐Ÿ“จ.
* ๐Ÿšฅ โšซ๏ธ ๐Ÿšซ, ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ”œ ๐Ÿ‘€ โš , ๐Ÿ†‘ โŒ.
* โœ… ๐Ÿšฅ ๐Ÿ“ค ๐Ÿ“ฆ ๐Ÿ”ข ๐Ÿ”ข ๐Ÿ“› `q` ( `http://127.0.0.1:8000/items/foo?q=somequery`) `GET` ๐Ÿ“จ.
* `q` ๐Ÿ”ข ๐Ÿ“ฃ โฎ๏ธ `= None`, โšซ๏ธ ๐Ÿ“ฆ.
* ๐Ÿต `None` โšซ๏ธ ๐Ÿ”œ ๐Ÿšš (๐Ÿ’ช ๐Ÿ’ผ โฎ๏ธ `PUT`).
* `PUT` ๐Ÿ“จ `/items/{item_id}`, โœ ๐Ÿ’ช ๐ŸŽป:
* โœ… ๐Ÿ‘ˆ โšซ๏ธ โœ”๏ธ โœ” ๐Ÿ”ข `name` ๐Ÿ‘ˆ ๐Ÿ”œ `str`.
* โœ… ๐Ÿ‘ˆ โšซ๏ธ โœ”๏ธ โœ” ๐Ÿ”ข `price` ๐Ÿ‘ˆ โœ”๏ธ `float`.
* โœ… ๐Ÿ‘ˆ โšซ๏ธ โœ”๏ธ ๐Ÿ“ฆ ๐Ÿ”ข `is_offer`, ๐Ÿ‘ˆ ๐Ÿ”œ `bool`, ๐Ÿšฅ ๐ŸŽ.
* ๐ŸŒ ๐Ÿ‘‰ ๐Ÿ”œ ๐Ÿ‘ท ๐Ÿ™‡ ๐Ÿฆ ๐ŸŽป ๐ŸŽš.
* ๐Ÿ—œ โšช๏ธโžก๏ธ &amp; ๐ŸŽป ๐Ÿ”.
* ๐Ÿ“„ ๐ŸŒ โฎ๏ธ ๐Ÿ—„, ๐Ÿ‘ˆ ๐Ÿ’ช โš™๏ธ:
* ๐ŸŽ“ ๐Ÿงพ โš™๏ธ.
* ๐Ÿง ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ“Ÿ โšก โš™๏ธ, ๐Ÿ“š ๐Ÿ‡ช๐Ÿ‡ธ.
* ๐Ÿšš 2๏ธโƒฃ ๐ŸŽ“ ๐Ÿงพ ๐Ÿ•ธ ๐Ÿ”ข ๐Ÿ”—.
---
๐Ÿ‘ฅ ๐Ÿ–Œ ๐Ÿงฝ, โœ‹๏ธ ๐Ÿ‘† โช ๐Ÿคš ๐Ÿ’ญ โ” โšซ๏ธ ๐ŸŒ ๐Ÿ‘ท.
๐Ÿ”„ ๐Ÿ”€ โธ โฎ๏ธ:
```Python
return {"item_name": item.name, "item_id": item_id}
```
...โšช๏ธโžก๏ธ:
```Python
... "item_name": item.name ...
```
...:
```Python
... "item_price": item.price ...
```
...&amp; ๐Ÿ‘€ โ” ๐Ÿ‘† ๐Ÿ‘จโ€๐ŸŽจ ๐Ÿ”œ ๐Ÿš˜-๐Ÿ ๐Ÿ”ข &amp; ๐Ÿ’ญ ๐Ÿ‘ซ ๐Ÿ†Ž:
![editor support](https://fastapi.tiangolo.com/img/vscode-completion.png)
๐ŸŒ… ๐Ÿ ๐Ÿ–ผ ๐Ÿ”Œ ๐ŸŒ… โš’, ๐Ÿ‘€ <a href="https://fastapi.tiangolo.com/tutorial/">๐Ÿ”ฐ - ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿฆฎ</a>.
**๐Ÿš˜ ๐Ÿšจ**: ๐Ÿ”ฐ - ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿฆฎ ๐Ÿ”Œ:
* ๐Ÿ“„ **๐Ÿ”ข** โšช๏ธโžก๏ธ ๐ŸŽ ๐ŸŽ ๐Ÿฅ‰: **๐ŸŽš**, **๐Ÿช**, **๐Ÿ“จ ๐Ÿ‘** &amp; **๐Ÿ“**.
* โ” โš’ **๐Ÿ”ฌ โš›** `maximum_length` โš–๏ธ `regex`.
* ๐Ÿ“ถ ๐Ÿ‹๏ธ &amp; โฉ โš™๏ธ **<abbr title="also known as components, resources, providers, services, injectables">๐Ÿ”— ๐Ÿ’‰</abbr>** โš™๏ธ.
* ๐Ÿ’‚โ€โ™‚ &amp; ๐Ÿค, โœ… ๐Ÿ•โ€๐Ÿฆบ **Oauth2๏ธโƒฃ** โฎ๏ธ **๐Ÿฅ™ ๐Ÿค** &amp; **๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ” ๐Ÿ”ฐ** ๐Ÿ”.
* ๐ŸŒ… ๐Ÿง (โœ‹๏ธ ๐Ÿ˜จ โฉ) โš’ ๐Ÿ“ฃ **๐Ÿ™‡ ๐Ÿฆ ๐ŸŽป ๐Ÿท** (๐Ÿ‘ Pydantic).
* **๐Ÿ•น** ๐Ÿ› ๏ธ โฎ๏ธ <a href="https://strawberry.rocks" class="external-link" target="_blank">๐Ÿ“</a> &amp; ๐ŸŽ ๐Ÿ—ƒ.
* ๐Ÿ“š โž• โš’ (๐Ÿ‘ ๐Ÿ’ƒ):
* ** *๏ธโƒฃ **
* ๐Ÿ“ถ โฉ ๐Ÿ’ฏ โš“๏ธ ๐Ÿ”› ๐Ÿ‡ธ๐Ÿ‡ฒ &amp; `pytest`
* **โšœ**
* **๐Ÿช ๐ŸŽ‰**
* ...&amp; ๐ŸŒ–.
## ๐ŸŽญ
๐Ÿ”ฌ ๐Ÿ‡ธ๐Ÿ‡ฒ ๐Ÿ“‡ ๐ŸŽฆ **FastAPI** ๐Ÿˆธ ๐Ÿƒโ€โ™‚ ๐Ÿ”ฝ Uvicorn <a href="https://www.techempower.com/benchmarks/#section=test&runid=7464e520-0dc2-473d-bd34-dbdfd7e85911&hw=ph&test=query&l=zijzen-7" class="external-link" target="_blank">1๏ธโƒฃ โฉ ๐Ÿ ๐Ÿ› ๏ธ ๐Ÿ’ช</a>, ๐Ÿ•ด ๐Ÿ”› ๐Ÿ’ƒ &amp; Uvicorn ๐Ÿ‘ซ (โš™๏ธ ๐Ÿ”˜ FastAPI). (*)
๐Ÿค” ๐ŸŒ– ๐Ÿ”ƒ โšซ๏ธ, ๐Ÿ‘€ ๐Ÿ“„ <a href="https://fastapi.tiangolo.com/benchmarks/" class="internal-link" target="_blank">๐Ÿ“‡</a>.
## ๐Ÿ“ฆ ๐Ÿ”—
โš™๏ธ Pydantic:
* <a href="https://github.com/esnme/ultrajson" target="_blank"><code>ujson</code></a> - โฉ ๐ŸŽป <abbr title="converting the string that comes from an HTTP request into Python data">"๐ŸŽป"</abbr>.
* <a href="https://github.com/JoshData/python-email-validator" target="_blank"><code>email_validator</code></a> - ๐Ÿ“ง ๐Ÿ”ฌ.
โš™๏ธ ๐Ÿ’ƒ:
* <a href="https://www.python-httpx.org" target="_blank"><code>httpx</code></a> - โœ” ๐Ÿšฅ ๐Ÿ‘† ๐Ÿ’š โš™๏ธ `TestClient`.
* <a href="https://jinja.palletsprojects.com" target="_blank"><code>jinja2</code></a> - โœ” ๐Ÿšฅ ๐Ÿ‘† ๐Ÿ’š โš™๏ธ ๐Ÿ”ข ๐Ÿ“„ ๐Ÿ“ณ.
* <a href="https://andrew-d.github.io/python-multipart/" target="_blank"><code>python-multipart</code></a> - โœ” ๐Ÿšฅ ๐Ÿ‘† ๐Ÿ’š ๐Ÿ•โ€๐Ÿฆบ ๐Ÿ“จ <abbr title="converting the string that comes from an HTTP request into Python data">"โœ"</abbr>, โฎ๏ธ `request.form()`.
* <a href="https://pythonhosted.org/itsdangerous/" target="_blank"><code>itsdangerous</code></a> - โœ” `SessionMiddleware` ๐Ÿ•โ€๐Ÿฆบ.
* <a href="https://pyyaml.org/wiki/PyYAMLDocumentation" target="_blank"><code>pyyaml</code></a> - โœ” ๐Ÿ’ƒ `SchemaGenerator` ๐Ÿ•โ€๐Ÿฆบ (๐Ÿ‘† ๐ŸŽฒ ๐Ÿšซ ๐Ÿ’ช โšซ๏ธ โฎ๏ธ FastAPI).
* <a href="https://github.com/esnme/ultrajson" target="_blank"><code>ujson</code></a> - โœ” ๐Ÿšฅ ๐Ÿ‘† ๐Ÿ’š โš™๏ธ `UJSONResponse`.
โš™๏ธ FastAPI / ๐Ÿ’ƒ:
* <a href="https://www.uvicorn.org" target="_blank"><code>uvicorn</code></a> - ๐Ÿ’ฝ ๐Ÿ‘ˆ ๐Ÿ“ &amp; ๐Ÿฆ ๐Ÿ‘† ๐Ÿˆธ.
* <a href="https://github.com/ijl/orjson" target="_blank"><code>orjson</code></a> - โœ” ๐Ÿšฅ ๐Ÿ‘† ๐Ÿ’š โš™๏ธ `ORJSONResponse`.
๐Ÿ‘† ๐Ÿ’ช โŽ ๐ŸŒ ๐Ÿ‘ซ โฎ๏ธ `pip install "fastapi[all]"`.
## ๐Ÿ›‚
๐Ÿ‘‰ ๐Ÿ— ยฎ ๐Ÿ”ฝ โš– ๐Ÿ‡ฉ๐Ÿ‡ช ๐Ÿ›‚.

84
docs/em/docs/project-generation.md

@ -0,0 +1,84 @@
# ๐Ÿ— โšก - ๐Ÿ“„
๐Ÿ‘† ๐Ÿ’ช โš™๏ธ ๐Ÿ— ๐Ÿš‚ ๐Ÿคš โ–ถ๏ธ, โšซ๏ธ ๐Ÿ”Œ ๐Ÿ“š โ–ถ๏ธ โš’ ๐Ÿ†™, ๐Ÿ’‚โ€โ™‚, ๐Ÿ’ฝ &amp; ๐Ÿ› ๏ธ ๐Ÿ”— โช โŒ› ๐Ÿ‘†.
๐Ÿ— ๐Ÿš‚ ๐Ÿ”œ ๐Ÿ•ง โœ”๏ธ ๐Ÿ“ถ ๐Ÿ™ƒ ๐Ÿ–ฅ ๐Ÿ‘ˆ ๐Ÿ‘† ๐Ÿ”œ โ„น &amp; ๐Ÿ› ๏ธ ๐Ÿ‘† ๐Ÿ‘ ๐Ÿ’ช, โœ‹๏ธ โšซ๏ธ ๐Ÿ’ช ๐Ÿ‘ โ–ถ๏ธ โ˜ ๐Ÿ‘† ๐Ÿ—.
## ๐ŸŒ• ๐Ÿ“š FastAPI โœณ
๐Ÿ“‚: <a href="https://github.com/tiangolo/full-stack-fastapi-postgresql" class="external-link" target="_blank">https://github.com/tiangolo/full-stack-fastapi-postgresql</a>
### ๐ŸŒ• ๐Ÿ“š FastAPI โœณ - โš’
* ๐ŸŒ• **โ˜** ๐Ÿ› ๏ธ (โ˜ ๐Ÿงข).
* โ˜ ๐Ÿ ๐Ÿ“ณ ๐Ÿ› ๏ธ.
* **โ˜ โœ** ๐Ÿ› ๏ธ &amp; ๐Ÿ› ๏ธ ๐Ÿ‡ง๐Ÿ‡ฟ ๐Ÿ› ๏ธ.
* **๐Ÿญ ๐Ÿ”œ** ๐Ÿ ๐Ÿ•ธ ๐Ÿ’ฝ โš™๏ธ Uvicorn &amp; ๐Ÿ.
* ๐Ÿ <a href="https://github.com/tiangolo/fastapi" class="external-link" target="_blank">**FastAPI**</a> ๐Ÿ‘ฉโ€๐Ÿ’ป:
* **โฉ**: ๐Ÿ“ถ โ†• ๐ŸŽญ, ๐Ÿ”› ๐Ÿ‡ท๐Ÿ‡ช โฎ๏ธ **โœณ** &amp; **๐Ÿšถ** (๐Ÿ‘ ๐Ÿ’ƒ &amp; Pydantic).
* **๐Ÿ‹๏ธ**: ๐Ÿ‘‘ ๐Ÿ‘จโ€๐ŸŽจ ๐Ÿ•โ€๐Ÿฆบ. <abbr title="also known as auto-complete, autocompletion, IntelliSense">๐Ÿ› ๏ธ</abbr> ๐ŸŒ. ๐ŸŒ˜ ๐Ÿ•ฐ ๐Ÿ› ๏ธ.
* **โฉ**: ๐Ÿ”ง โฉ โš™๏ธ &amp; ๐Ÿ’ก. ๐ŸŒ˜ ๐Ÿ•ฐ ๐Ÿ‘‚ ๐Ÿฉบ.
* **๐Ÿ“**: ๐Ÿ“‰ ๐Ÿ“Ÿ โŽ. ๐Ÿ’— โš’ โšช๏ธโžก๏ธ ๐Ÿ”  ๐Ÿ”ข ๐Ÿ“„.
* **๐Ÿ‹๏ธ**: ๐Ÿคš ๐Ÿญ-๐Ÿ”œ ๐Ÿ“Ÿ. โฎ๏ธ ๐Ÿง ๐ŸŽ“ ๐Ÿงพ.
* **๐Ÿฉ-โš“๏ธ**: โš“๏ธ ๐Ÿ”› (&amp; ๐Ÿ• ๐Ÿ”— โฎ๏ธ) ๐Ÿ“‚ ๐Ÿฉ ๐Ÿ”—: <a href="https://github.com/OAI/OpenAPI-Specification" class="external-link" target="_blank">๐Ÿ—„</a> &amp; <a href="https://json-schema.org/" class="external-link" target="_blank">๐ŸŽป ๐Ÿ”—</a>.
* <a href="https://fastapi.tiangolo.com/features/" class="external-link" target="_blank">**๐Ÿ“š ๐ŸŽ โš’**</a> ๐Ÿ”Œ ๐Ÿง ๐Ÿ”ฌ, ๐Ÿ› ๏ธ, ๐ŸŽ“ ๐Ÿงพ, ๐Ÿค โฎ๏ธ Oauth2๏ธโƒฃ ๐Ÿฅ™ ๐Ÿค, โ™’๏ธ.
* **๐Ÿ” ๐Ÿ”** ๐Ÿ” ๐Ÿ”ข.
* **๐Ÿฅ™ ๐Ÿค** ๐Ÿค.
* **๐Ÿ‡ธ๐Ÿ‡ฒ** ๐Ÿท (๐Ÿ”ฌ ๐Ÿบ โ†”, ๐Ÿ‘ซ ๐Ÿ’ช โš™๏ธ โฎ๏ธ ๐Ÿฅ’ ๐Ÿ‘จโ€๐Ÿญ ๐Ÿ”—).
* ๐Ÿ”ฐ โ–ถ๏ธ ๐Ÿท ๐Ÿ‘ฉโ€๐Ÿ’ป (๐Ÿ”€ &amp; โŽ ๐Ÿ‘† ๐Ÿ’ช).
* **โš—** ๐Ÿ› ๏ธ.
* **โšœ** (โœ–๏ธ ๐Ÿ‡จ๐Ÿ‡ณ โ„น ๐Ÿค).
* **๐Ÿฅ’** ๐Ÿ‘จโ€๐Ÿญ ๐Ÿ‘ˆ ๐Ÿ’ช ๐Ÿ—„ &amp; โš™๏ธ ๐Ÿท &amp; ๐Ÿ“Ÿ โšช๏ธโžก๏ธ ๐ŸŽ‚ ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ•.
* ๐ŸŽ‚ ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ’ฏ โš“๏ธ ๐Ÿ”› **โœณ**, ๐Ÿ› ๏ธ โฎ๏ธ โ˜, ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ’ฏ ๐ŸŒ• ๐Ÿ› ๏ธ ๐Ÿ”—, ๐Ÿ”ฌ ๐Ÿ”› ๐Ÿ’ฝ. โšซ๏ธ ๐Ÿƒ โ˜, โšซ๏ธ ๐Ÿ’ช ๐Ÿ— ๐Ÿ†• ๐Ÿ’ฝ ๐Ÿช โšช๏ธโžก๏ธ ๐Ÿ–Œ ๐Ÿ”  ๐Ÿ•ฐ (๐Ÿ‘† ๐Ÿ’ช โš™๏ธ โœณ, โœณ, โœณ, โš–๏ธ โšซ๏ธโ” ๐Ÿ‘† ๐Ÿ’š, &amp; ๐Ÿ’ฏ ๐Ÿ‘ˆ ๐Ÿ› ๏ธ ๐Ÿ‘ท).
* โฉ ๐Ÿ ๐Ÿ› ๏ธ โฎ๏ธ **๐Ÿ“‚ ๐Ÿ’พ** ๐Ÿ›ฐ โš–๏ธ-โ˜ ๐Ÿ› ๏ธ โฎ๏ธ โ†” ๐Ÿ’– โš› โš— โš–๏ธ ๐ŸŽ™ ๐ŸŽ™ ๐Ÿ“Ÿ ๐Ÿ“‚.
* **๐ŸŽฆ** ๐Ÿ•ธ:
* ๐Ÿ— โฎ๏ธ ๐ŸŽฆ โœณ.
* **๐Ÿฅ™ ๐Ÿค** ๐Ÿšš.
* ๐Ÿ’ณ ๐ŸŽ‘.
* โฎ๏ธ ๐Ÿ’ณ, ๐Ÿ‘‘ ๐Ÿ•น ๐ŸŽ‘.
* ๐Ÿ‘‘ ๐Ÿ•น โฎ๏ธ ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ— &amp; ๐Ÿ“•.
* ๐Ÿ‘ค ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ“•.
* **๐Ÿ‡ท๐Ÿ‡ช**.
* **๐ŸŽฆ-๐Ÿ“ป**.
* **Vuetify** ๐ŸŒน ๐Ÿงฝ ๐Ÿ”ง ๐Ÿฆฒ.
* **๐Ÿ“•**.
* โ˜ ๐Ÿ’ฝ โš“๏ธ ๐Ÿ”› **๐Ÿ‘Œ** (๐Ÿ“ถ ๐Ÿคพ ๐ŸŽ† โฎ๏ธ ๐ŸŽฆ-๐Ÿ“ป).
* โ˜ ๐Ÿ‘-โ–ถ๏ธ ๐Ÿ—, ๐Ÿ‘† ๐Ÿšซ ๐Ÿ’ช ๐Ÿ–Š โš–๏ธ ๐Ÿ’• โœ ๐Ÿ“Ÿ.
* ๐Ÿ•ธ ๐Ÿ’ฏ ๐Ÿƒ ๐Ÿ— ๐Ÿ•ฐ (๐Ÿ’ช ๐Ÿ”• ๐Ÿ’โ€โ™‚๏ธ).
* โš’ ๐Ÿ”ง ๐Ÿ’ช, โšซ๏ธ ๐Ÿ‘ท ๐Ÿ‘… ๐Ÿ“ฆ, โœ‹๏ธ ๐Ÿ‘† ๐Ÿ’ช ๐Ÿค-๐Ÿ— โฎ๏ธ ๐ŸŽฆ โœณ โš–๏ธ โœ โšซ๏ธ ๐Ÿ‘† ๐Ÿ’ช, &amp; ๐Ÿค-โš™๏ธ โšซ๏ธโ” ๐Ÿ‘† ๐Ÿ’š.
* ** *๏ธโƒฃ ** โœณ ๐Ÿ’ฝ, ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ”€ โšซ๏ธ โš™๏ธ ๐Ÿ“ &amp; โœณ ๐Ÿ’ช.
* **๐Ÿฅ€** ๐Ÿฅ’ ๐Ÿ‘จโ€๐Ÿญ โš–.
* ๐Ÿ“ โš– ๐Ÿ–– ๐Ÿ•ธ &amp; ๐Ÿ‘ฉโ€๐Ÿ’ป โฎ๏ธ **Traefik**, ๐Ÿ‘† ๐Ÿ’ช โœ”๏ธ ๐Ÿ‘ฏโ€โ™‚๏ธ ๐Ÿ”ฝ ๐ŸŽ ๐Ÿ†”, ๐Ÿ‘ฝ โžก, โœ‹๏ธ ๐Ÿฆ ๐ŸŽ ๐Ÿ“ฆ.
* Traefik ๐Ÿ› ๏ธ, โœ… โžก๏ธ ๐Ÿ—œ **๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ”** ๐Ÿ“„ ๐Ÿง โšก.
* โœณ **๐Ÿ†‘** (๐Ÿ” ๐Ÿ› ๏ธ), ๐Ÿ”Œ ๐Ÿ•ธ &amp; ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ”ฌ.
## ๐ŸŒ• ๐Ÿ“š FastAPI ๐Ÿ—„
๐Ÿ“‚: <a href="https://github.com/tiangolo/full-stack-fastapi-couchbase" class="external-link" target="_blank">https://github.com/tiangolo/full-stack-fastapi-couchbase</a>
๐Ÿ‘ถ ๐Ÿ‘ถ **โš ** ๐Ÿ‘ถ ๐Ÿ‘ถ
๐Ÿšฅ ๐Ÿ‘† โ–ถ๏ธ ๐Ÿ†• ๐Ÿ— โšช๏ธโžก๏ธ ๐Ÿ–Œ, โœ… ๐ŸŽ› ๐Ÿ“ฅ.
๐Ÿ–ผ, ๐Ÿ— ๐Ÿš‚ <a href="https://github.com/tiangolo/full-stack-fastapi-postgresql" class="external-link" target="_blank">๐ŸŒ• ๐Ÿ“š FastAPI โœณ</a> ๐Ÿ’ช ๐Ÿ‘ ๐ŸŽ›, โšซ๏ธ ๐ŸŽฏ ๐Ÿšง &amp; โš™๏ธ. &amp; โšซ๏ธ ๐Ÿ”Œ ๐ŸŒ ๐Ÿ†• โš’ &amp; ๐Ÿ“ˆ.
๐Ÿ‘† ๐Ÿ†“ โš™๏ธ ๐Ÿ—„-โš“๏ธ ๐Ÿš‚ ๐Ÿšฅ ๐Ÿ‘† ๐Ÿ’š, โšซ๏ธ ๐Ÿ”œ ๐ŸŽฒ ๐Ÿ‘ท ๐Ÿ‘Œ, &amp; ๐Ÿšฅ ๐Ÿ‘† โช โœ”๏ธ ๐Ÿ— ๐Ÿ— โฎ๏ธ โšซ๏ธ ๐Ÿ‘ˆ ๐Ÿ‘Œ ๐Ÿ‘ (&amp; ๐Ÿ‘† ๐ŸŽฒ โช โ„น โšซ๏ธ โ™ฃ ๐Ÿ‘† ๐Ÿ’ช).
๐Ÿ‘† ๐Ÿ’ช โœ ๐ŸŒ… ๐Ÿ”ƒ โšซ๏ธ ๐Ÿฉบ ๐Ÿฆ.
## ๐ŸŒ• ๐Ÿ“š FastAPI โœณ
...๐Ÿ’ช ๐Ÿ‘Ÿ โช, โš“๏ธ ๐Ÿ”› ๐Ÿ‘‡ ๐Ÿ•ฐ ๐Ÿšš &amp; ๐ŸŽ โš–. ๐Ÿ‘ถ ๐Ÿ‘ถ
## ๐ŸŽฐ ๐Ÿซ ๐Ÿท โฎ๏ธ ๐ŸŒˆ &amp; FastAPI
๐Ÿ“‚: <a href="https://github.com/microsoft/cookiecutter-spacy-fastapi" class="external-link" target="_blank">https://github.com/microsoft/cookiecutter-spacy-fastapi</a>
### ๐ŸŽฐ ๐Ÿซ ๐Ÿท โฎ๏ธ ๐ŸŒˆ &amp; FastAPI - โš’
* **๐ŸŒˆ** ๐Ÿ•œ ๐Ÿท ๐Ÿ› ๏ธ.
* **โ˜ ๐Ÿง  ๐Ÿ”Ž** ๐Ÿ“จ ๐Ÿ“ ๐Ÿ—.
* **๐Ÿญ ๐Ÿ”œ** ๐Ÿ ๐Ÿ•ธ ๐Ÿ’ฝ โš™๏ธ Uvicorn &amp; ๐Ÿ.
* **โ˜ ๐Ÿ‘ฉโ€๐Ÿ’ป** Kubernete (๐Ÿฆฒ) ๐Ÿ†‘/๐Ÿ’ฟ ๐Ÿ› ๏ธ ๐Ÿ—.
* **๐Ÿคธโ€โ™‚** ๐Ÿ’ช โš’ 1๏ธโƒฃ ๐ŸŒˆ ๐Ÿ— ๐Ÿ‡ช๐Ÿ‡ธ โฎ๏ธ ๐Ÿ— ๐Ÿ–ฅ.
* **๐Ÿ’ช ๐Ÿง** ๐ŸŽ ๐Ÿท ๐Ÿ› ๏ธ (Pytorch, ๐Ÿ‡ธ๐Ÿ‡ฒ), ๐Ÿšซ ๐ŸŒˆ.

490
docs/em/docs/python-types.md

@ -0,0 +1,490 @@
# ๐Ÿ ๐Ÿ†Ž ๐ŸŽถ
๐Ÿ โœ”๏ธ ๐Ÿ•โ€๐Ÿฆบ ๐Ÿ“ฆ "๐Ÿ†Ž ๐Ÿ”‘".
๐Ÿ‘ซ **"๐Ÿ†Ž ๐Ÿ”‘"** ๐ŸŽ โ• ๐Ÿ‘ˆ โœ” ๐Ÿ“ฃ <abbr title="for example: str, int, float, bool">๐Ÿ†Ž</abbr> ๐Ÿ”ข.
๐Ÿ“ฃ ๐Ÿ†Ž ๐Ÿ‘† ๐Ÿ”ข, ๐Ÿ‘จโ€๐ŸŽจ &amp; ๐Ÿงฐ ๐Ÿ’ช ๐Ÿค ๐Ÿ‘† ๐Ÿ‘ ๐Ÿ•โ€๐Ÿฆบ.
๐Ÿ‘‰ **โฉ ๐Ÿ”ฐ / โ†—๏ธ** ๐Ÿ”ƒ ๐Ÿ ๐Ÿ†Ž ๐Ÿ”‘. โšซ๏ธ ๐Ÿ“” ๐Ÿ•ด ๐Ÿ’ฏ ๐Ÿ’ช โš™๏ธ ๐Ÿ‘ซ โฎ๏ธ **FastAPI**... โ” ๐Ÿค™ ๐Ÿ“ถ ๐Ÿฅ.
**FastAPI** ๐ŸŒ โš“๏ธ ๐Ÿ”› ๐Ÿ‘ซ ๐Ÿ†Ž ๐Ÿ”‘, ๐Ÿ‘ซ ๐Ÿค โšซ๏ธ ๐Ÿ“š ๐Ÿ“ˆ &amp; ๐Ÿ’ฐ.
โœ‹๏ธ ๐Ÿšฅ ๐Ÿ‘† ๐Ÿ™… โš™๏ธ **FastAPI**, ๐Ÿ‘† ๐Ÿ”œ ๐Ÿ’ฐ โšช๏ธโžก๏ธ ๐Ÿซ ๐Ÿ– ๐Ÿ”ƒ ๐Ÿ‘ซ.
!!! note
๐Ÿšฅ ๐Ÿ‘† ๐Ÿ ๐Ÿ•ด, &amp; ๐Ÿ‘† โช ๐Ÿ’ญ ๐ŸŒ ๐Ÿ”ƒ ๐Ÿ†Ž ๐Ÿ”‘, ๐Ÿšถ โญ ๐Ÿ“ƒ.
## ๐ŸŽฏ
โžก๏ธ โ–ถ๏ธ โฎ๏ธ ๐Ÿ™… ๐Ÿ–ผ:
```Python
{!../../../docs_src/python_types/tutorial001.py!}
```
๐Ÿค™ ๐Ÿ‘‰ ๐Ÿ“‹ ๐Ÿ”ข:
```
John Doe
```
๐Ÿ”ข ๐Ÿ”จ ๐Ÿ“„:
* โœŠ `first_name` &amp; `last_name`.
* ๐Ÿ—œ ๐Ÿฅ‡ ๐Ÿ”ค ๐Ÿ”  1๏ธโƒฃ โ†– ๐Ÿ’ผ โฎ๏ธ `title()`.
* <abbr title="Puts them together, as one. With the contents of one after the other.">๐Ÿ”ข</abbr> ๐Ÿ‘ซ โฎ๏ธ ๐Ÿš€ ๐Ÿ–•.
```Python hl_lines="2"
{!../../../docs_src/python_types/tutorial001.py!}
```
### โœ โšซ๏ธ
โšซ๏ธ ๐Ÿ“ถ ๐Ÿ™… ๐Ÿ“‹.
โœ‹๏ธ ๐Ÿ”œ ๐ŸŒˆ ๐Ÿ‘ˆ ๐Ÿ‘† โœ โšซ๏ธ โšช๏ธโžก๏ธ ๐Ÿ–Œ.
โ˜ ๐Ÿ‘† ๐Ÿ”œ โœ”๏ธ โ–ถ๏ธ ๐Ÿ”‘ ๐Ÿ”ข, ๐Ÿ‘† โœ”๏ธ ๐Ÿ”ข ๐Ÿ”œ...
โœ‹๏ธ โคด๏ธ ๐Ÿ‘† โœ”๏ธ ๐Ÿค™ "๐Ÿ‘ˆ ๐Ÿ‘ฉโ€๐Ÿ”ฌ ๐Ÿ‘ˆ ๐Ÿ—œ ๐Ÿฅ‡ ๐Ÿ”ค โ†– ๐Ÿ’ผ".
โšซ๏ธ `upper`โ“ โšซ๏ธ `uppercase`โ“ `first_uppercase`โ“ `capitalize`โ“
โคด๏ธ, ๐Ÿ‘† ๐Ÿ”„ โฎ๏ธ ๐Ÿ— ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ‘จโ€๐Ÿ‘งโ€๐Ÿ‘ฆ, ๐Ÿ‘จโ€๐ŸŽจ โœ.
๐Ÿ‘† ๐Ÿ†Ž ๐Ÿฅ‡ ๐Ÿ”ข ๐Ÿ”ข, `first_name`, โคด๏ธ โฃ (`.`) &amp; โคด๏ธ ๐ŸŽฏ `Ctrl+Space` โฒ ๐Ÿ› ๏ธ.
โœ‹๏ธ, ๐Ÿ˜ž, ๐Ÿ‘† ๐Ÿคš ๐Ÿ•ณ โš :
<img src="/img/python-types/image01.png">
### ๐Ÿšฎ ๐Ÿ†Ž
โžก๏ธ ๐Ÿ”€ ๐Ÿ‘ โธ โšช๏ธโžก๏ธ โฎ๏ธ โฌ.
๐Ÿ‘ฅ ๐Ÿ”œ ๐Ÿ”€ โšซ๏ธโ” ๐Ÿ‘‰ ๐Ÿงฌ, ๐Ÿ”ข ๐Ÿ”ข, โšช๏ธโžก๏ธ:
```Python
first_name, last_name
```
:
```Python
first_name: str, last_name: str
```
๐Ÿ‘ˆ โšซ๏ธ.
๐Ÿ‘ˆ "๐Ÿ†Ž ๐Ÿ”‘":
```Python hl_lines="1"
{!../../../docs_src/python_types/tutorial002.py!}
```
๐Ÿ‘ˆ ๐Ÿšซ ๐ŸŽ ๐Ÿ“ฃ ๐Ÿ”ข ๐Ÿ’ฒ ๐Ÿ’– ๐Ÿ”œ โฎ๏ธ:
```Python
first_name="john", last_name="doe"
```
โšซ๏ธ ๐ŸŽ ๐Ÿ‘œ.
๐Ÿ‘ฅ โš™๏ธ โค (`:`), ๐Ÿšซ ๐ŸŒ“ (`=`).
&amp; โŽ ๐Ÿ†Ž ๐Ÿ”‘ ๐Ÿ›Ž ๐Ÿšซ ๐Ÿ”€ โšซ๏ธโ” ๐Ÿ”จ โšช๏ธโžก๏ธ โšซ๏ธโ” ๐Ÿ”œ ๐Ÿ”จ ๐Ÿต ๐Ÿ‘ซ.
โœ‹๏ธ ๐Ÿ”œ, ๐ŸŒˆ ๐Ÿ‘† ๐Ÿ”„ ๐Ÿ–• ๐Ÿ— ๐Ÿ‘ˆ ๐Ÿ”ข, โœ‹๏ธ โฎ๏ธ ๐Ÿ†Ž ๐Ÿ”‘.
๐ŸŽ โ˜, ๐Ÿ‘† ๐Ÿ”„ โฒ ๐Ÿ“‹ โฎ๏ธ `Ctrl+Space` &amp; ๐Ÿ‘† ๐Ÿ‘€:
<img src="/img/python-types/image02.png">
โฎ๏ธ ๐Ÿ‘ˆ, ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ“œ, ๐Ÿ‘€ ๐ŸŽ›, โญ ๐Ÿ‘† ๐Ÿ”Ž 1๏ธโƒฃ ๐Ÿ‘ˆ "๐Ÿ’ ๐Ÿ””":
<img src="/img/python-types/image03.png">
## ๐ŸŒ… ๐ŸŽฏ
โœ… ๐Ÿ‘‰ ๐Ÿ”ข, โšซ๏ธ โช โœ”๏ธ ๐Ÿ†Ž ๐Ÿ”‘:
```Python hl_lines="1"
{!../../../docs_src/python_types/tutorial003.py!}
```
โ†ฉ๏ธ ๐Ÿ‘จโ€๐ŸŽจ ๐Ÿ’ญ ๐Ÿ†Ž ๐Ÿ”ข, ๐Ÿ‘† ๐Ÿšซ ๐Ÿ•ด ๐Ÿคš ๐Ÿ› ๏ธ, ๐Ÿ‘† ๐Ÿคš โŒ โœ…:
<img src="/img/python-types/image04.png">
๐Ÿ”œ ๐Ÿ‘† ๐Ÿ’ญ ๐Ÿ‘ˆ ๐Ÿ‘† โœ”๏ธ ๐Ÿ”ง โšซ๏ธ, ๐Ÿ—œ `age` ๐ŸŽป โฎ๏ธ `str(age)`:
```Python hl_lines="2"
{!../../../docs_src/python_types/tutorial004.py!}
```
## ๐Ÿ“ฃ ๐Ÿ†Ž
๐Ÿ‘† ๐Ÿ‘€ ๐Ÿ‘‘ ๐Ÿฅ‰ ๐Ÿ“ฃ ๐Ÿ†Ž ๐Ÿ”‘. ๐Ÿ”ข ๐Ÿ”ข.
๐Ÿ‘‰ ๐Ÿ‘‘ ๐Ÿฅ‰ ๐Ÿ‘† ๐Ÿ”œ โš™๏ธ ๐Ÿ‘ซ โฎ๏ธ **FastAPI**.
### ๐Ÿ™… ๐Ÿ†Ž
๐Ÿ‘† ๐Ÿ’ช ๐Ÿ“ฃ ๐ŸŒ ๐Ÿฉ ๐Ÿ ๐Ÿ†Ž, ๐Ÿšซ ๐Ÿ•ด `str`.
๐Ÿ‘† ๐Ÿ’ช โš™๏ธ, ๐Ÿ–ผ:
* `int`
* `float`
* `bool`
* `bytes`
```Python hl_lines="1"
{!../../../docs_src/python_types/tutorial005.py!}
```
### ๐Ÿ’Š ๐Ÿ†Ž โฎ๏ธ ๐Ÿ†Ž ๐Ÿ”ข
๐Ÿ“ค ๐Ÿ“Š ๐Ÿ“Š ๐Ÿ‘ˆ ๐Ÿ’ช ๐Ÿ”Œ ๐ŸŽ ๐Ÿ’ฒ, ๐Ÿ’– `dict`, `list`, `set` &amp; `tuple`. &amp; ๐Ÿ”— ๐Ÿ’ฒ ๐Ÿ’ช โœ”๏ธ ๐Ÿ‘ซ ๐Ÿ‘ ๐Ÿ†Ž ๐Ÿ’โ€โ™‚๏ธ.
๐Ÿ‘‰ ๐Ÿ†Ž ๐Ÿ‘ˆ โœ”๏ธ ๐Ÿ”— ๐Ÿ†Ž ๐Ÿค™ "**๐Ÿ’Š**" ๐Ÿ†Ž. &amp; โšซ๏ธ ๐Ÿ’ช ๐Ÿ“ฃ ๐Ÿ‘ซ, โฎ๏ธ ๐Ÿ‘ซ ๐Ÿ”— ๐Ÿ†Ž.
๐Ÿ“ฃ ๐Ÿ‘ˆ ๐Ÿ†Ž &amp; ๐Ÿ”— ๐Ÿ†Ž, ๐Ÿ‘† ๐Ÿ’ช โš™๏ธ ๐Ÿฉ ๐Ÿ ๐Ÿ•น `typing`. โšซ๏ธ ๐Ÿ”€ ๐ŸŽฏ ๐Ÿ•โ€๐Ÿฆบ ๐Ÿ‘ซ ๐Ÿ†Ž ๐Ÿ”‘.
#### ๐Ÿ†• โฌ ๐Ÿ
โ• โš™๏ธ `typing` **๐Ÿ”—** โฎ๏ธ ๐ŸŒ โฌ, โšช๏ธโžก๏ธ ๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ โช ๐Ÿ•, โœ… ๐Ÿ 3๏ธโƒฃ.9๏ธโƒฃ, ๐Ÿ 3๏ธโƒฃ.1๏ธโƒฃ0๏ธโƒฃ, โ™’๏ธ.
๐Ÿ ๐Ÿง, **๐Ÿ†• โฌ** ๐Ÿ‘Ÿ โฎ๏ธ ๐Ÿ“‰ ๐Ÿ•โ€๐Ÿฆบ ๐Ÿ‘‰ ๐Ÿ†Ž โœ &amp; ๐Ÿ“š ๐Ÿ’ผ ๐Ÿ‘† ๐Ÿ† ๐Ÿšซ ๐Ÿ’ช ๐Ÿ—„ &amp; โš™๏ธ `typing` ๐Ÿ•น ๐Ÿ“ฃ ๐Ÿ†Ž โœ.
๐Ÿšฅ ๐Ÿ‘† ๐Ÿ’ช โš’ ๐ŸŒ– โฎ๏ธ โฌ ๐Ÿ ๐Ÿ‘† ๐Ÿ—, ๐Ÿ‘† ๐Ÿ”œ ๐Ÿ’ช โœŠ ๐Ÿ“ˆ ๐Ÿ‘ˆ โž• ๐Ÿฆ. ๐Ÿ‘€ ๐Ÿ–ผ ๐Ÿ”›.
#### ๐Ÿ“‡
๐Ÿ–ผ, โžก๏ธ ๐Ÿ”ฌ ๐Ÿ”ข `list` `str`.
=== "๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ &amp; ๐Ÿ”›"
โšช๏ธโžก๏ธ `typing`, ๐Ÿ—„ `List` (โฎ๏ธ ๐Ÿ”  `L`):
``` Python hl_lines="1"
{!> ../../../docs_src/python_types/tutorial006.py!}
```
๐Ÿ“ฃ ๐Ÿ”ข, โฎ๏ธ ๐ŸŽ โค (`:`) โ•.
๐Ÿ†Ž, ๐Ÿšฎ `List` ๐Ÿ‘ˆ ๐Ÿ‘† ๐Ÿ—„ โšช๏ธโžก๏ธ `typing`.
๐Ÿ“‡ ๐Ÿ†Ž ๐Ÿ‘ˆ ๐Ÿ”Œ ๐Ÿ”— ๐Ÿ†Ž, ๐Ÿ‘† ๐Ÿšฎ ๐Ÿ‘ซ โฌœ ๐Ÿ—œ:
```Python hl_lines="4"
{!> ../../../docs_src/python_types/tutorial006.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.9๏ธโƒฃ &amp; ๐Ÿ”›"
๐Ÿ“ฃ ๐Ÿ”ข, โฎ๏ธ ๐ŸŽ โค (`:`) โ•.
๐Ÿ†Ž, ๐Ÿšฎ `list`.
๐Ÿ“‡ ๐Ÿ†Ž ๐Ÿ‘ˆ ๐Ÿ”Œ ๐Ÿ”— ๐Ÿ†Ž, ๐Ÿ‘† ๐Ÿšฎ ๐Ÿ‘ซ โฌœ ๐Ÿ—œ:
```Python hl_lines="1"
{!> ../../../docs_src/python_types/tutorial006_py39.py!}
```
!!! info
๐Ÿ‘ˆ ๐Ÿ”— ๐Ÿ†Ž โฌœ ๐Ÿ—œ ๐Ÿค™ "๐Ÿ†Ž ๐Ÿ”ข".
๐Ÿ‘‰ ๐Ÿ’ผ, `str` ๐Ÿ†Ž ๐Ÿ”ข ๐Ÿšถโ€โ™€๏ธ `List` (โš–๏ธ `list` ๐Ÿ 3๏ธโƒฃ.9๏ธโƒฃ &amp; ๐Ÿ”›).
๐Ÿ‘ˆ โ›“: "๐Ÿ”ข `items` `list`, &amp; ๐Ÿ”  ๐Ÿฌ ๐Ÿ‘‰ ๐Ÿ“‡ `str`".
!!! tip
๐Ÿšฅ ๐Ÿ‘† โš™๏ธ ๐Ÿ 3๏ธโƒฃ.9๏ธโƒฃ โš–๏ธ ๐Ÿ”›, ๐Ÿ‘† ๐Ÿšซ โœ”๏ธ ๐Ÿ—„ `List` โšช๏ธโžก๏ธ `typing`, ๐Ÿ‘† ๐Ÿ’ช โš™๏ธ ๐ŸŽ ๐Ÿฅ” `list` ๐Ÿ†Ž โ†ฉ๏ธ.
๐Ÿ”จ ๐Ÿ‘ˆ, ๐Ÿ‘† ๐Ÿ‘จโ€๐ŸŽจ ๐Ÿ’ช ๐Ÿšš ๐Ÿ•โ€๐Ÿฆบ โช ๐Ÿญ ๐Ÿฌ โšช๏ธโžก๏ธ ๐Ÿ“‡:
<img src="/img/python-types/image05.png">
๐Ÿต ๐Ÿ†Ž, ๐Ÿ‘ˆ ๐ŸŒ– ๐Ÿ’ช ๐Ÿ†.
๐Ÿ‘€ ๐Ÿ‘ˆ ๐Ÿ”ข `item` 1๏ธโƒฃ ๐Ÿ”ฃ ๐Ÿ“‡ `items`.
&amp; , ๐Ÿ‘จโ€๐ŸŽจ ๐Ÿ’ญ โšซ๏ธ `str`, &amp; ๐Ÿšš ๐Ÿ•โ€๐Ÿฆบ ๐Ÿ‘ˆ.
#### ๐Ÿ”ข &amp; โš’
๐Ÿ‘† ๐Ÿ”œ ๐ŸŽ ๐Ÿ“ฃ `tuple`โ“‚ &amp; `set`โ“‚:
=== "๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="1 4"
{!> ../../../docs_src/python_types/tutorial007.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.9๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="1"
{!> ../../../docs_src/python_types/tutorial007_py39.py!}
```
๐Ÿ‘‰ โ›“:
* ๐Ÿ”ข `items_t` `tuple` โฎ๏ธ 3๏ธโƒฃ ๐Ÿฌ, `int`, โž•1๏ธโƒฃ `int`, &amp; `str`.
* ๐Ÿ”ข `items_s` `set`, &amp; ๐Ÿ”  ๐Ÿšฎ ๐Ÿฌ ๐Ÿ†Ž `bytes`.
#### #๏ธโƒฃ
๐Ÿ”ฌ `dict`, ๐Ÿ‘† ๐Ÿšถโ€โ™€๏ธ 2๏ธโƒฃ ๐Ÿ†Ž ๐Ÿ”ข, ๐ŸŽ โ•.
๐Ÿฅ‡ ๐Ÿ†Ž ๐Ÿ”ข ๐Ÿ”‘ `dict`.
๐Ÿฅˆ ๐Ÿ†Ž ๐Ÿ”ข ๐Ÿ’ฒ `dict`:
=== "๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="1 4"
{!> ../../../docs_src/python_types/tutorial008.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.9๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="1"
{!> ../../../docs_src/python_types/tutorial008_py39.py!}
```
๐Ÿ‘‰ โ›“:
* ๐Ÿ”ข `prices` `dict`:
* ๐Ÿ”‘ ๐Ÿ‘‰ `dict` ๐Ÿ†Ž `str` (โžก๏ธ ๐Ÿ’ฌ, ๐Ÿ“› ๐Ÿ”  ๐Ÿฌ).
* ๐Ÿ’ฒ ๐Ÿ‘‰ `dict` ๐Ÿ†Ž `float` (โžก๏ธ ๐Ÿ’ฌ, ๐Ÿ”– ๐Ÿ”  ๐Ÿฌ).
#### ๐Ÿ‡ช๐Ÿ‡บ
๐Ÿ‘† ๐Ÿ’ช ๐Ÿ“ฃ ๐Ÿ‘ˆ ๐Ÿ”ข ๐Ÿ’ช ๐Ÿ™† **๐Ÿ“š ๐Ÿ†Ž**, ๐Ÿ–ผ, `int` โš–๏ธ `str`.
๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ &amp; ๐Ÿ”› (โœ… ๐Ÿ 3๏ธโƒฃ.1๏ธโƒฃ0๏ธโƒฃ) ๐Ÿ‘† ๐Ÿ’ช โš™๏ธ `Union` ๐Ÿ†Ž โšช๏ธโžก๏ธ `typing` &amp; ๐Ÿšฎ ๐Ÿ”˜ โฌœ ๐Ÿ—œ ๐Ÿ’ช ๐Ÿ†Ž ๐Ÿšซ.
๐Ÿ 3๏ธโƒฃ.1๏ธโƒฃ0๏ธโƒฃ ๐Ÿ“ค **๐ŸŽ› โ•** ๐ŸŒโ” ๐Ÿ‘† ๐Ÿ’ช ๐Ÿšฎ ๐Ÿ’ช ๐Ÿ†Ž ๐Ÿ‘ฝ <abbr title='also called "bitwise or operator", but that meaning is not relevant here'>โธ โธ (`|`)</abbr>.
=== "๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="1 4"
{!> ../../../docs_src/python_types/tutorial008b.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.1๏ธโƒฃ0๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="1"
{!> ../../../docs_src/python_types/tutorial008b_py310.py!}
```
๐Ÿ‘ฏโ€โ™‚๏ธ ๐Ÿ’ผ ๐Ÿ‘‰ โ›“ ๐Ÿ‘ˆ `item` ๐Ÿ’ช `int` โš–๏ธ `str`.
#### ๐ŸŽฒ `None`
๐Ÿ‘† ๐Ÿ’ช ๐Ÿ“ฃ ๐Ÿ‘ˆ ๐Ÿ’ฒ ๐Ÿ’ช โœ”๏ธ ๐Ÿ†Ž, ๐Ÿ’– `str`, โœ‹๏ธ ๐Ÿ‘ˆ โšซ๏ธ ๐Ÿ’ช `None`.
๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ &amp; ๐Ÿ”› (โœ… ๐Ÿ 3๏ธโƒฃ.1๏ธโƒฃ0๏ธโƒฃ) ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ“ฃ โšซ๏ธ ๐Ÿญ &amp; โš™๏ธ `Optional` โšช๏ธโžก๏ธ `typing` ๐Ÿ•น.
```Python hl_lines="1 4"
{!../../../docs_src/python_types/tutorial009.py!}
```
โš™๏ธ `Optional[str]` โ†ฉ๏ธ `str` ๐Ÿ”œ โžก๏ธ ๐Ÿ‘จโ€๐ŸŽจ โ„น ๐Ÿ‘† ๐Ÿ” โŒ ๐ŸŒโ” ๐Ÿ‘† ๐Ÿ’ช ๐Ÿค” ๐Ÿ‘ˆ ๐Ÿ’ฒ ๐Ÿ•ง `str`, ๐Ÿ•โ” โšซ๏ธ ๐Ÿ’ช ๐Ÿค™ `None` ๐Ÿ’โ€โ™‚๏ธ.
`Optional[Something]` ๐Ÿค™ โŒจ `Union[Something, None]`, ๐Ÿ‘ซ ๐ŸŒ“.
๐Ÿ‘‰ โ›“ ๐Ÿ‘ˆ ๐Ÿ 3๏ธโƒฃ.1๏ธโƒฃ0๏ธโƒฃ, ๐Ÿ‘† ๐Ÿ’ช โš™๏ธ `Something | None`:
=== "๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="1 4"
{!> ../../../docs_src/python_types/tutorial009.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ &amp; ๐Ÿ”› - ๐ŸŽ›"
```Python hl_lines="1 4"
{!> ../../../docs_src/python_types/tutorial009b.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.1๏ธโƒฃ0๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="1"
{!> ../../../docs_src/python_types/tutorial009_py310.py!}
```
#### โš™๏ธ `Union` โš–๏ธ `Optional`
๐Ÿšฅ ๐Ÿ‘† โš™๏ธ ๐Ÿ โฌ ๐Ÿ”› 3๏ธโƒฃ.1๏ธโƒฃ0๏ธโƒฃ, ๐Ÿ“ฅ ๐Ÿ’โ€โ™‚ โšช๏ธโžก๏ธ ๐Ÿ‘‡ ๐Ÿ“ถ **๐Ÿค”** โ˜ ๐ŸŽ‘:
* ๐Ÿ‘ถ โŽ โš™๏ธ `Optional[SomeType]`
* โ†ฉ๏ธ ๐Ÿ‘ถ **โš™๏ธ `Union[SomeType, None]`** ๐Ÿ‘ถ.
๐Ÿ‘ฏโ€โ™‚๏ธ ๐ŸŒ“ &amp; ๐Ÿ”˜ ๐Ÿ‘ซ ๐ŸŽ, โœ‹๏ธ ๐Ÿ‘ค ๐Ÿ”œ ๐Ÿ‘ `Union` โ†ฉ๏ธ `Optional` โ†ฉ๏ธ ๐Ÿ”ค "**๐Ÿ“ฆ**" ๐Ÿ”œ ๐Ÿ˜‘ ๐Ÿ”‘ ๐Ÿ‘ˆ ๐Ÿ’ฒ ๐Ÿ“ฆ, &amp; โšซ๏ธ ๐Ÿค™ โ›“ "โšซ๏ธ ๐Ÿ’ช `None`", ๐Ÿšฅ โšซ๏ธ ๐Ÿšซ ๐Ÿ“ฆ &amp; โœ”.
๐Ÿ‘ค ๐Ÿ’ญ `Union[SomeType, None]` ๐ŸŒ– ๐Ÿ”‘ ๐Ÿ”ƒ โšซ๏ธโ” โšซ๏ธ โ›“.
โšซ๏ธ ๐Ÿ”ƒ ๐Ÿ”ค &amp; ๐Ÿ“›. โœ‹๏ธ ๐Ÿ‘ˆ ๐Ÿ”ค ๐Ÿ’ช ๐Ÿ“‰ โ” ๐Ÿ‘† &amp; ๐Ÿ‘† ๐Ÿคฝโ€โ™‚ ๐Ÿ’ญ ๐Ÿ”ƒ ๐Ÿ“Ÿ.
๐Ÿ–ผ, โžก๏ธ โœŠ ๐Ÿ‘‰ ๐Ÿ”ข:
```Python hl_lines="1 4"
{!../../../docs_src/python_types/tutorial009c.py!}
```
๐Ÿ”ข `name` ๐Ÿ”ฌ `Optional[str]`, โœ‹๏ธ โšซ๏ธ **๐Ÿšซ ๐Ÿ“ฆ**, ๐Ÿ‘† ๐Ÿšซ๐Ÿ”œ ๐Ÿค™ ๐Ÿ”ข ๐Ÿต ๐Ÿ”ข:
```Python
say_hi() # Oh, no, this throws an error! ๐Ÿ˜ฑ
```
`name` ๐Ÿ”ข **โœ”** (๐Ÿšซ *๐Ÿ“ฆ*) โ†ฉ๏ธ โšซ๏ธ ๐Ÿšซ โœ”๏ธ ๐Ÿ”ข ๐Ÿ’ฒ. , `name` ๐Ÿšซ `None` ๐Ÿ’ฒ:
```Python
say_hi(name=None) # This works, None is valid ๐ŸŽ‰
```
๐Ÿ‘ ๐Ÿ“ฐ, ๐Ÿ• ๐Ÿ‘† ๐Ÿ”› ๐Ÿ 3๏ธโƒฃ.1๏ธโƒฃ0๏ธโƒฃ ๐Ÿ‘† ๐Ÿ† ๐Ÿšซ โœ”๏ธ ๐Ÿ˜Ÿ ๐Ÿ”ƒ ๐Ÿ‘ˆ, ๐Ÿ‘† ๐Ÿ”œ ๐Ÿ’ช ๐ŸŽฏ โš™๏ธ `|` ๐Ÿ”ฌ ๐Ÿ‡ช๐Ÿ‡บ ๐Ÿ†Ž:
```Python hl_lines="1 4"
{!../../../docs_src/python_types/tutorial009c_py310.py!}
```
&amp; โคด๏ธ ๐Ÿ‘† ๐Ÿ† ๐Ÿšซ โœ”๏ธ ๐Ÿ˜Ÿ ๐Ÿ”ƒ ๐Ÿ“› ๐Ÿ’– `Optional` &amp; `Union`. ๐Ÿ‘ถ
#### ๐Ÿ’Š ๐Ÿ†Ž
๐Ÿ‘‰ ๐Ÿ†Ž ๐Ÿ‘ˆ โœŠ ๐Ÿ†Ž ๐Ÿ”ข โฌœ ๐Ÿ—œ ๐Ÿค™ **๐Ÿ’Š ๐Ÿ†Ž** โš–๏ธ **๐Ÿ’Š**, ๐Ÿ–ผ:
=== "๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ &amp; ๐Ÿ”›"
* `List`
* `Tuple`
* `Set`
* `Dict`
* `Union`
* `Optional`
* ...&amp; ๐ŸŽ.
=== "๐Ÿ 3๏ธโƒฃ.9๏ธโƒฃ &amp; ๐Ÿ”›"
๐Ÿ‘† ๐Ÿ’ช โš™๏ธ ๐ŸŽ ๐Ÿ’ฝ ๐Ÿ†Ž ๐Ÿ’Š (โฎ๏ธ โฌœ ๐Ÿ—œ &amp; ๐Ÿ†Ž ๐Ÿ”˜):
* `list`
* `tuple`
* `set`
* `dict`
&amp; ๐ŸŽ โฎ๏ธ ๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ, โšช๏ธโžก๏ธ `typing` ๐Ÿ•น:
* `Union`
* `Optional`
* ...&amp; ๐ŸŽ.
=== "๐Ÿ 3๏ธโƒฃ.1๏ธโƒฃ0๏ธโƒฃ &amp; ๐Ÿ”›"
๐Ÿ‘† ๐Ÿ’ช โš™๏ธ ๐ŸŽ ๐Ÿ’ฝ ๐Ÿ†Ž ๐Ÿ’Š (โฎ๏ธ โฌœ ๐Ÿ—œ &amp; ๐Ÿ†Ž ๐Ÿ”˜):
* `list`
* `tuple`
* `set`
* `dict`
&amp; ๐ŸŽ โฎ๏ธ ๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ, โšช๏ธโžก๏ธ `typing` ๐Ÿ•น:
* `Union`
* `Optional` (๐ŸŽ โฎ๏ธ ๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ)
* ...&amp; ๐ŸŽ.
๐Ÿ 3๏ธโƒฃ.1๏ธโƒฃ0๏ธโƒฃ, ๐ŸŽ› โš™๏ธ ๐Ÿ’Š `Union` &amp; `Optional`, ๐Ÿ‘† ๐Ÿ’ช โš™๏ธ <abbr title='also called "bitwise or operator", but that meaning is not relevant here'>โธ โธ (`|`)</abbr> ๐Ÿ“ฃ ๐Ÿ‡ช๐Ÿ‡บ ๐Ÿ†Ž.
### ๐ŸŽ“ ๐Ÿ†Ž
๐Ÿ‘† ๐Ÿ’ช ๐Ÿ“ฃ ๐ŸŽ“ ๐Ÿ†Ž ๐Ÿ”ข.
โžก๏ธ ๐Ÿ’ฌ ๐Ÿ‘† โœ”๏ธ ๐ŸŽ“ `Person`, โฎ๏ธ ๐Ÿ“›:
```Python hl_lines="1-3"
{!../../../docs_src/python_types/tutorial010.py!}
```
โคด๏ธ ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ“ฃ ๐Ÿ”ข ๐Ÿ†Ž `Person`:
```Python hl_lines="6"
{!../../../docs_src/python_types/tutorial010.py!}
```
&amp; โคด๏ธ, ๐Ÿ”„, ๐Ÿ‘† ๐Ÿคš ๐ŸŒ ๐Ÿ‘จโ€๐ŸŽจ ๐Ÿ•โ€๐Ÿฆบ:
<img src="/img/python-types/image06.png">
## Pydantic ๐Ÿท
<a href="https://pydantic-docs.helpmanual.io/" class="external-link" target="_blank">Pydantic</a> ๐Ÿ ๐Ÿ—ƒ ๐ŸŽญ ๐Ÿ“Š ๐Ÿ”ฌ.
๐Ÿ‘† ๐Ÿ“ฃ "๐Ÿ’ " ๐Ÿ’ฝ ๐ŸŽ“ โฎ๏ธ ๐Ÿ”ข.
&amp; ๐Ÿ”  ๐Ÿ”ข โœ”๏ธ ๐Ÿ†Ž.
โคด๏ธ ๐Ÿ‘† โœ ๐Ÿ‘ ๐Ÿ‘ˆ ๐ŸŽ“ โฎ๏ธ ๐Ÿ’ฒ &amp; โšซ๏ธ ๐Ÿ”œ โœ” ๐Ÿ’ฒ, ๐Ÿ—œ ๐Ÿ‘ซ โ˜‘ ๐Ÿ†Ž (๐Ÿšฅ ๐Ÿ‘ˆ ๐Ÿ’ผ) &amp; ๐Ÿค ๐Ÿ‘† ๐ŸŽš โฎ๏ธ ๐ŸŒ ๐Ÿ’ฝ.
&amp; ๐Ÿ‘† ๐Ÿคš ๐ŸŒ ๐Ÿ‘จโ€๐ŸŽจ ๐Ÿ•โ€๐Ÿฆบ โฎ๏ธ ๐Ÿ‘ˆ ๐Ÿ“‰ ๐ŸŽš.
๐Ÿ–ผ โšช๏ธโžก๏ธ ๐Ÿ›‚ Pydantic ๐Ÿฉบ:
=== "๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ &amp; ๐Ÿ”›"
```Python
{!> ../../../docs_src/python_types/tutorial011.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.9๏ธโƒฃ &amp; ๐Ÿ”›"
```Python
{!> ../../../docs_src/python_types/tutorial011_py39.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.1๏ธโƒฃ0๏ธโƒฃ &amp; ๐Ÿ”›"
```Python
{!> ../../../docs_src/python_types/tutorial011_py310.py!}
```
!!! info
๐Ÿ’ก ๐ŸŒ– ๐Ÿ”ƒ <a href="https://pydantic-docs.helpmanual.io/" class="external-link" target="_blank">Pydantic, โœ… ๐Ÿšฎ ๐Ÿฉบ</a>.
**FastAPI** ๐ŸŒ โš“๏ธ ๐Ÿ”› Pydantic.
๐Ÿ‘† ๐Ÿ”œ ๐Ÿ‘€ ๐Ÿ“š ๐ŸŒ… ๐ŸŒ ๐Ÿ‘‰ ๐Ÿ’ก [๐Ÿ”ฐ - ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿฆฎ](tutorial/index.md){.internal-link target=_blank}.
!!! tip
Pydantic โœ”๏ธ ๐ŸŽ ๐ŸŽญ ๐Ÿ•โ” ๐Ÿ‘† โš™๏ธ `Optional` โš–๏ธ `Union[Something, None]` ๐Ÿต ๐Ÿ”ข ๐Ÿ’ฒ, ๐Ÿ‘† ๐Ÿ’ช โœ ๐ŸŒ… ๐Ÿ”ƒ โšซ๏ธ Pydantic ๐Ÿฉบ ๐Ÿ”ƒ <a href="https://pydantic-docs.helpmanual.io/usage/models/#required-optional-fields" class="external-link" target="_blank">โœ” ๐Ÿ“ฆ ๐Ÿ‘</a>.
## ๐Ÿ†Ž ๐Ÿ”‘ **FastAPI**
**FastAPI** โœŠ ๐Ÿ“ˆ ๐Ÿ‘ซ ๐Ÿ†Ž ๐Ÿ”‘ ๐Ÿ“š ๐Ÿ‘œ.
โฎ๏ธ **FastAPI** ๐Ÿ‘† ๐Ÿ“ฃ ๐Ÿ”ข โฎ๏ธ ๐Ÿ†Ž ๐Ÿ”‘ &amp; ๐Ÿ‘† ๐Ÿคš:
* **๐Ÿ‘จโ€๐ŸŽจ ๐Ÿ•โ€๐Ÿฆบ**.
* **๐Ÿ†Ž โœ…**.
...and **FastAPI** uses the same declarations :
* **๐Ÿ”ฌ ๐Ÿ“„**: โšช๏ธโžก๏ธ ๐Ÿ“จ โžก ๐Ÿ”ข, ๐Ÿ”ข ๐Ÿ”ข, ๐ŸŽš, ๐Ÿ’ช, ๐Ÿ”—, โ™’๏ธ.
* **๐Ÿ—œ ๐Ÿ’ฝ**: โšช๏ธโžก๏ธ ๐Ÿ“จ ๐Ÿšš ๐Ÿ†Ž.
* **โœ” ๐Ÿ’ฝ**: ๐Ÿ‘Ÿ โšช๏ธโžก๏ธ ๐Ÿ”  ๐Ÿ“จ:
* ๐Ÿญ **๐Ÿง โŒ** ๐Ÿ“จ ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ•โ” ๐Ÿ“Š โŒ.
* **๐Ÿ“„** ๐Ÿ› ๏ธ โš™๏ธ ๐Ÿ—„:
* โ” โคด๏ธ โš™๏ธ ๐Ÿง ๐ŸŽ“ ๐Ÿงพ ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ”ข.
๐Ÿ‘‰ 5๏ธโƒฃ๐Ÿ“† ๐ŸŒ ๐Ÿ”Š ๐Ÿ“. ๐Ÿšซ ๐Ÿ˜Ÿ. ๐Ÿ‘† ๐Ÿ”œ ๐Ÿ‘€ ๐ŸŒ ๐Ÿ‘‰ ๐ŸŽฏ [๐Ÿ”ฐ - ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿฆฎ](tutorial/index.md){.internal-link target=_blank}.
โš  ๐Ÿ‘œ ๐Ÿ‘ˆ โš™๏ธ ๐Ÿฉ ๐Ÿ ๐Ÿ†Ž, ๐Ÿ‘ ๐Ÿฅ‰ (โ†ฉ๏ธ โŽ ๐ŸŒ– ๐ŸŽ“, ๐Ÿ‘จโ€๐ŸŽจ, โ™’๏ธ), **FastAPI** ๐Ÿ”œ ๐Ÿ“š ๐Ÿ‘ท ๐Ÿ‘†.
!!! info
๐Ÿšฅ ๐Ÿ‘† โช ๐Ÿšถ ๐Ÿ”˜ ๐ŸŒ ๐Ÿ”ฐ &amp; ๐Ÿ‘Ÿ ๐Ÿ”™ ๐Ÿ‘€ ๐ŸŒ… ๐Ÿ”ƒ ๐Ÿ†Ž, ๐Ÿ‘ โ„น <a href="https://mypy.readthedocs.io/en/latest/cheat_sheet_py3.html" class="external-link" target="_blank"> "๐ŸŽฎ ๐ŸŽผ" โšช๏ธโžก๏ธ `mypy`</a>.

102
docs/em/docs/tutorial/background-tasks.md

@ -0,0 +1,102 @@
# ๐Ÿ–ฅ ๐Ÿ“‹
๐Ÿ‘† ๐Ÿ’ช ๐Ÿ”ฌ ๐Ÿ–ฅ ๐Ÿ“‹ ๐Ÿƒ *โฎ๏ธ* ๐Ÿ›ฌ ๐Ÿ“จ.
๐Ÿ‘‰ โš  ๐Ÿ› ๏ธ ๐Ÿ‘ˆ ๐Ÿ’ช ๐Ÿ”จ โฎ๏ธ ๐Ÿ“จ, โœ‹๏ธ ๐Ÿ‘ˆ ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿšซ ๐Ÿค™ โœ”๏ธ โŒ› ๐Ÿ› ๏ธ ๐Ÿ โญ ๐Ÿ“จ ๐Ÿ“จ.
๐Ÿ‘‰ ๐Ÿ”Œ, ๐Ÿ–ผ:
* ๐Ÿ“ง ๐Ÿ“จ ๐Ÿ“จ โฎ๏ธ ๐ŸŽญ ๐ŸŽฏ:
* ๐Ÿ”— ๐Ÿ“ง ๐Ÿ’ฝ &amp; ๐Ÿ“จ ๐Ÿ“ง ๐Ÿ˜‘ "๐ŸŒ" (๐Ÿ“š ๐Ÿฅˆ), ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ“จ ๐Ÿ“จ โ–ถ๏ธ๏ธ โ†–๏ธ &amp; ๐Ÿ“จ ๐Ÿ“ง ๐Ÿ“จ ๐Ÿ–ฅ.
* ๐Ÿญ ๐Ÿ’ฝ:
* ๐Ÿ–ผ, โžก๏ธ ๐Ÿ’ฌ ๐Ÿ‘† ๐Ÿ“จ ๐Ÿ“ ๐Ÿ‘ˆ ๐Ÿ”œ ๐Ÿšถ ๐Ÿ”˜ ๐ŸŒ ๐Ÿ› ๏ธ, ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ“จ ๐Ÿ“จ "๐Ÿšซ" (๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ” 2๏ธโƒฃ0๏ธโƒฃ2๏ธโƒฃ) &amp; ๐Ÿ› ๏ธ โšซ๏ธ ๐Ÿ–ฅ.
## โš™๏ธ `BackgroundTasks`
๐Ÿฅ‡, ๐Ÿ—„ `BackgroundTasks` &amp; ๐Ÿ”ฌ ๐Ÿ”ข ๐Ÿ‘† *โžก ๐Ÿ› ๏ธ ๐Ÿ”ข* โฎ๏ธ ๐Ÿ†Ž ๐Ÿ“„ `BackgroundTasks`:
```Python hl_lines="1 13"
{!../../../docs_src/background_tasks/tutorial001.py!}
```
**FastAPI** ๐Ÿ”œ โœ ๐ŸŽš ๐Ÿ†Ž `BackgroundTasks` ๐Ÿ‘† &amp; ๐Ÿšถโ€โ™€๏ธ โšซ๏ธ ๐Ÿ‘ˆ ๐Ÿ”ข.
## โœ ๐Ÿ“‹ ๐Ÿ”ข
โœ ๐Ÿ”ข ๐Ÿƒ ๐Ÿ–ฅ ๐Ÿ“‹.
โšซ๏ธ ๐Ÿฉ ๐Ÿ”ข ๐Ÿ‘ˆ ๐Ÿ’ช ๐Ÿ“จ ๐Ÿ”ข.
โšซ๏ธ ๐Ÿ’ช `async def` โš–๏ธ ๐Ÿ˜ `def` ๐Ÿ”ข, **FastAPI** ๐Ÿ”œ ๐Ÿ’ญ โ” ๐Ÿต โšซ๏ธ โ˜‘.
๐Ÿ‘‰ ๐Ÿ’ผ, ๐Ÿ“‹ ๐Ÿ”ข ๐Ÿ”œ โœ ๐Ÿ“ (โš– ๐Ÿ“จ ๐Ÿ“ง).
&amp; โœ ๐Ÿ› ๏ธ ๐Ÿšซ โš™๏ธ `async` &amp; `await`, ๐Ÿ‘ฅ ๐Ÿ”ฌ ๐Ÿ”ข โฎ๏ธ ๐Ÿ˜ `def`:
```Python hl_lines="6-9"
{!../../../docs_src/background_tasks/tutorial001.py!}
```
## ๐Ÿšฎ ๐Ÿ–ฅ ๐Ÿ“‹
๐Ÿ”˜ ๐Ÿ‘† *โžก ๐Ÿ› ๏ธ ๐Ÿ”ข*, ๐Ÿšถโ€โ™€๏ธ ๐Ÿ‘† ๐Ÿ“‹ ๐Ÿ”ข *๐Ÿ–ฅ ๐Ÿ“‹* ๐ŸŽš โฎ๏ธ ๐Ÿ‘ฉโ€๐Ÿ”ฌ `.add_task()`:
```Python hl_lines="14"
{!../../../docs_src/background_tasks/tutorial001.py!}
```
`.add_task()` ๐Ÿ“จ โŒ:
* ๐Ÿ“‹ ๐Ÿ”ข ๐Ÿƒ ๐Ÿ–ฅ (`write_notification`).
* ๐Ÿ™† ๐Ÿ” โŒ ๐Ÿ‘ˆ ๐Ÿ”œ ๐Ÿšถโ€โ™€๏ธ ๐Ÿ“‹ ๐Ÿ”ข โœ” (`email`).
* ๐Ÿ™† ๐Ÿ‡จ๐Ÿ‡ป โŒ ๐Ÿ‘ˆ ๐Ÿ”œ ๐Ÿšถโ€โ™€๏ธ ๐Ÿ“‹ ๐Ÿ”ข (`message="some notification"`).
## ๐Ÿ”— ๐Ÿ’‰
โš™๏ธ `BackgroundTasks` ๐Ÿ‘ท โฎ๏ธ ๐Ÿ”— ๐Ÿ’‰ โš™๏ธ, ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ“ฃ ๐Ÿ”ข ๐Ÿ†Ž `BackgroundTasks` ๐Ÿ’— ๐ŸŽš: *โžก ๐Ÿ› ๏ธ ๐Ÿ”ข*, ๐Ÿ”— (โ˜‘), ๐ŸŽง-๐Ÿ”—, โ™’๏ธ.
**FastAPI** ๐Ÿ’ญ โšซ๏ธโ” ๐Ÿ”  ๐Ÿ’ผ &amp; โ” ๐Ÿค-โš™๏ธ ๐ŸŽ ๐ŸŽš, ๐Ÿ‘ˆ ๐ŸŒ ๐Ÿ–ฅ ๐Ÿ“‹ ๐Ÿ”— ๐Ÿ‘ฏโ€โ™‚๏ธ &amp; ๐Ÿƒ ๐Ÿ–ฅ โฎ๏ธ:
=== "๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="13 15 22 25"
{!> ../../../docs_src/background_tasks/tutorial002.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.1๏ธโƒฃ0๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="11 13 20 23"
{!> ../../../docs_src/background_tasks/tutorial002_py310.py!}
```
๐Ÿ‘‰ ๐Ÿ–ผ, ๐Ÿ“ง ๐Ÿ”œ โœ `log.txt` ๐Ÿ“ *โฎ๏ธ* ๐Ÿ“จ ๐Ÿ“จ.
๐Ÿšฅ ๐Ÿ“ค ๐Ÿ”ข ๐Ÿ“จ, โšซ๏ธ ๐Ÿ”œ โœ ๐Ÿ•น ๐Ÿ–ฅ ๐Ÿ“‹.
&amp; โคด๏ธ โž•1๏ธโƒฃ ๐Ÿ–ฅ ๐Ÿ“‹ ๐Ÿ— *โžก ๐Ÿ› ๏ธ ๐Ÿ”ข* ๐Ÿ”œ โœ ๐Ÿ“ง โš™๏ธ `email` โžก ๐Ÿ”ข.
## ๐Ÿ“ก โ„น
๐ŸŽ“ `BackgroundTasks` ๐Ÿ‘Ÿ ๐Ÿ”— โšช๏ธโžก๏ธ <a href="https://www.starlette.io/background/" class="external-link" target="_blank">`starlette.background`</a>.
โšซ๏ธ ๐Ÿ—„/๐Ÿ”Œ ๐Ÿ”— ๐Ÿ”˜ FastAPI ๐Ÿ‘ˆ ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ—„ โšซ๏ธ โšช๏ธโžก๏ธ `fastapi` &amp; โŽ ๐Ÿ˜ซ ๐Ÿ—„ ๐ŸŽ› `BackgroundTask` (๐Ÿต `s` ๐Ÿ”š) โšช๏ธโžก๏ธ `starlette.background`.
๐Ÿ•ด โš™๏ธ `BackgroundTasks` (&amp; ๐Ÿšซ `BackgroundTask`), โšซ๏ธ โคด๏ธ ๐Ÿ’ช โš™๏ธ โšซ๏ธ *โžก ๐Ÿ› ๏ธ ๐Ÿ”ข* ๐Ÿ”ข &amp; โœ”๏ธ **FastAPI** ๐Ÿต ๐ŸŽ‚ ๐Ÿ‘†, ๐Ÿ’– ๐Ÿ•โ” โš™๏ธ `Request` ๐ŸŽš ๐Ÿ”—.
โšซ๏ธ ๐Ÿ’ช โš™๏ธ `BackgroundTask` ๐Ÿ˜ž FastAPI, โœ‹๏ธ ๐Ÿ‘† โœ”๏ธ โœ ๐ŸŽš ๐Ÿ‘† ๐Ÿ“Ÿ &amp; ๐Ÿ“จ ๐Ÿ’ƒ `Response` ๐Ÿ”Œ โšซ๏ธ.
๐Ÿ‘† ๐Ÿ’ช ๐Ÿ‘€ ๐ŸŒ– โ„น <a href="https://www.starlette.io/background/" class="external-link" target="_blank">๐Ÿ’ƒ ๐Ÿ›‚ ๐Ÿฉบ ๐Ÿ–ฅ ๐Ÿ“‹</a>.
## โš 
๐Ÿšฅ ๐Ÿ‘† ๐Ÿ’ช ๐ŸŽญ ๐Ÿ‹๏ธ ๐Ÿ–ฅ ๐Ÿ“Š &amp; ๐Ÿ‘† ๐Ÿšซ ๐ŸŽฏ ๐Ÿ’ช โšซ๏ธ ๐Ÿƒ ๐ŸŽ ๐Ÿ› ๏ธ (๐Ÿ–ผ, ๐Ÿ‘† ๐Ÿšซ ๐Ÿ’ช ๐Ÿ’ฐ ๐Ÿ’พ, ๐Ÿ”ข, โ™’๏ธ), ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ’ฐ โšช๏ธโžก๏ธ โš™๏ธ ๐ŸŽ ๐Ÿฆ ๐Ÿงฐ ๐Ÿ’– <a href="https://docs.celeryq.dev" class="external-link" target="_blank">๐Ÿฅ’</a>.
๐Ÿ‘ซ ๐Ÿ˜‘ ๐Ÿšš ๐ŸŒ– ๐Ÿ— ๐Ÿ“ณ, ๐Ÿ“ง/๐Ÿ‘จโ€๐Ÿญ ๐Ÿ“ค ๐Ÿ‘จโ€๐Ÿ’ผ, ๐Ÿ’– โœณ โš–๏ธ โœณ, โœ‹๏ธ ๐Ÿ‘ซ โœ” ๐Ÿ‘† ๐Ÿƒ ๐Ÿ–ฅ ๐Ÿ“‹ ๐Ÿ’— ๐Ÿ› ๏ธ, &amp; โœด๏ธ, ๐Ÿ’— ๐Ÿ’ฝ.
๐Ÿ‘€ ๐Ÿ–ผ, โœ… [๐Ÿ— ๐Ÿš‚](../project-generation.md){.internal-link target=_blank}, ๐Ÿ‘ซ ๐ŸŒ ๐Ÿ”Œ ๐Ÿฅ’ โช ๐Ÿ“ถ.
โœ‹๏ธ ๐Ÿšฅ ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ” ๐Ÿ”ข &amp; ๐ŸŽš โšช๏ธโžก๏ธ ๐ŸŽ **FastAPI** ๐Ÿ“ฑ, โš–๏ธ ๐Ÿ‘† ๐Ÿ’ช ๐ŸŽญ ๐Ÿคช ๐Ÿ–ฅ ๐Ÿ“‹ (๐Ÿ’– ๐Ÿ“จ ๐Ÿ“ง ๐Ÿ“จ), ๐Ÿ‘† ๐Ÿ’ช ๐ŸŽฏ โš™๏ธ `BackgroundTasks`.
## ๐ŸŒƒ
๐Ÿ—„ &amp; โš™๏ธ `BackgroundTasks` โฎ๏ธ ๐Ÿ”ข *โžก ๐Ÿ› ๏ธ ๐Ÿ”ข* &amp; ๐Ÿ”— ๐Ÿšฎ ๐Ÿ–ฅ ๐Ÿ“‹.

488
docs/em/docs/tutorial/bigger-applications.md

@ -0,0 +1,488 @@
# ๐Ÿฆ ๐Ÿˆธ - ๐Ÿ’— ๐Ÿ“
๐Ÿšฅ ๐Ÿ‘† ๐Ÿ— ๐Ÿˆธ โš–๏ธ ๐Ÿ•ธ ๐Ÿ› ๏ธ, โšซ๏ธ ๐Ÿ›Ž ๐Ÿ’ผ ๐Ÿ‘ˆ ๐Ÿ‘† ๐Ÿ’ช ๐Ÿšฎ ๐ŸŒ ๐Ÿ”› ๐Ÿ‘ ๐Ÿ“.
**FastAPI** ๐Ÿšš ๐Ÿช ๐Ÿงฐ ๐Ÿ“Š ๐Ÿ‘† ๐Ÿˆธ โช ๐Ÿšง ๐ŸŒ ๐Ÿ’ช.
!!! info
๐Ÿšฅ ๐Ÿ‘† ๐Ÿ‘Ÿ โšช๏ธโžก๏ธ ๐Ÿบ, ๐Ÿ‘‰ ๐Ÿ”œ ๐ŸŒ“ ๐Ÿบ ๐Ÿ“—.
## ๐Ÿ–ผ ๐Ÿ“ ๐Ÿ“Š
โžก๏ธ ๐Ÿ’ฌ ๐Ÿ‘† โœ”๏ธ ๐Ÿ“ ๐Ÿ“Š ๐Ÿ’– ๐Ÿ‘‰:
```
.
โ”œโ”€โ”€ app
โ”‚ย ย  โ”œโ”€โ”€ __init__.py
โ”‚ย ย  โ”œโ”€โ”€ main.py
โ”‚ย ย  โ”œโ”€โ”€ dependencies.py
โ”‚ย ย  โ””โ”€โ”€ routers
โ”‚ย ย  โ”‚ โ”œโ”€โ”€ __init__.py
โ”‚ย ย  โ”‚ โ”œโ”€โ”€ items.py
โ”‚ย ย  โ”‚ โ””โ”€โ”€ users.py
โ”‚ย ย  โ””โ”€โ”€ internal
โ”‚ย ย  โ”œโ”€โ”€ __init__.py
โ”‚ย ย  โ””โ”€โ”€ admin.py
```
!!! tip
๐Ÿ“ค ๐Ÿ“š `__init__.py` ๐Ÿ“: 1๏ธโƒฃ ๐Ÿ”  ๐Ÿ“ โš–๏ธ ๐Ÿ“.
๐Ÿ‘‰ โšซ๏ธโ” โœ” ๐Ÿญ ๐Ÿ“Ÿ โšช๏ธโžก๏ธ 1๏ธโƒฃ ๐Ÿ“ ๐Ÿ”˜ โž•1๏ธโƒฃ.
๐Ÿ–ผ, `app/main.py` ๐Ÿ‘† ๐Ÿ’ช โœ”๏ธ โธ ๐Ÿ’–:
```
from app.routers import items
```
* `app` ๐Ÿ“ ๐Ÿ”Œ ๐ŸŒ. &amp; โšซ๏ธ โœ”๏ธ ๐Ÿ› ๐Ÿ“ `app/__init__.py`, โšซ๏ธ "๐Ÿ ๐Ÿ“ฆ" (๐Ÿ—ƒ "๐Ÿ ๐Ÿ•น"): `app`.
* โšซ๏ธ ๐Ÿ”Œ `app/main.py` ๐Ÿ“. โšซ๏ธ ๐Ÿ”˜ ๐Ÿ ๐Ÿ“ฆ (๐Ÿ“ โฎ๏ธ ๐Ÿ“ `__init__.py`), โšซ๏ธ "๐Ÿ•น" ๐Ÿ‘ˆ ๐Ÿ“ฆ: `app.main`.
* ๐Ÿ“ค `app/dependencies.py` ๐Ÿ“, ๐Ÿ’– `app/main.py`, โšซ๏ธ "๐Ÿ•น": `app.dependencies`.
* ๐Ÿ“ค ๐Ÿ“ `app/routers/` โฎ๏ธ โž•1๏ธโƒฃ ๐Ÿ“ `__init__.py`, โšซ๏ธ "๐Ÿ ๐Ÿ“ฆ": `app.routers`.
* ๐Ÿ“ `app/routers/items.py` ๐Ÿ”˜ ๐Ÿ“ฆ, `app/routers/`,, โšซ๏ธ ๐Ÿ”: `app.routers.items`.
* ๐ŸŽ โฎ๏ธ `app/routers/users.py`, โšซ๏ธ โž•1๏ธโƒฃ ๐Ÿ”: `app.routers.users`.
* ๐Ÿ“ค ๐Ÿ“ `app/internal/` โฎ๏ธ โž•1๏ธโƒฃ ๐Ÿ“ `__init__.py`, โšซ๏ธ โž•1๏ธโƒฃ "๐Ÿ ๐Ÿ“ฆ": `app.internal`.
* &amp; ๐Ÿ“ `app/internal/admin.py` โž•1๏ธโƒฃ ๐Ÿ”: `app.internal.admin`.
<img src="/img/tutorial/bigger-applications/package.svg">
๐ŸŽ ๐Ÿ“ ๐Ÿ“Š โฎ๏ธ ๐Ÿค:
```
.
โ”œโ”€โ”€ app # "app" is a Python package
โ”‚ย ย  โ”œโ”€โ”€ __init__.py # this file makes "app" a "Python package"
โ”‚ย ย  โ”œโ”€โ”€ main.py # "main" module, e.g. import app.main
โ”‚ย ย  โ”œโ”€โ”€ dependencies.py # "dependencies" module, e.g. import app.dependencies
โ”‚ย ย  โ””โ”€โ”€ routers # "routers" is a "Python subpackage"
โ”‚ย ย  โ”‚ โ”œโ”€โ”€ __init__.py # makes "routers" a "Python subpackage"
โ”‚ย ย  โ”‚ โ”œโ”€โ”€ items.py # "items" submodule, e.g. import app.routers.items
โ”‚ย ย  โ”‚ โ””โ”€โ”€ users.py # "users" submodule, e.g. import app.routers.users
โ”‚ย ย  โ””โ”€โ”€ internal # "internal" is a "Python subpackage"
โ”‚ย ย  โ”œโ”€โ”€ __init__.py # makes "internal" a "Python subpackage"
โ”‚ย ย  โ””โ”€โ”€ admin.py # "admin" submodule, e.g. import app.internal.admin
```
## `APIRouter`
โžก๏ธ ๐Ÿ’ฌ ๐Ÿ“ ๐Ÿ’ก ๐Ÿšš ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ” `/app/routers/users.py`.
๐Ÿ‘† ๐Ÿ’š โœ”๏ธ *โžก ๐Ÿ› ๏ธ* ๐Ÿ”— ๐Ÿ‘† ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ‘ฝ โšช๏ธโžก๏ธ ๐ŸŽ‚ ๐Ÿ“Ÿ, ๐Ÿšง โšซ๏ธ ๐Ÿ—.
โœ‹๏ธ โšซ๏ธ ๐Ÿ• ๐ŸŽ **FastAPI** ๐Ÿˆธ/๐Ÿ•ธ ๐Ÿ› ๏ธ (โšซ๏ธ ๐Ÿ• ๐ŸŽ "๐Ÿ ๐Ÿ“ฆ").
๐Ÿ‘† ๐Ÿ’ช โœ *โžก ๐Ÿ› ๏ธ* ๐Ÿ‘ˆ ๐Ÿ•น โš™๏ธ `APIRouter`.
### ๐Ÿ—„ `APIRouter`
๐Ÿ‘† ๐Ÿ—„ โšซ๏ธ &amp; โœ "๐Ÿ‘" ๐ŸŽ ๐ŸŒŒ ๐Ÿ‘† ๐Ÿ”œ โฎ๏ธ ๐ŸŽ“ `FastAPI`:
```Python hl_lines="1 3"
{!../../../docs_src/bigger_applications/app/routers/users.py!}
```
### *โžก ๐Ÿ› ๏ธ* โฎ๏ธ `APIRouter`
&amp; โคด๏ธ ๐Ÿ‘† โš™๏ธ โšซ๏ธ ๐Ÿ“ฃ ๐Ÿ‘† *โžก ๐Ÿ› ๏ธ*.
โš™๏ธ โšซ๏ธ ๐ŸŽ ๐ŸŒŒ ๐Ÿ‘† ๐Ÿ”œ โš™๏ธ `FastAPI` ๐ŸŽ“:
```Python hl_lines="6 11 16"
{!../../../docs_src/bigger_applications/app/routers/users.py!}
```
๐Ÿ‘† ๐Ÿ’ช ๐Ÿ’ญ `APIRouter` "๐Ÿฉ `FastAPI`" ๐ŸŽ“.
๐ŸŒ ๐ŸŽ ๐ŸŽ› ๐Ÿ•โ€๐Ÿฆบ.
๐ŸŒ ๐ŸŽ `parameters`, `responses`, `dependencies`, `tags`, โ™’๏ธ.
!!! tip
๐Ÿ‘‰ ๐Ÿ–ผ, ๐Ÿ”ข ๐Ÿค™ `router`, โœ‹๏ธ ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ“› โšซ๏ธ ๐Ÿ‘ ๐Ÿ‘† ๐Ÿ’š.
๐Ÿ‘ฅ ๐Ÿ”œ ๐Ÿ”Œ ๐Ÿ‘‰ `APIRouter` ๐Ÿ‘‘ `FastAPI` ๐Ÿ“ฑ, โœ‹๏ธ ๐Ÿฅ‡, โžก๏ธ โœ… ๐Ÿ”— &amp; โž•1๏ธโƒฃ `APIRouter`.
## ๐Ÿ”—
๐Ÿ‘ฅ ๐Ÿ‘€ ๐Ÿ‘ˆ ๐Ÿ‘ฅ ๐Ÿ”œ ๐Ÿ’ช ๐Ÿ”— โš™๏ธ ๐Ÿ“š ๐Ÿฅ‰ ๐Ÿˆธ.
๐Ÿ‘ฅ ๐Ÿšฎ ๐Ÿ‘ซ ๐Ÿ‘ซ ๐Ÿ‘ `dependencies` ๐Ÿ•น (`app/dependencies.py`).
๐Ÿ‘ฅ ๐Ÿ”œ ๐Ÿ”œ โš™๏ธ ๐Ÿ™… ๐Ÿ”— โœ ๐Ÿ›ƒ `X-Token` ๐ŸŽš:
```Python hl_lines="1 4-6"
{!../../../docs_src/bigger_applications/app/dependencies.py!}
```
!!! tip
๐Ÿ‘ฅ โš™๏ธ ๐Ÿ’ญ ๐ŸŽš ๐Ÿ“‰ ๐Ÿ‘‰ ๐Ÿ–ผ.
โœ‹๏ธ ๐ŸŽฐ ๐Ÿ’ผ ๐Ÿ‘† ๐Ÿ”œ ๐Ÿคš ๐Ÿ‘ ๐Ÿ โš™๏ธ ๐Ÿ› ๏ธ [๐Ÿ’‚โ€โ™‚ ๐Ÿš™](./security/index.md){.internal-link target=_blank}.
## โž•1๏ธโƒฃ ๐Ÿ•น โฎ๏ธ `APIRouter`
โžก๏ธ ๐Ÿ’ฌ ๐Ÿ‘† โœ”๏ธ ๐Ÿ”— ๐Ÿ’ก ๐Ÿšš "๐Ÿฌ" โšช๏ธโžก๏ธ ๐Ÿ‘† ๐Ÿˆธ ๐Ÿ•น `app/routers/items.py`.
๐Ÿ‘† โœ”๏ธ *โžก ๐Ÿ› ๏ธ* :
* `/items/`
* `/items/{item_id}`
โšซ๏ธ ๐ŸŒ ๐ŸŽ ๐Ÿ“Š โฎ๏ธ `app/routers/users.py`.
โœ‹๏ธ ๐Ÿ‘ฅ ๐Ÿ’š ๐Ÿ™ƒ &amp; ๐Ÿ“‰ ๐Ÿ“Ÿ ๐Ÿ–.
๐Ÿ‘ฅ ๐Ÿ’ญ ๐ŸŒ *โžก ๐Ÿ› ๏ธ* ๐Ÿ‘‰ ๐Ÿ•น โœ”๏ธ ๐ŸŽ:
* โžก `prefix`: `/items`.
* `tags`: (1๏ธโƒฃ ๐Ÿ”–: `items`).
* โž• `responses`.
* `dependencies`: ๐Ÿ‘ซ ๐ŸŒ ๐Ÿ’ช ๐Ÿ‘ˆ `X-Token` ๐Ÿ”— ๐Ÿ‘ฅ โœ.
, โ†ฉ๏ธ โŽ ๐ŸŒ ๐Ÿ‘ˆ ๐Ÿ”  *โžก ๐Ÿ› ๏ธ*, ๐Ÿ‘ฅ ๐Ÿ’ช ๐Ÿšฎ โšซ๏ธ `APIRouter`.
```Python hl_lines="5-10 16 21"
{!../../../docs_src/bigger_applications/app/routers/items.py!}
```
โžก ๐Ÿ”  *โžก ๐Ÿ› ๏ธ* โœ”๏ธ โ–ถ๏ธ โฎ๏ธ `/`, ๐Ÿ’–:
```Python hl_lines="1"
@router.get("/{item_id}")
async def read_item(item_id: str):
...
```
...๐Ÿ”ก ๐Ÿ”œ ๐Ÿšซ ๐Ÿ”Œ ๐Ÿ `/`.
, ๐Ÿ”ก ๐Ÿ‘‰ ๐Ÿ’ผ `/items`.
๐Ÿ‘ฅ ๐Ÿ’ช ๐Ÿšฎ ๐Ÿ“‡ `tags` &amp; โž• `responses` ๐Ÿ‘ˆ ๐Ÿ”œ โœ” ๐ŸŒ *โžก ๐Ÿ› ๏ธ* ๐Ÿ”Œ ๐Ÿ‘‰ ๐Ÿ“ป.
&amp; ๐Ÿ‘ฅ ๐Ÿ’ช ๐Ÿšฎ ๐Ÿ“‡ `dependencies` ๐Ÿ‘ˆ ๐Ÿ”œ ๐Ÿšฎ ๐ŸŒ *โžก ๐Ÿ› ๏ธ* ๐Ÿ“ป &amp; ๐Ÿ”œ ๐Ÿ› ๏ธ/โŽ ๐Ÿ”  ๐Ÿ“จ โš’ ๐Ÿ‘ซ.
!!! tip
๐Ÿ—’ ๐Ÿ‘ˆ, ๐ŸŒ… ๐Ÿ’– [๐Ÿ”— *โžก ๐Ÿ› ๏ธ ๐Ÿ‘จโ€๐ŸŽจ*](dependencies/dependencies-in-path-operation-decorators.md){.internal-link target=_blank}, ๐Ÿ™…โ€โ™‚ ๐Ÿ’ฒ ๐Ÿ”œ ๐Ÿšถโ€โ™€๏ธ ๐Ÿ‘† *โžก ๐Ÿ› ๏ธ ๐Ÿ”ข*.
๐Ÿ”š ๐Ÿ ๐Ÿ‘ˆ ๐Ÿฌ โžก ๐Ÿ”œ:
* `/items/`
* `/items/{item_id}`
...๐Ÿ‘ฅ ๐ŸŽฏ.
* ๐Ÿ‘ซ ๐Ÿ”œ โ„ข โฎ๏ธ ๐Ÿ“‡ ๐Ÿ”– ๐Ÿ‘ˆ ๐Ÿ”Œ ๐Ÿ‘ ๐ŸŽป `"items"`.
* ๐Ÿ‘ซ "๐Ÿ”–" โœด๏ธ โš  ๐Ÿง ๐ŸŽ“ ๐Ÿงพ โš™๏ธ (โš™๏ธ ๐Ÿ—„).
* ๐ŸŒ ๐Ÿ‘ซ ๐Ÿ”œ ๐Ÿ”Œ ๐Ÿ” `responses`.
* ๐ŸŒ ๐Ÿ‘ซ *โžก ๐Ÿ› ๏ธ* ๐Ÿ”œ โœ”๏ธ ๐Ÿ“‡ `dependencies` ๐Ÿ”ฌ/๐Ÿ› ๏ธ โญ ๐Ÿ‘ซ.
* ๐Ÿšฅ ๐Ÿ‘† ๐Ÿ“ฃ ๐Ÿ”— ๐ŸŽฏ *โžก ๐Ÿ› ๏ธ*, **๐Ÿ‘ซ ๐Ÿ”œ ๐Ÿ› ๏ธ ๐Ÿ’โ€โ™‚๏ธ**.
* ๐Ÿ“ป ๐Ÿ”— ๐Ÿ› ๏ธ ๐Ÿฅ‡, โคด๏ธ [`dependencies` ๐Ÿ‘จโ€๐ŸŽจ](dependencies/dependencies-in-path-operation-decorators.md){.internal-link target=_blank}, &amp; โคด๏ธ ๐Ÿ˜ ๐Ÿ”ข ๐Ÿ”—.
* ๐Ÿ‘† ๐Ÿ’ช ๐Ÿšฎ [`Security` ๐Ÿ”— โฎ๏ธ `scopes`](../advanced/security/oauth2-scopes.md){.internal-link target=_blank}.
!!! tip
โœ”๏ธ `dependencies` `APIRouter` ๐Ÿ’ช โš™๏ธ, ๐Ÿ–ผ, ๐Ÿšš ๐Ÿค ๐ŸŽ‚ ๐Ÿ‘ช *โžก ๐Ÿ› ๏ธ*. ๐Ÿšฅ ๐Ÿ”— ๐Ÿšซ ๐Ÿšฎ ๐Ÿ“ฆ ๐Ÿ”  1๏ธโƒฃ ๐Ÿ‘ซ.
!!! check
`prefix`, `tags`, `responses`, &amp; `dependencies` ๐Ÿ”ข (๐Ÿ“š ๐ŸŽ ๐Ÿ’ผ) โš’ โšช๏ธโžก๏ธ **FastAPI** โ„น ๐Ÿ‘† โŽ ๐Ÿ“Ÿ โŽ.
### ๐Ÿ—„ ๐Ÿ”—
๐Ÿ‘‰ ๐Ÿ“Ÿ ๐Ÿ‘จโ€โคโ€๐Ÿ‘จ ๐Ÿ•น `app.routers.items`, ๐Ÿ“ `app/routers/items.py`.
&amp; ๐Ÿ‘ฅ ๐Ÿ’ช ๐Ÿคš ๐Ÿ”— ๐Ÿ”ข โšช๏ธโžก๏ธ ๐Ÿ•น `app.dependencies`, ๐Ÿ“ `app/dependencies.py`.
๐Ÿ‘ฅ โš™๏ธ โš– ๐Ÿ—„ โฎ๏ธ `..` ๐Ÿ”—:
```Python hl_lines="3"
{!../../../docs_src/bigger_applications/app/routers/items.py!}
```
#### โ” โš– ๐Ÿ—„ ๐Ÿ‘ท
!!! tip
๐Ÿšฅ ๐Ÿ‘† ๐Ÿ’ญ ๐Ÿ‘Œ โ” ๐Ÿ—„ ๐Ÿ‘ท, ๐Ÿ˜ฃ โญ ๐Ÿ“„ ๐Ÿ”›.
๐Ÿ‘ โฃ `.`, ๐Ÿ’–:
```Python
from .dependencies import get_token_header
```
๐Ÿ”œ โ›“:
* โ–ถ๏ธ ๐ŸŽ ๐Ÿ“ฆ ๐Ÿ‘ˆ ๐Ÿ‘‰ ๐Ÿ•น (๐Ÿ“ `app/routers/items.py`) ๐Ÿ–– (๐Ÿ“ `app/routers/`)...
* ๐Ÿ”Ž ๐Ÿ•น `dependencies` (๐Ÿ‘ฝ ๐Ÿ“ `app/routers/dependencies.py`)...
* &amp; โšช๏ธโžก๏ธ โšซ๏ธ, ๐Ÿ—„ ๐Ÿ”ข `get_token_header`.
โœ‹๏ธ ๐Ÿ‘ˆ ๐Ÿ“ ๐Ÿšซ ๐Ÿ”€, ๐Ÿ‘† ๐Ÿ”— ๐Ÿ“ `app/dependencies.py`.
๐Ÿ’ญ โ” ๐Ÿ‘† ๐Ÿ“ฑ/๐Ÿ“ ๐Ÿ“Š ๐Ÿ‘€ ๐Ÿ’–:
<img src="/img/tutorial/bigger-applications/package.svg">
---
2๏ธโƒฃ โฃ `..`, ๐Ÿ’–:
```Python
from ..dependencies import get_token_header
```
โ›“:
* โ–ถ๏ธ ๐ŸŽ ๐Ÿ“ฆ ๐Ÿ‘ˆ ๐Ÿ‘‰ ๐Ÿ•น (๐Ÿ“ `app/routers/items.py`) ๐Ÿ–– (๐Ÿ“ `app/routers/`)...
* ๐Ÿšถ ๐Ÿ‘ช ๐Ÿ“ฆ (๐Ÿ“ `app/`)...
* &amp; ๐Ÿ“ค, ๐Ÿ”Ž ๐Ÿ•น `dependencies` (๐Ÿ“ `app/dependencies.py`)...
* &amp; โšช๏ธโžก๏ธ โšซ๏ธ, ๐Ÿ—„ ๐Ÿ”ข `get_token_header`.
๐Ÿ‘ˆ ๐Ÿ‘ท โ˜‘ โ— ๐Ÿ‘ถ
---
๐ŸŽ ๐ŸŒŒ, ๐Ÿšฅ ๐Ÿ‘ฅ โœ”๏ธ โš™๏ธ 3๏ธโƒฃ โฃ `...`, ๐Ÿ’–:
```Python
from ...dependencies import get_token_header
```
that ๐Ÿ”œ โ›“:
* โ–ถ๏ธ ๐ŸŽ ๐Ÿ“ฆ ๐Ÿ‘ˆ ๐Ÿ‘‰ ๐Ÿ•น (๐Ÿ“ `app/routers/items.py`) ๐Ÿ–– (๐Ÿ“ `app/routers/`)...
* ๐Ÿšถ ๐Ÿ‘ช ๐Ÿ“ฆ (๐Ÿ“ `app/`)...
* โคด๏ธ ๐Ÿšถ ๐Ÿ‘ช ๐Ÿ‘ˆ ๐Ÿ“ฆ (๐Ÿ“ค ๐Ÿ™…โ€โ™‚ ๐Ÿ‘ช ๐Ÿ“ฆ, `app` ๐Ÿ” ๐ŸŽš ๐Ÿ‘ถ)...
* &amp; ๐Ÿ“ค, ๐Ÿ”Ž ๐Ÿ•น `dependencies` (๐Ÿ“ `app/dependencies.py`)...
* &amp; โšช๏ธโžก๏ธ โšซ๏ธ, ๐Ÿ—„ ๐Ÿ”ข `get_token_header`.
๐Ÿ‘ˆ ๐Ÿ”œ ๐Ÿ”— ๐Ÿ“ฆ ๐Ÿ”› `app/`, โฎ๏ธ ๐Ÿšฎ ๐Ÿ‘ ๐Ÿ“ `__init__.py`, โ™’๏ธ. โœ‹๏ธ ๐Ÿ‘ฅ ๐Ÿšซ โœ”๏ธ ๐Ÿ‘ˆ. , ๐Ÿ‘ˆ ๐Ÿ”œ ๐Ÿšฎ โŒ ๐Ÿ‘† ๐Ÿ–ผ. ๐Ÿ‘ถ
โœ‹๏ธ ๐Ÿ”œ ๐Ÿ‘† ๐Ÿ’ญ โ” โšซ๏ธ ๐Ÿ‘ท, ๐Ÿ‘† ๐Ÿ’ช โš™๏ธ โš– ๐Ÿ—„ ๐Ÿ‘† ๐Ÿ‘ ๐Ÿ“ฑ ๐Ÿ™…โ€โ™‚ ๐Ÿค” โ” ๐Ÿ— ๐Ÿ‘ซ. ๐Ÿ‘ถ
### ๐Ÿšฎ ๐Ÿ›ƒ `tags`, `responses`, &amp; `dependencies`
๐Ÿ‘ฅ ๐Ÿšซ โŽ ๐Ÿ”ก `/items` ๐Ÿšซ `tags=["items"]` ๐Ÿ”  *โžก ๐Ÿ› ๏ธ* โ†ฉ๏ธ ๐Ÿ‘ฅ ๐Ÿšฎ ๐Ÿ‘ซ `APIRouter`.
โœ‹๏ธ ๐Ÿ‘ฅ ๐Ÿ’ช ๐Ÿšฎ _๐ŸŒ…_ `tags` ๐Ÿ‘ˆ ๐Ÿ”œ โœ” ๐ŸŽฏ *โžก ๐Ÿ› ๏ธ*, &amp; โž• `responses` ๐ŸŽฏ ๐Ÿ‘ˆ *โžก ๐Ÿ› ๏ธ*:
```Python hl_lines="30-31"
{!../../../docs_src/bigger_applications/app/routers/items.py!}
```
!!! tip
๐Ÿ‘‰ ๐Ÿ โžก ๐Ÿ› ๏ธ ๐Ÿ”œ โœ”๏ธ ๐ŸŒ€ ๐Ÿ”–: `["items", "custom"]`.
&amp; โšซ๏ธ ๐Ÿ”œ โœ”๏ธ ๐Ÿ‘ฏโ€โ™‚๏ธ ๐Ÿ“จ ๐Ÿงพ, 1๏ธโƒฃ `404` &amp; 1๏ธโƒฃ `403`.
## ๐Ÿ‘‘ `FastAPI`
๐Ÿ”œ, โžก๏ธ ๐Ÿ‘€ ๐Ÿ•น `app/main.py`.
๐Ÿ“ฅ ๐ŸŒโ” ๐Ÿ‘† ๐Ÿ—„ &amp; โš™๏ธ ๐ŸŽ“ `FastAPI`.
๐Ÿ‘‰ ๐Ÿ”œ ๐Ÿ‘‘ ๐Ÿ“ ๐Ÿ‘† ๐Ÿˆธ ๐Ÿ‘ˆ ๐Ÿ‘” ๐ŸŒ ๐Ÿ‘ฏโ€โ™‚๏ธ.
&amp; ๐Ÿ† ๐Ÿ‘† โš› ๐Ÿ”œ ๐Ÿ”œ ๐Ÿ–– ๐Ÿšฎ ๐Ÿ‘ ๐ŸŽฏ ๐Ÿ•น, ๐Ÿ‘‘ ๐Ÿ“ ๐Ÿ”œ ๐Ÿ™….
### ๐Ÿ—„ `FastAPI`
๐Ÿ‘† ๐Ÿ—„ &amp; โœ `FastAPI` ๐ŸŽ“ ๐Ÿ›Ž.
&amp; ๐Ÿ‘ฅ ๐Ÿ’ช ๐Ÿ“ฃ [๐ŸŒ ๐Ÿ”—](dependencies/global-dependencies.md){.internal-link target=_blank} ๐Ÿ‘ˆ ๐Ÿ”œ ๐ŸŒ€ โฎ๏ธ ๐Ÿ”— ๐Ÿ”  `APIRouter`:
```Python hl_lines="1 3 7"
{!../../../docs_src/bigger_applications/app/main.py!}
```
### ๐Ÿ—„ `APIRouter`
๐Ÿ”œ ๐Ÿ‘ฅ ๐Ÿ—„ ๐ŸŽ ๐Ÿ” ๐Ÿ‘ˆ โœ”๏ธ `APIRouter`โ“‚:
```Python hl_lines="5"
{!../../../docs_src/bigger_applications/app/main.py!}
```
๐Ÿ“ `app/routers/users.py` &amp; `app/routers/items.py` ๐Ÿ” ๐Ÿ‘ˆ ๐Ÿ• ๐ŸŽ ๐Ÿ ๐Ÿ“ฆ `app`, ๐Ÿ‘ฅ ๐Ÿ’ช โš™๏ธ ๐Ÿ‘ โฃ `.` ๐Ÿ—„ ๐Ÿ‘ซ โš™๏ธ "โš– ๐Ÿ—„".
### โ” ๐Ÿญ ๐Ÿ‘ท
๐Ÿ“„:
```Python
from .routers import items, users
```
โ›“:
* โ–ถ๏ธ ๐ŸŽ ๐Ÿ“ฆ ๐Ÿ‘ˆ ๐Ÿ‘‰ ๐Ÿ•น (๐Ÿ“ `app/main.py`) ๐Ÿ–– (๐Ÿ“ `app/`)...
* ๐Ÿ‘€ ๐Ÿ“ฆ `routers` (๐Ÿ“ `app/routers/`)...
* &amp; โšช๏ธโžก๏ธ โšซ๏ธ, ๐Ÿ—„ ๐Ÿ” `items` (๐Ÿ“ `app/routers/items.py`) &amp; `users` (๐Ÿ“ `app/routers/users.py`)...
๐Ÿ•น `items` ๐Ÿ”œ โœ”๏ธ ๐Ÿ”ข `router` (`items.router`). ๐Ÿ‘‰ ๐ŸŽ 1๏ธโƒฃ ๐Ÿ‘ฅ โœ ๐Ÿ“ `app/routers/items.py`, โšซ๏ธ `APIRouter` ๐ŸŽš.
&amp; โคด๏ธ ๐Ÿ‘ฅ ๐ŸŽ ๐Ÿ•น `users`.
๐Ÿ‘ฅ ๐Ÿ’ช ๐Ÿ—„ ๐Ÿ‘ซ ๐Ÿ’–:
```Python
from app.routers import items, users
```
!!! info
๐Ÿฅ‡ โฌ "โš– ๐Ÿ—„":
```Python
from .routers import items, users
```
๐Ÿฅˆ โฌ "๐ŸŽ† ๐Ÿ—„":
```Python
from app.routers import items, users
```
๐Ÿ’ก ๐ŸŒ… ๐Ÿ”ƒ ๐Ÿ ๐Ÿ“ฆ &amp; ๐Ÿ•น, โœ <a href="https://docs.python.org/3/tutorial/modules.html" class="external-link" target="_blank">๐Ÿ›‚ ๐Ÿ ๐Ÿงพ ๐Ÿ”ƒ ๐Ÿ•น</a>.
### โŽ ๐Ÿ“› ๐Ÿ’ฅ
๐Ÿ‘ฅ ๐Ÿญ ๐Ÿ” `items` ๐Ÿ”—, โ†ฉ๏ธ ๐Ÿญ ๐Ÿšฎ ๐Ÿ”ข `router`.
๐Ÿ‘‰ โ†ฉ๏ธ ๐Ÿ‘ฅ โœ”๏ธ โž•1๏ธโƒฃ ๐Ÿ”ข ๐Ÿ“› `router` ๐Ÿ” `users`.
๐Ÿšฅ ๐Ÿ‘ฅ โœ”๏ธ ๐Ÿ—„ 1๏ธโƒฃ โฎ๏ธ ๐ŸŽ, ๐Ÿ’–:
```Python
from .routers.items import router
from .routers.users import router
```
`router` โšช๏ธโžก๏ธ `users` ๐Ÿ”œ ๐Ÿ“ 1๏ธโƒฃ โšช๏ธโžก๏ธ `items` &amp; ๐Ÿ‘ฅ ๐Ÿšซ๐Ÿ”œ ๐Ÿ’ช โš™๏ธ ๐Ÿ‘ซ ๐ŸŽ ๐Ÿ•ฐ.
, ๐Ÿ’ช โš™๏ธ ๐Ÿ‘ฏโ€โ™‚๏ธ ๐Ÿ‘ซ ๐ŸŽ ๐Ÿ“, ๐Ÿ‘ฅ ๐Ÿ—„ ๐Ÿ” ๐Ÿ”—:
```Python hl_lines="4"
{!../../../docs_src/bigger_applications/app/main.py!}
```
### ๐Ÿ”Œ `APIRouter`โ“‚ `users` &amp; `items`
๐Ÿ”œ, โžก๏ธ ๐Ÿ”Œ `router`โ“‚ โšช๏ธโžก๏ธ ๐Ÿ” `users` &amp; `items`:
```Python hl_lines="10-11"
{!../../../docs_src/bigger_applications/app/main.py!}
```
!!! info
`users.router` ๐Ÿ”Œ `APIRouter` ๐Ÿ”˜ ๐Ÿ“ `app/routers/users.py`.
&amp; `items.router` ๐Ÿ”Œ `APIRouter` ๐Ÿ”˜ ๐Ÿ“ `app/routers/items.py`.
โฎ๏ธ `app.include_router()` ๐Ÿ‘ฅ ๐Ÿ’ช ๐Ÿšฎ ๐Ÿ”  `APIRouter` ๐Ÿ‘‘ `FastAPI` ๐Ÿˆธ.
โšซ๏ธ ๐Ÿ”œ ๐Ÿ”Œ ๐ŸŒ ๐Ÿ›ฃ โšช๏ธโžก๏ธ ๐Ÿ‘ˆ ๐Ÿ“ป ๐Ÿ• โšซ๏ธ.
!!! note "๐Ÿ“ก โ„น"
โšซ๏ธ ๐Ÿ”œ ๐Ÿค™ ๐Ÿ”˜ โœ *โžก ๐Ÿ› ๏ธ* ๐Ÿ”  *โžก ๐Ÿ› ๏ธ* ๐Ÿ‘ˆ ๐Ÿ“ฃ `APIRouter`.
, โ›… ๐ŸŽ‘, โšซ๏ธ ๐Ÿ”œ ๐Ÿค™ ๐Ÿ‘ท ๐Ÿšฅ ๐ŸŒ ๐ŸŽ ๐Ÿ‘ ๐Ÿ“ฑ.
!!! check
๐Ÿ‘† ๐Ÿšซ โœ”๏ธ ๐Ÿ˜Ÿ ๐Ÿ”ƒ ๐ŸŽญ ๐Ÿ•โ” โœ… ๐Ÿ“ป.
๐Ÿ‘‰ ๐Ÿ”œ โœŠ โฒ &amp; ๐Ÿ”œ ๐Ÿ•ด ๐Ÿ”จ ๐Ÿ•ด.
โšซ๏ธ ๐Ÿ† ๐Ÿšซ ๐Ÿ“‰ ๐ŸŽญ. ๐Ÿ‘ถ
### ๐Ÿ”Œ `APIRouter` โฎ๏ธ ๐Ÿ›ƒ `prefix`, `tags`, `responses`, &amp; `dependencies`
๐Ÿ”œ, โžก๏ธ ๐ŸŒˆ ๐Ÿ‘† ๐Ÿข ๐Ÿค ๐Ÿ‘† `app/internal/admin.py` ๐Ÿ“.
โšซ๏ธ ๐Ÿ”Œ `APIRouter` โฎ๏ธ ๐Ÿ“ก *โžก ๐Ÿ› ๏ธ* ๐Ÿ‘ˆ ๐Ÿ‘† ๐Ÿข ๐Ÿ’ฐ ๐Ÿ–– ๐Ÿ“š ๐Ÿ—.
๐Ÿ‘‰ ๐Ÿ–ผ โšซ๏ธ ๐Ÿ”œ ๐Ÿ’Ž ๐Ÿ™…. โœ‹๏ธ โžก๏ธ ๐Ÿ’ฌ ๐Ÿ‘ˆ โ†ฉ๏ธ โšซ๏ธ ๐Ÿ’ฐ โฎ๏ธ ๐ŸŽ ๐Ÿ— ๐Ÿข, ๐Ÿ‘ฅ ๐Ÿšซ๐Ÿ”œ ๐Ÿ”€ โšซ๏ธ &amp; ๐Ÿšฎ `prefix`, `dependencies`, `tags`, โ™’๏ธ. ๐Ÿ”— `APIRouter`:
```Python hl_lines="3"
{!../../../docs_src/bigger_applications/app/internal/admin.py!}
```
โœ‹๏ธ ๐Ÿ‘ฅ ๐Ÿ’š โš’ ๐Ÿ›ƒ `prefix` ๐Ÿ•โ” โœ… `APIRouter` ๐Ÿ‘ˆ ๐ŸŒ ๐Ÿšฎ *โžก ๐Ÿ› ๏ธ* โ–ถ๏ธ โฎ๏ธ `/admin`, ๐Ÿ‘ฅ ๐Ÿ’š ๐Ÿ” โšซ๏ธ โฎ๏ธ `dependencies` ๐Ÿ‘ฅ โช โœ”๏ธ ๐Ÿ‘‰ ๐Ÿ—, &amp; ๐Ÿ‘ฅ ๐Ÿ’š ๐Ÿ”Œ `tags` &amp; `responses`.
๐Ÿ‘ฅ ๐Ÿ’ช ๐Ÿ“ฃ ๐ŸŒ ๐Ÿ‘ˆ ๐Ÿต โœ”๏ธ ๐Ÿ”€ โฎ๏ธ `APIRouter` ๐Ÿšถโ€โ™€๏ธ ๐Ÿ‘ˆ ๐Ÿ”ข `app.include_router()`:
```Python hl_lines="14-17"
{!../../../docs_src/bigger_applications/app/main.py!}
```
๐Ÿ‘ˆ ๐ŸŒŒ, โฎ๏ธ `APIRouter` ๐Ÿ”œ ๐Ÿšง โš—, ๐Ÿ‘ฅ ๐Ÿ’ช ๐Ÿ’ฐ ๐Ÿ‘ˆ ๐ŸŽ `app/internal/admin.py` ๐Ÿ“ โฎ๏ธ ๐ŸŽ ๐Ÿ— ๐Ÿข.
๐Ÿ ๐Ÿ‘ˆ ๐Ÿ‘† ๐Ÿ“ฑ, ๐Ÿ”  *โžก ๐Ÿ› ๏ธ* โšช๏ธโžก๏ธ `admin` ๐Ÿ•น ๐Ÿ”œ โœ”๏ธ:
* ๐Ÿ”ก `/admin`.
* ๐Ÿ”– `admin`.
* ๐Ÿ”— `get_token_header`.
* ๐Ÿ“จ `418`. ๐Ÿ‘ถ
โœ‹๏ธ ๐Ÿ‘ˆ ๐Ÿ”œ ๐Ÿ•ด ๐Ÿ“‰ ๐Ÿ‘ˆ `APIRouter` ๐Ÿ‘† ๐Ÿ“ฑ, ๐Ÿšซ ๐Ÿ™† ๐ŸŽ ๐Ÿ“Ÿ ๐Ÿ‘ˆ โš™๏ธ โšซ๏ธ.
, ๐Ÿ–ผ, ๐ŸŽ ๐Ÿ— ๐Ÿ’ช โš™๏ธ ๐ŸŽ `APIRouter` โฎ๏ธ ๐ŸŽ ๐Ÿค ๐Ÿ‘ฉโ€๐Ÿ”ฌ.
### ๐Ÿ”Œ *โžก ๐Ÿ› ๏ธ*
๐Ÿ‘ฅ ๐Ÿ’ช ๐Ÿšฎ *โžก ๐Ÿ› ๏ธ* ๐Ÿ”— `FastAPI` ๐Ÿ“ฑ.
๐Ÿ“ฅ ๐Ÿ‘ฅ โšซ๏ธ... ๐ŸŽฆ ๐Ÿ‘ˆ ๐Ÿ‘ฅ ๐Ÿ’ช ๐Ÿคท:
```Python hl_lines="21-23"
{!../../../docs_src/bigger_applications/app/main.py!}
```
&amp; โšซ๏ธ ๐Ÿ”œ ๐Ÿ‘ท โ˜‘, ๐Ÿ‘ฏโ€โ™‚๏ธ โฎ๏ธ ๐ŸŒ ๐ŸŽ *โžก ๐Ÿ› ๏ธ* ๐Ÿšฎ โฎ๏ธ `app.include_router()`.
!!! info "๐Ÿ“ถ ๐Ÿ“ก โ„น"
**๐Ÿ—’**: ๐Ÿ‘‰ ๐Ÿ“ถ ๐Ÿ“ก โ„น ๐Ÿ‘ˆ ๐Ÿ‘† ๐ŸŽฒ ๐Ÿ’ช **๐Ÿšถ**.
---
`APIRouter`โ“‚ ๐Ÿšซ "๐Ÿ—ป", ๐Ÿ‘ซ ๐Ÿšซ ๐Ÿ‘ฝ โšช๏ธโžก๏ธ ๐ŸŽ‚ ๐Ÿˆธ.
๐Ÿ‘‰ โ†ฉ๏ธ ๐Ÿ‘ฅ ๐Ÿ’š ๐Ÿ”Œ ๐Ÿ‘ซ *โžก ๐Ÿ› ๏ธ* ๐Ÿ—„ ๐Ÿ”— &amp; ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ”ข.
๐Ÿ‘ฅ ๐Ÿšซ๐Ÿ”œ โŽ ๐Ÿ‘ซ &amp; "๐Ÿ—ป" ๐Ÿ‘ซ โžก ๐ŸŽ‚, *โžก ๐Ÿ› ๏ธ* "๐Ÿ––" (๐Ÿค-โœ), ๐Ÿšซ ๐Ÿ”Œ ๐Ÿ”—.
## โœ… ๐Ÿง ๐Ÿ› ๏ธ ๐Ÿฉบ
๐Ÿ”œ, ๐Ÿƒ `uvicorn`, โš™๏ธ ๐Ÿ•น `app.main` &amp; ๐Ÿ”ข `app`:
<div class="termy">
```console
$ uvicorn app.main:app --reload
<span style="color: green;">INFO</span>: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
```
</div>
&amp; ๐Ÿ“‚ ๐Ÿฉบ <a href="http://127.0.0.1:8000/docs" class="external-link" target="_blank">http://127.0.0.1:8000/docs</a>.
๐Ÿ‘† ๐Ÿ”œ ๐Ÿ‘€ ๐Ÿง ๐Ÿ› ๏ธ ๐Ÿฉบ, โœ… โžก โšช๏ธโžก๏ธ ๐ŸŒ ๐Ÿ”, โš™๏ธ โ˜‘ โžก (&amp; ๐Ÿ”ก) &amp; โ˜‘ ๐Ÿ”–:
<img src="/img/tutorial/bigger-applications/image01.png">
## ๐Ÿ”Œ ๐ŸŽ ๐Ÿ“ป ๐Ÿ’— ๐Ÿ•ฐ โฎ๏ธ ๐ŸŽ `prefix`
๐Ÿ‘† ๐Ÿ’ช โš™๏ธ `.include_router()` ๐Ÿ’— ๐Ÿ•ฐ โฎ๏ธ *๐ŸŽ* ๐Ÿ“ป โš™๏ธ ๐ŸŽ ๐Ÿ”ก.
๐Ÿ‘‰ ๐Ÿ’ช โš , ๐Ÿ–ผ, ๐ŸŽฆ ๐ŸŽ ๐Ÿ› ๏ธ ๐Ÿ”ฝ ๐ŸŽ ๐Ÿ”ก, โœ… `/api/v1` &amp; `/api/latest`.
๐Ÿ‘‰ ๐Ÿง โš™๏ธ ๐Ÿ‘ˆ ๐Ÿ‘† 5๏ธโƒฃ๐Ÿ“† ๐Ÿšซ ๐Ÿค™ ๐Ÿ’ช, โœ‹๏ธ โšซ๏ธ ๐Ÿ“ค ๐Ÿ’ผ ๐Ÿ‘†.
## ๐Ÿ”Œ `APIRouter` โž•1๏ธโƒฃ
๐ŸŽ ๐ŸŒŒ ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ”Œ `APIRouter` `FastAPI` ๐Ÿˆธ, ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ”Œ `APIRouter` โž•1๏ธโƒฃ `APIRouter` โš™๏ธ:
```Python
router.include_router(other_router)
```
โš’ ๐Ÿ’ญ ๐Ÿ‘† โšซ๏ธ โญ ๐Ÿ”Œ `router` `FastAPI` ๐Ÿ“ฑ, ๐Ÿ‘ˆ *โžก ๐Ÿ› ๏ธ* โšช๏ธโžก๏ธ `other_router` ๐Ÿ”Œ.

68
docs/em/docs/tutorial/body-fields.md

@ -0,0 +1,68 @@
# ๐Ÿ’ช - ๐Ÿ‘
๐ŸŽ ๐ŸŒŒ ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ“ฃ ๐ŸŒ– ๐Ÿ”ฌ &amp; ๐Ÿ—ƒ *โžก ๐Ÿ› ๏ธ ๐Ÿ”ข* ๐Ÿ”ข โฎ๏ธ `Query`, `Path` &amp; `Body`, ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ“ฃ ๐Ÿ”ฌ &amp; ๐Ÿ—ƒ ๐Ÿ”˜ Pydantic ๐Ÿท โš™๏ธ Pydantic `Field`.
## ๐Ÿ—„ `Field`
๐Ÿฅ‡, ๐Ÿ‘† โœ”๏ธ ๐Ÿ—„ โšซ๏ธ:
=== "๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="4"
{!> ../../../docs_src/body_fields/tutorial001.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.1๏ธโƒฃ0๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="2"
{!> ../../../docs_src/body_fields/tutorial001_py310.py!}
```
!!! warning
๐Ÿ‘€ ๐Ÿ‘ˆ `Field` ๐Ÿ—„ ๐Ÿ”— โšช๏ธโžก๏ธ `pydantic`, ๐Ÿšซ โšช๏ธโžก๏ธ `fastapi` ๐ŸŒ ๐ŸŽ‚ (`Query`, `Path`, `Body`, โ™’๏ธ).
## ๐Ÿ“ฃ ๐Ÿท ๐Ÿ”ข
๐Ÿ‘† ๐Ÿ’ช โคด๏ธ โš™๏ธ `Field` โฎ๏ธ ๐Ÿท ๐Ÿ”ข:
=== "๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="11-14"
{!> ../../../docs_src/body_fields/tutorial001.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.1๏ธโƒฃ0๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="9-12"
{!> ../../../docs_src/body_fields/tutorial001_py310.py!}
```
`Field` ๐Ÿ‘ท ๐ŸŽ ๐ŸŒŒ `Query`, `Path` &amp; `Body`, โšซ๏ธ โœ”๏ธ ๐ŸŒ ๐ŸŽ ๐Ÿ”ข, โ™’๏ธ.
!!! note "๐Ÿ“ก โ„น"
๐Ÿค™, `Query`, `Path` &amp; ๐ŸŽ ๐Ÿ‘† ๐Ÿ”œ ๐Ÿ‘€ โญ โœ ๐ŸŽš ๐Ÿฟ โš  `Param` ๐ŸŽ“, โ” โšซ๏ธ ๐Ÿฟ Pydantic `FieldInfo` ๐ŸŽ“.
&amp; Pydantic `Field` ๐Ÿ“จ ๐Ÿ‘ `FieldInfo` ๐Ÿ‘.
`Body` ๐Ÿ“จ ๐ŸŽš ๐Ÿฟ `FieldInfo` ๐Ÿ”—. &amp; ๐Ÿ“ค ๐ŸŽ ๐Ÿ‘† ๐Ÿ”œ ๐Ÿ‘€ โช ๐Ÿ‘ˆ ๐Ÿฟ `Body` ๐ŸŽ“.
๐Ÿ’ญ ๐Ÿ‘ˆ ๐Ÿ•โ” ๐Ÿ‘† ๐Ÿ—„ `Query`, `Path`, &amp; ๐ŸŽ โšช๏ธโžก๏ธ `fastapi`, ๐Ÿ‘ˆ ๐Ÿค™ ๐Ÿ”ข ๐Ÿ‘ˆ ๐Ÿ“จ ๐ŸŽ ๐ŸŽ“.
!!! tip
๐Ÿ‘€ โ” ๐Ÿ”  ๐Ÿท ๐Ÿ”ข โฎ๏ธ ๐Ÿ†Ž, ๐Ÿ”ข ๐Ÿ’ฒ &amp; `Field` โœ”๏ธ ๐ŸŽ ๐Ÿ“Š *โžก ๐Ÿ› ๏ธ ๐Ÿ”ข* ๐Ÿ”ข, โฎ๏ธ `Field` โ†ฉ๏ธ `Path`, `Query` &amp; `Body`.
## ๐Ÿšฎ โž• โ„น
๐Ÿ‘† ๐Ÿ’ช ๐Ÿ“ฃ โž• โ„น `Field`, `Query`, `Body`, โ™’๏ธ. &amp; โšซ๏ธ ๐Ÿ”œ ๐Ÿ”Œ ๐Ÿ— ๐ŸŽป ๐Ÿ”—.
๐Ÿ‘† ๐Ÿ”œ ๐Ÿ’ก ๐ŸŒ… ๐Ÿ”ƒ โŽ โž• โ„น โช ๐Ÿฉบ, ๐Ÿ•โ” ๐Ÿซ ๐Ÿ“ฃ ๐Ÿ–ผ.
!!! warning
โž• ๐Ÿ”‘ ๐Ÿšถโ€โ™€๏ธ `Field` ๐Ÿ”œ ๐ŸŽ ๐Ÿ“‰ ๐Ÿ—„ ๐Ÿ”— ๐Ÿ‘† ๐Ÿˆธ.
๐Ÿ‘ซ ๐Ÿ”‘ 5๏ธโƒฃ๐Ÿ“† ๐Ÿšซ ๐ŸŽฏ ๐Ÿ• ๐Ÿ—„ ๐Ÿ”ง, ๐Ÿ—„ ๐Ÿงฐ, ๐Ÿ–ผ [๐Ÿ—„ ๐Ÿ’ณ](https://validator.swagger.io/), 5๏ธโƒฃ๐Ÿ“† ๐Ÿšซ ๐Ÿ‘ท โฎ๏ธ ๐Ÿ‘† ๐Ÿ— ๐Ÿ”—.
## ๐ŸŒƒ
๐Ÿ‘† ๐Ÿ’ช โš™๏ธ Pydantic `Field` ๐Ÿ“ฃ โž• ๐Ÿ”ฌ &amp; ๐Ÿ—ƒ ๐Ÿท ๐Ÿ”ข.
๐Ÿ‘† ๐Ÿ’ช โš™๏ธ โž• ๐Ÿ‡จ๐Ÿ‡ป โŒ ๐Ÿšถโ€โ™€๏ธ ๐ŸŒ– ๐ŸŽป ๐Ÿ”— ๐Ÿ—ƒ.

213
docs/em/docs/tutorial/body-multiple-params.md

@ -0,0 +1,213 @@
# ๐Ÿ’ช - ๐Ÿ’— ๐Ÿ”ข
๐Ÿ”œ ๐Ÿ‘ˆ ๐Ÿ‘ฅ โœ”๏ธ ๐Ÿ‘€ โ” โš™๏ธ `Path` &amp; `Query`, โžก๏ธ ๐Ÿ‘€ ๐ŸŒ… ๐Ÿง โš™๏ธ ๐Ÿ“จ ๐Ÿ’ช ๐Ÿ“„.
## ๐ŸŒ€ `Path`, `Query` &amp; ๐Ÿ’ช ๐Ÿ”ข
๐Ÿฅ‡, โ†—๏ธ, ๐Ÿ‘† ๐Ÿ’ช ๐ŸŒ€ `Path`, `Query` &amp; ๐Ÿ“จ ๐Ÿ’ช ๐Ÿ”ข ๐Ÿ“„ โžก &amp; **FastAPI** ๐Ÿ”œ ๐Ÿ’ญ โšซ๏ธโ”.
&amp; ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ“ฃ ๐Ÿ’ช ๐Ÿ”ข ๐Ÿ“ฆ, โš’ ๐Ÿ”ข `None`:
=== "๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="19-21"
{!> ../../../docs_src/body_multiple_params/tutorial001.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.1๏ธโƒฃ0๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="17-19"
{!> ../../../docs_src/body_multiple_params/tutorial001_py310.py!}
```
!!! note
๐Ÿ‘€ ๐Ÿ‘ˆ, ๐Ÿ‘‰ ๐Ÿ’ผ, `item` ๐Ÿ‘ˆ ๐Ÿ”œ โœŠ โšช๏ธโžก๏ธ ๐Ÿ’ช ๐Ÿ“ฆ. โšซ๏ธ โœ”๏ธ `None` ๐Ÿ”ข ๐Ÿ’ฒ.
## ๐Ÿ’— ๐Ÿ’ช ๐Ÿ”ข
โฎ๏ธ ๐Ÿ–ผ, *โžก ๐Ÿ› ๏ธ* ๐Ÿ”œ โŒ› ๐ŸŽป ๐Ÿ’ช โฎ๏ธ ๐Ÿ”ข `Item`, ๐Ÿ’–:
```JSON
{
"name": "Foo",
"description": "The pretender",
"price": 42.0,
"tax": 3.2
}
```
โœ‹๏ธ ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ“ฃ ๐Ÿ’— ๐Ÿ’ช ๐Ÿ”ข, โœ… `item` &amp; `user`:
=== "๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="22"
{!> ../../../docs_src/body_multiple_params/tutorial002.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.1๏ธโƒฃ0๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="20"
{!> ../../../docs_src/body_multiple_params/tutorial002_py310.py!}
```
๐Ÿ‘‰ ๐Ÿ’ผ, **FastAPI** ๐Ÿ”œ ๐Ÿ‘€ ๐Ÿ‘ˆ ๐Ÿ“ค ๐ŸŒ… ๐ŸŒ˜ 1๏ธโƒฃ ๐Ÿ’ช ๐Ÿ”ข ๐Ÿ”ข (2๏ธโƒฃ ๐Ÿ”ข ๐Ÿ‘ˆ Pydantic ๐Ÿท).
, โšซ๏ธ ๐Ÿ”œ โคด๏ธ โš™๏ธ ๐Ÿ”ข ๐Ÿ“› ๐Ÿ”‘ (๐Ÿ‘ ๐Ÿ“›) ๐Ÿ’ช, &amp; โŒ› ๐Ÿ’ช ๐Ÿ’–:
```JSON
{
"item": {
"name": "Foo",
"description": "The pretender",
"price": 42.0,
"tax": 3.2
},
"user": {
"username": "dave",
"full_name": "Dave Grohl"
}
}
```
!!! note
๐Ÿ‘€ ๐Ÿ‘ˆ โœ‹๏ธ `item` ๐Ÿ“ฃ ๐ŸŽ ๐ŸŒŒ โญ, โšซ๏ธ ๐Ÿ”œ โŒ› ๐Ÿ”˜ ๐Ÿ’ช โฎ๏ธ ๐Ÿ”‘ `item`.
**FastAPI** ๐Ÿ”œ ๐Ÿง ๐Ÿ› ๏ธ โšช๏ธโžก๏ธ ๐Ÿ“จ, ๐Ÿ‘ˆ ๐Ÿ”ข `item` ๐Ÿ“จ โšซ๏ธ ๐ŸŽฏ ๐ŸŽš &amp; ๐ŸŽ `user`.
โšซ๏ธ ๐Ÿ”œ ๐ŸŽญ ๐Ÿ”ฌ โš— ๐Ÿ’ฝ, &amp; ๐Ÿ”œ ๐Ÿ“„ โšซ๏ธ ๐Ÿ’– ๐Ÿ‘ˆ ๐Ÿ—„ ๐Ÿ”— &amp; ๐Ÿง ๐Ÿฉบ.
## โญ ๐Ÿ’ฒ ๐Ÿ’ช
๐ŸŽ ๐ŸŒŒ ๐Ÿ“ค `Query` &amp; `Path` ๐Ÿ”ฌ โž• ๐Ÿ’ฝ ๐Ÿ”ข &amp; โžก ๐Ÿ”ข, **FastAPI** ๐Ÿšš ๐ŸŒ“ `Body`.
๐Ÿ–ผ, โ†” โฎ๏ธ ๐Ÿท, ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ’ญ ๐Ÿ‘ˆ ๐Ÿ‘† ๐Ÿ’š โœ”๏ธ โž•1๏ธโƒฃ ๐Ÿ”‘ `importance` ๐ŸŽ ๐Ÿ’ช, ๐Ÿฅˆ `item` &amp; `user`.
๐Ÿšฅ ๐Ÿ‘† ๐Ÿ“ฃ โšซ๏ธ, โ†ฉ๏ธ โšซ๏ธ โญ ๐Ÿ’ฒ, **FastAPI** ๐Ÿ”œ ๐Ÿค” ๐Ÿ‘ˆ โšซ๏ธ ๐Ÿ”ข ๐Ÿ”ข.
โœ‹๏ธ ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ’ก **FastAPI** ๐Ÿ˜ฅ โšซ๏ธ โž•1๏ธโƒฃ ๐Ÿ’ช ๐Ÿ”‘ โš™๏ธ `Body`:
=== "๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="22"
{!> ../../../docs_src/body_multiple_params/tutorial003.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.1๏ธโƒฃ0๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="20"
{!> ../../../docs_src/body_multiple_params/tutorial003_py310.py!}
```
๐Ÿ‘‰ ๐Ÿ’ผ, **FastAPI** ๐Ÿ”œ โŒ› ๐Ÿ’ช ๐Ÿ’–:
```JSON
{
"item": {
"name": "Foo",
"description": "The pretender",
"price": 42.0,
"tax": 3.2
},
"user": {
"username": "dave",
"full_name": "Dave Grohl"
},
"importance": 5
}
```
๐Ÿ”„, โšซ๏ธ ๐Ÿ”œ ๐Ÿ—œ ๐Ÿ“Š ๐Ÿ†Ž, โœ”, ๐Ÿ“„, โ™’๏ธ.
## ๐Ÿ’— ๐Ÿ’ช = &amp; ๐Ÿ”ข
โ†—๏ธ, ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ“ฃ ๐ŸŒ– ๐Ÿ”ข ๐Ÿ”ข ๐Ÿ•โ” ๐Ÿ‘† ๐Ÿ’ช, ๐ŸŒ– ๐Ÿ™† ๐Ÿ’ช ๐Ÿ”ข.
, ๐Ÿ”ข, โญ ๐Ÿ’ฒ ๐Ÿ”ฌ ๐Ÿ”ข ๐Ÿ”ข, ๐Ÿ‘† ๐Ÿšซ โœ”๏ธ ๐ŸŽฏ ๐Ÿšฎ `Query`, ๐Ÿ‘† ๐Ÿ’ช:
```Python
q: Union[str, None] = None
```
โš–๏ธ ๐Ÿ 3๏ธโƒฃ.1๏ธโƒฃ0๏ธโƒฃ &amp; ๐Ÿ”›:
```Python
q: str | None = None
```
๐Ÿ–ผ:
=== "๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="27"
{!> ../../../docs_src/body_multiple_params/tutorial004.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.1๏ธโƒฃ0๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="26"
{!> ../../../docs_src/body_multiple_params/tutorial004_py310.py!}
```
!!! info
`Body` โœ”๏ธ ๐ŸŒ ๐ŸŽ โž• ๐Ÿ”ฌ &amp; ๐Ÿ—ƒ ๐Ÿ”ข `Query`,`Path` &amp; ๐ŸŽ ๐Ÿ‘† ๐Ÿ”œ ๐Ÿ‘€ โช.
## โฏ ๐Ÿ‘ ๐Ÿ’ช ๐Ÿ”ข
โžก๏ธ ๐Ÿ’ฌ ๐Ÿ‘† ๐Ÿ•ด โœ”๏ธ ๐Ÿ‘ `item` ๐Ÿ’ช ๐Ÿ”ข โšช๏ธโžก๏ธ Pydantic ๐Ÿท `Item`.
๐Ÿ”ข, **FastAPI** ๐Ÿ”œ โคด๏ธ โŒ› ๐Ÿšฎ ๐Ÿ’ช ๐Ÿ”—.
โœ‹๏ธ ๐Ÿšฅ ๐Ÿ‘† ๐Ÿ’š โšซ๏ธ โŒ› ๐ŸŽป โฎ๏ธ ๐Ÿ”‘ `item` &amp; ๐Ÿ”˜ โšซ๏ธ ๐Ÿท ๐ŸŽš, โšซ๏ธ ๐Ÿ”จ ๐Ÿ•โ” ๐Ÿ‘† ๐Ÿ“ฃ โž• ๐Ÿ’ช ๐Ÿ”ข, ๐Ÿ‘† ๐Ÿ’ช โš™๏ธ ๐ŸŽ `Body` ๐Ÿ”ข `embed`:
```Python
item: Item = Body(embed=True)
```
:
=== "๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="17"
{!> ../../../docs_src/body_multiple_params/tutorial005.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.1๏ธโƒฃ0๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="15"
{!> ../../../docs_src/body_multiple_params/tutorial005_py310.py!}
```
๐Ÿ‘‰ ๐Ÿ’ผ **FastAPI** ๐Ÿ”œ โŒ› ๐Ÿ’ช ๐Ÿ’–:
```JSON hl_lines="2"
{
"item": {
"name": "Foo",
"description": "The pretender",
"price": 42.0,
"tax": 3.2
}
}
```
โ†ฉ๏ธ:
```JSON
{
"name": "Foo",
"description": "The pretender",
"price": 42.0,
"tax": 3.2
}
```
## ๐ŸŒƒ
๐Ÿ‘† ๐Ÿ’ช ๐Ÿšฎ ๐Ÿ’— ๐Ÿ’ช ๐Ÿ”ข ๐Ÿ‘† *โžก ๐Ÿ› ๏ธ ๐Ÿ”ข*, โœ‹๏ธ ๐Ÿ“จ ๐Ÿ’ช ๐Ÿ•ด โœ”๏ธ ๐Ÿ‘ ๐Ÿ’ช.
โœ‹๏ธ **FastAPI** ๐Ÿ”œ ๐Ÿต โšซ๏ธ, ๐Ÿค ๐Ÿ‘† โ˜‘ ๐Ÿ“Š ๐Ÿ‘† ๐Ÿ”ข, &amp; โœ” &amp; ๐Ÿ“„ โ˜‘ ๐Ÿ”— *โžก ๐Ÿ› ๏ธ*.
๐Ÿ‘† ๐Ÿ’ช ๐Ÿ“ฃ โญ ๐Ÿ’ฒ ๐Ÿ“จ ๐Ÿ• ๐Ÿ’ช.
&amp; ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ’ก **FastAPI** โฏ ๐Ÿ’ช ๐Ÿ”‘ ๐Ÿ•โ” ๐Ÿ“ค ๐Ÿ•ด ๐Ÿ‘ ๐Ÿ”ข ๐Ÿ“ฃ.

382
docs/em/docs/tutorial/body-nested-models.md

@ -0,0 +1,382 @@
# ๐Ÿ’ช - ๐Ÿ” ๐Ÿท
โฎ๏ธ **FastAPI**, ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ”ฌ, โœ”, ๐Ÿ“„, &amp; โš™๏ธ ๐ŸŽฒ ๐Ÿ™‡ ๐Ÿฆ ๐Ÿท (๐Ÿ‘ Pydantic).
## ๐Ÿ“‡ ๐Ÿ‘
๐Ÿ‘† ๐Ÿ’ช ๐Ÿ”ฌ ๐Ÿ”ข ๐Ÿพ. ๐Ÿ–ผ, ๐Ÿ `list`:
=== "๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="14"
{!> ../../../docs_src/body_nested_models/tutorial001.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.1๏ธโƒฃ0๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="12"
{!> ../../../docs_src/body_nested_models/tutorial001_py310.py!}
```
๐Ÿ‘‰ ๐Ÿ”œ โš’ `tags` ๐Ÿ“‡, ๐Ÿ‘ โšซ๏ธ ๐Ÿšซ ๐Ÿ“ฃ ๐Ÿ†Ž ๐Ÿ”ฃ ๐Ÿ“‡.
## ๐Ÿ“‡ ๐Ÿ‘ โฎ๏ธ ๐Ÿ†Ž ๐Ÿ”ข
โœ‹๏ธ ๐Ÿ โœ”๏ธ ๐ŸŽฏ ๐ŸŒŒ ๐Ÿ“ฃ ๐Ÿ“‡ โฎ๏ธ ๐Ÿ”— ๐Ÿ†Ž, โš–๏ธ "๐Ÿ†Ž ๐Ÿ”ข":
### ๐Ÿ—„ โŒจ `List`
๐Ÿ 3๏ธโƒฃ.9๏ธโƒฃ &amp; ๐Ÿ”› ๐Ÿ‘† ๐Ÿ’ช โš™๏ธ ๐Ÿฉ `list` ๐Ÿ“ฃ ๐Ÿ‘ซ ๐Ÿ†Ž โœ ๐Ÿ‘ฅ ๐Ÿ”œ ๐Ÿ‘€ ๐Ÿ”›. ๐Ÿ‘ถ
โœ‹๏ธ ๐Ÿ โฌ โญ 3๏ธโƒฃ.9๏ธโƒฃ (3๏ธโƒฃ.6๏ธโƒฃ &amp; ๐Ÿ”›), ๐Ÿ‘† ๐Ÿฅ‡ ๐Ÿ’ช ๐Ÿ—„ `List` โšช๏ธโžก๏ธ ๐Ÿฉ ๐Ÿ `typing` ๐Ÿ•น:
```Python hl_lines="1"
{!> ../../../docs_src/body_nested_models/tutorial002.py!}
```
### ๐Ÿ“ฃ `list` โฎ๏ธ ๐Ÿ†Ž ๐Ÿ”ข
๐Ÿ“ฃ ๐Ÿ†Ž ๐Ÿ‘ˆ โœ”๏ธ ๐Ÿ†Ž ๐Ÿ”ข (๐Ÿ”— ๐Ÿ†Ž), ๐Ÿ’– `list`, `dict`, `tuple`:
* ๐Ÿšฅ ๐Ÿ‘† ๐Ÿ โฌ ๐Ÿ”… ๐ŸŒ˜ 3๏ธโƒฃ.9๏ธโƒฃ, ๐Ÿ—„ ๐Ÿ‘ซ ๐ŸŒ“ โฌ โšช๏ธโžก๏ธ `typing` ๐Ÿ•น
* ๐Ÿšถโ€โ™€๏ธ ๐Ÿ”— ๐Ÿ†Ž(โ“‚) "๐Ÿ†Ž ๐Ÿ”ข" โš™๏ธ โฌœ ๐Ÿ—œ: `[` &amp; `]`
๐Ÿ 3๏ธโƒฃ.9๏ธโƒฃ โšซ๏ธ ๐Ÿ”œ:
```Python
my_list: list[str]
```
โฌ ๐Ÿ โญ 3๏ธโƒฃ.9๏ธโƒฃ, โšซ๏ธ ๐Ÿ”œ:
```Python
from typing import List
my_list: List[str]
```
๐Ÿ‘ˆ ๐ŸŒ ๐Ÿฉ ๐Ÿ โ• ๐Ÿ†Ž ๐Ÿ“„.
โš™๏ธ ๐Ÿ‘ˆ ๐ŸŽ ๐Ÿฉ โ• ๐Ÿท ๐Ÿ”ข โฎ๏ธ ๐Ÿ”— ๐Ÿ†Ž.
, ๐Ÿ‘† ๐Ÿ–ผ, ๐Ÿ‘ฅ ๐Ÿ’ช โš’ `tags` ๐ŸŽฏ "๐Ÿ“‡ ๐ŸŽป":
=== "๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="14"
{!> ../../../docs_src/body_nested_models/tutorial002.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.9๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="14"
{!> ../../../docs_src/body_nested_models/tutorial002_py39.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.1๏ธโƒฃ0๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="12"
{!> ../../../docs_src/body_nested_models/tutorial002_py310.py!}
```
## โš’ ๐Ÿ†Ž
โœ‹๏ธ โคด๏ธ ๐Ÿ‘ฅ ๐Ÿ’ญ ๐Ÿ”ƒ โšซ๏ธ, &amp; ๐Ÿค” ๐Ÿ‘ˆ ๐Ÿ”– ๐Ÿšซ๐Ÿ”œ ๐Ÿšซ ๐Ÿ”, ๐Ÿ‘ซ ๐Ÿ”œ ๐ŸŽฒ ๐Ÿ˜ ๐ŸŽป.
&amp; ๐Ÿ โœ”๏ธ ๐ŸŽ ๐Ÿ’ฝ ๐Ÿ†Ž โš’ ๐Ÿ˜ ๐Ÿฌ, `set`.
โคด๏ธ ๐Ÿ‘ฅ ๐Ÿ’ช ๐Ÿ“ฃ `tags` โš’ ๐ŸŽป:
=== "๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="1 14"
{!> ../../../docs_src/body_nested_models/tutorial003.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.9๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="14"
{!> ../../../docs_src/body_nested_models/tutorial003_py39.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.1๏ธโƒฃ0๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="12"
{!> ../../../docs_src/body_nested_models/tutorial003_py310.py!}
```
โฎ๏ธ ๐Ÿ‘‰, ๐Ÿšฅ ๐Ÿ‘† ๐Ÿ“จ ๐Ÿ“จ โฎ๏ธ โŽ ๐Ÿ“Š, โšซ๏ธ ๐Ÿ”œ ๐Ÿ—œ โš’ ๐Ÿ˜ ๐Ÿฌ.
&amp; ๐Ÿ•โ” ๐Ÿ‘† ๐Ÿ”ข ๐Ÿ‘ˆ ๐Ÿ“Š, ๐Ÿšฅ โ„น โœ”๏ธ โŽ, โšซ๏ธ ๐Ÿ”œ ๐Ÿ”ข โš’ ๐Ÿ˜ ๐Ÿฌ.
&amp; โšซ๏ธ ๐Ÿ”œ โœ / ๐Ÿ“„ โžก๏ธ ๐Ÿ’โ€โ™‚๏ธ.
## ๐Ÿฆ ๐Ÿท
๐Ÿ”  ๐Ÿ”ข Pydantic ๐Ÿท โœ”๏ธ ๐Ÿ†Ž.
โœ‹๏ธ ๐Ÿ‘ˆ ๐Ÿ†Ž ๐Ÿ’ช โšซ๏ธ โž•1๏ธโƒฃ Pydantic ๐Ÿท.
, ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ“ฃ ๐Ÿ™‡ ๐Ÿฆ ๐ŸŽป "๐ŸŽš" โฎ๏ธ ๐ŸŽฏ ๐Ÿ”ข ๐Ÿ“›, ๐Ÿ†Ž &amp; ๐Ÿ”ฌ.
๐ŸŒ ๐Ÿ‘ˆ, ๐ŸŽฒ ๐Ÿฆ.
### ๐Ÿ”ฌ ๐Ÿ“Š
๐Ÿ–ผ, ๐Ÿ‘ฅ ๐Ÿ’ช ๐Ÿ”ฌ `Image` ๐Ÿท:
=== "๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="9-11"
{!> ../../../docs_src/body_nested_models/tutorial004.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.9๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="9-11"
{!> ../../../docs_src/body_nested_models/tutorial004_py39.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.1๏ธโƒฃ0๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="7-9"
{!> ../../../docs_src/body_nested_models/tutorial004_py310.py!}
```
### โš™๏ธ ๐Ÿ“Š ๐Ÿ†Ž
&amp; โคด๏ธ ๐Ÿ‘ฅ ๐Ÿ’ช โš™๏ธ โšซ๏ธ ๐Ÿ†Ž ๐Ÿ”ข:
=== "๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="20"
{!> ../../../docs_src/body_nested_models/tutorial004.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.9๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="20"
{!> ../../../docs_src/body_nested_models/tutorial004_py39.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.1๏ธโƒฃ0๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="18"
{!> ../../../docs_src/body_nested_models/tutorial004_py310.py!}
```
๐Ÿ‘‰ ๐Ÿ”œ โ›“ ๐Ÿ‘ˆ **FastAPI** ๐Ÿ”œ โŒ› ๐Ÿ’ช ๐ŸŽ:
```JSON
{
"name": "Foo",
"description": "The pretender",
"price": 42.0,
"tax": 3.2,
"tags": ["rock", "metal", "bar"],
"image": {
"url": "http://example.com/baz.jpg",
"name": "The Foo live"
}
}
```
๐Ÿ”„, ๐Ÿคธ ๐Ÿ‘ˆ ๐Ÿ“„, โฎ๏ธ **FastAPI** ๐Ÿ‘† ๐Ÿคš:
* ๐Ÿ‘จโ€๐ŸŽจ ๐Ÿ•โ€๐Ÿฆบ (๐Ÿ› ๏ธ, โ™’๏ธ), ๐Ÿฆ ๐Ÿท
* ๐Ÿ’ฝ ๐Ÿ› ๏ธ
* ๐Ÿ’ฝ ๐Ÿ”ฌ
* ๐Ÿง ๐Ÿงพ
## ๐ŸŽ ๐Ÿ†Ž &amp; ๐Ÿ”ฌ
โ†–๏ธ โšช๏ธโžก๏ธ ๐Ÿ˜ โญ ๐Ÿ†Ž ๐Ÿ’– `str`, `int`, `float`, โ™’๏ธ. ๐Ÿ‘† ๐Ÿ’ช โš™๏ธ ๐ŸŒ… ๐Ÿ— โญ ๐Ÿ†Ž ๐Ÿ‘ˆ ๐Ÿ˜– โšช๏ธโžก๏ธ `str`.
๐Ÿ‘€ ๐ŸŒ ๐ŸŽ› ๐Ÿ‘† โœ”๏ธ, ๐Ÿ›’ ๐Ÿฉบ <a href="https://pydantic-docs.helpmanual.io/usage/types/" class="external-link" target="_blank">Pydantic ๐Ÿ˜ ๐Ÿ†Ž</a>. ๐Ÿ‘† ๐Ÿ”œ ๐Ÿ‘€ ๐Ÿ–ผ โญ ๐Ÿ“ƒ.
๐Ÿ–ผ, `Image` ๐Ÿท ๐Ÿ‘ฅ โœ”๏ธ `url` ๐Ÿ‘, ๐Ÿ‘ฅ ๐Ÿ’ช ๐Ÿ“ฃ โšซ๏ธ โ†ฉ๏ธ `str`, Pydantic `HttpUrl`:
=== "๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="4 10"
{!> ../../../docs_src/body_nested_models/tutorial005.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.9๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="4 10"
{!> ../../../docs_src/body_nested_models/tutorial005_py39.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.1๏ธโƒฃ0๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="2 8"
{!> ../../../docs_src/body_nested_models/tutorial005_py310.py!}
```
๐ŸŽป ๐Ÿ”œ โœ… โ˜‘ ๐Ÿ“›, &amp; ๐Ÿ“„ ๐ŸŽป ๐Ÿ”— / ๐Ÿ—„ โœ….
## ๐Ÿ”ข โฎ๏ธ ๐Ÿ“‡ ๐Ÿ“Š
๐Ÿ‘† ๐Ÿ’ช โš™๏ธ Pydantic ๐Ÿท ๐Ÿพ `list`, `set`, โ™’๏ธ:
=== "๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="20"
{!> ../../../docs_src/body_nested_models/tutorial006.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.9๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="20"
{!> ../../../docs_src/body_nested_models/tutorial006_py39.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.1๏ธโƒฃ0๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="18"
{!> ../../../docs_src/body_nested_models/tutorial006_py310.py!}
```
๐Ÿ‘‰ ๐Ÿ”œ โŒ› (๐Ÿ—œ, โœ”, ๐Ÿ“„, โ™’๏ธ) ๐ŸŽป ๐Ÿ’ช ๐Ÿ’–:
```JSON hl_lines="11"
{
"name": "Foo",
"description": "The pretender",
"price": 42.0,
"tax": 3.2,
"tags": [
"rock",
"metal",
"bar"
],
"images": [
{
"url": "http://example.com/baz.jpg",
"name": "The Foo live"
},
{
"url": "http://example.com/dave.jpg",
"name": "The Baz"
}
]
}
```
!!! info
๐Ÿ‘€ โ” `images` ๐Ÿ”‘ ๐Ÿ”œ โœ”๏ธ ๐Ÿ“‡ ๐Ÿ–ผ ๐ŸŽš.
## ๐Ÿ™‡ ๐Ÿฆ ๐Ÿท
๐Ÿ‘† ๐Ÿ’ช ๐Ÿ”ฌ ๐ŸŽฒ ๐Ÿ™‡ ๐Ÿฆ ๐Ÿท:
=== "๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="9 14 20 23 27"
{!> ../../../docs_src/body_nested_models/tutorial007.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.9๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="9 14 20 23 27"
{!> ../../../docs_src/body_nested_models/tutorial007_py39.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.1๏ธโƒฃ0๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="7 12 18 21 25"
{!> ../../../docs_src/body_nested_models/tutorial007_py310.py!}
```
!!! info
๐Ÿ‘€ โ” `Offer` โœ”๏ธ ๐Ÿ“‡ `Item`โ“‚, โ” ๐Ÿ”„ โœ”๏ธ ๐Ÿ“ฆ ๐Ÿ“‡ `Image`โ“‚
## ๐Ÿ’ช ๐Ÿ˜ ๐Ÿ“‡
๐Ÿšฅ ๐Ÿ” ๐ŸŽš ๐Ÿ’ฒ ๐ŸŽป ๐Ÿ’ช ๐Ÿ‘† โŒ› ๐ŸŽป `array` (๐Ÿ `list`), ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ“ฃ ๐Ÿ†Ž ๐Ÿ”ข ๐Ÿ”ข, ๐ŸŽ Pydantic ๐Ÿท:
```Python
images: List[Image]
```
โš–๏ธ ๐Ÿ 3๏ธโƒฃ.9๏ธโƒฃ &amp; ๐Ÿ”›:
```Python
images: list[Image]
```
:
=== "๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="15"
{!> ../../../docs_src/body_nested_models/tutorial008.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.9๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="13"
{!> ../../../docs_src/body_nested_models/tutorial008_py39.py!}
```
## ๐Ÿ‘จโ€๐ŸŽจ ๐Ÿ•โ€๐Ÿฆบ ๐ŸŒ
&amp; ๐Ÿ‘† ๐Ÿคš ๐Ÿ‘จโ€๐ŸŽจ ๐Ÿ•โ€๐Ÿฆบ ๐ŸŒ.
๐Ÿฌ ๐Ÿ”˜ ๐Ÿ“‡:
<img src="/img/tutorial/body-nested-models/image01.png">
๐Ÿ‘† ๐Ÿšซ ๐Ÿšซ ๐Ÿคš ๐Ÿ‘‰ ๐Ÿ˜‡ ๐Ÿ‘จโ€๐ŸŽจ ๐Ÿ•โ€๐Ÿฆบ ๐Ÿšฅ ๐Ÿ‘† ๐Ÿ‘ท ๐Ÿ”— โฎ๏ธ `dict` โ†ฉ๏ธ Pydantic ๐Ÿท.
โœ‹๏ธ ๐Ÿ‘† ๐Ÿšซ โœ”๏ธ ๐Ÿ˜Ÿ ๐Ÿ”ƒ ๐Ÿ‘ซ ๐Ÿ‘ฏโ€โ™‚๏ธ, ๐Ÿ“จ #๏ธโƒฃ ๐Ÿ—œ ๐Ÿ” &amp; ๐Ÿ‘† ๐Ÿ”ข ๐Ÿ—œ ๐Ÿ” ๐ŸŽป ๐Ÿ’โ€โ™‚๏ธ.
## ๐Ÿ’ช โŒ `dict`โ“‚
๐Ÿ‘† ๐Ÿ’ช ๐Ÿ“ฃ ๐Ÿ’ช `dict` โฎ๏ธ ๐Ÿ”‘ ๐Ÿ†Ž &amp; ๐Ÿ’ฒ ๐ŸŽ ๐Ÿ†Ž.
๐Ÿต โœ”๏ธ ๐Ÿ’ญ โช โšซ๏ธโ” โ˜‘ ๐Ÿ‘/๐Ÿ”ข ๐Ÿ“› (๐Ÿ”œ ๐Ÿ’ผ โฎ๏ธ Pydantic ๐Ÿท).
๐Ÿ‘‰ ๐Ÿ”œ โš  ๐Ÿšฅ ๐Ÿ‘† ๐Ÿ’š ๐Ÿ“จ ๐Ÿ”‘ ๐Ÿ‘ˆ ๐Ÿ‘† ๐Ÿšซ โช ๐Ÿ’ญ.
---
๐ŸŽ โš  ๐Ÿ’ผ ๐Ÿ•โ” ๐Ÿ‘† ๐Ÿ’š โœ”๏ธ ๐Ÿ”‘ ๐ŸŽ ๐Ÿ†Ž, โœ… `int`.
๐Ÿ‘ˆ โšซ๏ธโ” ๐Ÿ‘ฅ ๐Ÿ”œ ๐Ÿ‘€ ๐Ÿ“ฅ.
๐Ÿ‘‰ ๐Ÿ’ผ, ๐Ÿ‘† ๐Ÿ”œ ๐Ÿšซ ๐Ÿ™† `dict` ๐Ÿ“ โšซ๏ธ โœ”๏ธ `int` ๐Ÿ”‘ โฎ๏ธ `float` ๐Ÿ’ฒ:
=== "๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="9"
{!> ../../../docs_src/body_nested_models/tutorial009.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.9๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="7"
{!> ../../../docs_src/body_nested_models/tutorial009_py39.py!}
```
!!! tip
โœ”๏ธ ๐Ÿคฏ ๐Ÿ‘ˆ ๐ŸŽป ๐Ÿ•ด ๐Ÿ•โ€๐Ÿฆบ `str` ๐Ÿ”‘.
โœ‹๏ธ Pydantic โœ”๏ธ ๐Ÿง ๐Ÿ’ฝ ๐Ÿ› ๏ธ.
๐Ÿ‘‰ โ›“ ๐Ÿ‘ˆ, โœ‹๏ธ ๐Ÿ‘† ๐Ÿ› ๏ธ ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ’ช ๐Ÿ•ด ๐Ÿ“จ ๐ŸŽป ๐Ÿ”‘, ๐Ÿ“ ๐Ÿ‘ˆ ๐ŸŽป ๐Ÿ”Œ ๐Ÿ˜ ๐Ÿ”ข, Pydantic ๐Ÿ”œ ๐Ÿ—œ ๐Ÿ‘ซ &amp; โœ” ๐Ÿ‘ซ.
&amp; `dict` ๐Ÿ‘† ๐Ÿ“จ `weights` ๐Ÿ”œ ๐Ÿค™ โœ”๏ธ `int` ๐Ÿ”‘ &amp; `float` ๐Ÿ’ฒ.
## ๐ŸŒƒ
โฎ๏ธ **FastAPI** ๐Ÿ‘† โœ”๏ธ ๐Ÿ”† ๐Ÿ’ช ๐Ÿšš Pydantic ๐Ÿท, โช ๐Ÿšง ๐Ÿ‘† ๐Ÿ“Ÿ ๐Ÿ™…, ๐Ÿ“ &amp; ๐Ÿ˜.
โœ‹๏ธ โฎ๏ธ ๐ŸŒ ๐Ÿ’ฐ:
* ๐Ÿ‘จโ€๐ŸŽจ ๐Ÿ•โ€๐Ÿฆบ (๐Ÿ› ๏ธ ๐ŸŒ โ—)
* ๐Ÿ’ฝ ๐Ÿ› ๏ธ (.โ“‚.. โœ / ๐Ÿ› ๏ธ)
* ๐Ÿ’ฝ ๐Ÿ”ฌ
* ๐Ÿ”— ๐Ÿงพ
* ๐Ÿง ๐Ÿฉบ

155
docs/em/docs/tutorial/body-updates.md

@ -0,0 +1,155 @@
# ๐Ÿ’ช - โ„น
## โ„น โŽ โฎ๏ธ `PUT`
โ„น ๐Ÿฌ ๐Ÿ‘† ๐Ÿ’ช โš™๏ธ <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/PUT" class="external-link" target="_blank">๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ” `PUT`</a> ๐Ÿ› ๏ธ.
๐Ÿ‘† ๐Ÿ’ช โš™๏ธ `jsonable_encoder` ๐Ÿ—œ ๐Ÿ”ข ๐Ÿ’ฝ ๐Ÿ“Š ๐Ÿ‘ˆ ๐Ÿ’ช ๐Ÿช ๐ŸŽป (โœ… โฎ๏ธ โ˜ ๐Ÿ’ฝ). ๐Ÿ–ผ, ๐Ÿญ `datetime` `str`.
=== "๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="30-35"
{!> ../../../docs_src/body_updates/tutorial001.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.9๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="30-35"
{!> ../../../docs_src/body_updates/tutorial001_py39.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.1๏ธโƒฃ0๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="28-33"
{!> ../../../docs_src/body_updates/tutorial001_py310.py!}
```
`PUT` โš™๏ธ ๐Ÿ“จ ๐Ÿ’ฝ ๐Ÿ‘ˆ ๐Ÿ”œ โŽ โ™ป ๐Ÿ’ฝ.
### โš  ๐Ÿ”ƒ โŽ
๐Ÿ‘ˆ โ›“ ๐Ÿ‘ˆ ๐Ÿšฅ ๐Ÿ‘† ๐Ÿ’š โ„น ๐Ÿฌ `bar` โš™๏ธ `PUT` โฎ๏ธ ๐Ÿ’ช โš—:
```Python
{
"name": "Barz",
"price": 3,
"description": None,
}
```
โ†ฉ๏ธ โšซ๏ธ ๐Ÿšซ ๐Ÿ”Œ โช ๐Ÿช ๐Ÿ”ข `"tax": 20.2`, ๐Ÿ”ข ๐Ÿท ๐Ÿ”œ โœŠ ๐Ÿ”ข ๐Ÿ’ฒ `"tax": 10.5`.
&amp; ๐Ÿ“Š ๐Ÿ”œ ๐Ÿ–Š โฎ๏ธ ๐Ÿ‘ˆ "๐Ÿ†•" `tax` `10.5`.
## ๐Ÿ• โ„น โฎ๏ธ `PATCH`
๐Ÿ‘† ๐Ÿ’ช โš™๏ธ <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/PATCH" class="external-link" target="_blank">๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ” `PATCH`</a> ๐Ÿ› ๏ธ *๐Ÿ•* โ„น ๐Ÿ’ฝ.
๐Ÿ‘‰ โ›“ ๐Ÿ‘ˆ ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ“จ ๐Ÿ•ด ๐Ÿ’ฝ ๐Ÿ‘ˆ ๐Ÿ‘† ๐Ÿ’š โ„น, ๐Ÿ‚ ๐ŸŽ‚ ๐Ÿฃ.
!!! Note
`PATCH` ๐ŸŒ˜ ๐Ÿ›Ž โš™๏ธ &amp; ๐Ÿ’ญ ๐ŸŒ˜ `PUT`.
&amp; ๐Ÿ“š ๐Ÿ‰ โš™๏ธ ๐Ÿ•ด `PUT`, ๐Ÿ• โ„น.
๐Ÿ‘† **๐Ÿ†“** โš™๏ธ ๐Ÿ‘ซ ๐Ÿ‘ ๐Ÿ‘† ๐Ÿ’š, **FastAPI** ๐Ÿšซ ๐Ÿšซ ๐Ÿ™† ๐Ÿšซ.
โœ‹๏ธ ๐Ÿ‘‰ ๐Ÿฆฎ ๐ŸŽฆ ๐Ÿ‘†, ๐ŸŒ– โš–๏ธ ๐ŸŒ˜, โ” ๐Ÿ‘ซ ๐ŸŽฏ โš™๏ธ.
### โš™๏ธ Pydantic `exclude_unset` ๐Ÿ”ข
๐Ÿšฅ ๐Ÿ‘† ๐Ÿ’š ๐Ÿ“จ ๐Ÿ• โ„น, โšซ๏ธ ๐Ÿ“ถ โš  โš™๏ธ ๐Ÿ”ข `exclude_unset` Pydantic ๐Ÿท `.dict()`.
๐Ÿ’– `item.dict(exclude_unset=True)`.
๐Ÿ‘ˆ ๐Ÿ”œ ๐Ÿ— `dict` โฎ๏ธ ๐Ÿ•ด ๐Ÿ’ฝ ๐Ÿ‘ˆ โš’ ๐Ÿ•โ” ๐Ÿ— `item` ๐Ÿท, ๐Ÿšซ ๐Ÿ”ข ๐Ÿ’ฒ.
โคด๏ธ ๐Ÿ‘† ๐Ÿ’ช โš™๏ธ ๐Ÿ‘‰ ๐Ÿ— `dict` โฎ๏ธ ๐Ÿ•ด ๐Ÿ’ฝ ๐Ÿ‘ˆ โš’ (๐Ÿ“จ ๐Ÿ“จ), ๐Ÿšซ ๐Ÿ”ข ๐Ÿ’ฒ:
=== "๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="34"
{!> ../../../docs_src/body_updates/tutorial002.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.9๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="34"
{!> ../../../docs_src/body_updates/tutorial002_py39.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.1๏ธโƒฃ0๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="32"
{!> ../../../docs_src/body_updates/tutorial002_py310.py!}
```
### โš™๏ธ Pydantic `update` ๐Ÿ”ข
๐Ÿ”œ, ๐Ÿ‘† ๐Ÿ’ช โœ ๐Ÿ“ โ™ป ๐Ÿท โš™๏ธ `.copy()`, &amp; ๐Ÿšถโ€โ™€๏ธ `update` ๐Ÿ”ข โฎ๏ธ `dict` โš— ๐Ÿ’ฝ โ„น.
๐Ÿ’– `stored_item_model.copy(update=update_data)`:
=== "๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="35"
{!> ../../../docs_src/body_updates/tutorial002.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.9๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="35"
{!> ../../../docs_src/body_updates/tutorial002_py39.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.1๏ธโƒฃ0๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="33"
{!> ../../../docs_src/body_updates/tutorial002_py310.py!}
```
### ๐Ÿ• โ„น ๐ŸŒƒ
๐Ÿ“„, โœ” ๐Ÿ• โ„น ๐Ÿ‘† ๐Ÿ”œ:
* (โš—) โš™๏ธ `PATCH` โ†ฉ๏ธ `PUT`.
* ๐Ÿ—ƒ ๐Ÿช ๐Ÿ’ฝ.
* ๐Ÿšฎ ๐Ÿ‘ˆ ๐Ÿ’ฝ Pydantic ๐Ÿท.
* ๐Ÿ— `dict` ๐Ÿต ๐Ÿ”ข ๐Ÿ’ฒ โšช๏ธโžก๏ธ ๐Ÿ”ข ๐Ÿท (โš™๏ธ `exclude_unset`).
* ๐Ÿ‘‰ ๐ŸŒŒ ๐Ÿ‘† ๐Ÿ’ช โ„น ๐Ÿ•ด ๐Ÿ’ฒ ๐Ÿค™ โš’ ๐Ÿ‘ฉโ€๐Ÿ’ป, โ†ฉ๏ธ ๐Ÿ” ๐Ÿ’ฒ โช ๐Ÿช โฎ๏ธ ๐Ÿ”ข ๐Ÿ’ฒ ๐Ÿ‘† ๐Ÿท.
* โœ ๐Ÿ“ ๐Ÿช ๐Ÿท, ๐Ÿ› ๏ธ โšซ๏ธ ๐Ÿ”ข โฎ๏ธ ๐Ÿ“จ ๐Ÿ• โ„น (โš™๏ธ `update` ๐Ÿ”ข).
* ๐Ÿ—œ ๐Ÿ“ ๐Ÿท ๐Ÿ•ณ ๐Ÿ‘ˆ ๐Ÿ’ช ๐Ÿช ๐Ÿ‘† ๐Ÿ’ฝ (๐Ÿ–ผ, โš™๏ธ `jsonable_encoder`).
* ๐Ÿ‘‰ โญ โš™๏ธ ๐Ÿท `.dict()` ๐Ÿ‘ฉโ€๐Ÿ”ฌ ๐Ÿ”„, โœ‹๏ธ โšซ๏ธ โš’ ๐Ÿ’ญ (&amp; ๐Ÿ—œ) ๐Ÿ’ฒ ๐Ÿ’ฝ ๐Ÿ†Ž ๐Ÿ‘ˆ ๐Ÿ’ช ๐Ÿ—œ ๐ŸŽป, ๐Ÿ–ผ, `datetime` `str`.
* ๐Ÿ–Š ๐Ÿ’ฝ ๐Ÿ‘† ๐Ÿ’ฝ.
* ๐Ÿ“จ โ„น ๐Ÿท.
=== "๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="30-37"
{!> ../../../docs_src/body_updates/tutorial002.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.9๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="30-37"
{!> ../../../docs_src/body_updates/tutorial002_py39.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.1๏ธโƒฃ0๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="28-35"
{!> ../../../docs_src/body_updates/tutorial002_py310.py!}
```
!!! tip
๐Ÿ‘† ๐Ÿ’ช ๐Ÿค™ โš™๏ธ ๐Ÿ‘‰ ๐ŸŽ โš’ โฎ๏ธ ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ” `PUT` ๐Ÿ› ๏ธ.
โœ‹๏ธ ๐Ÿ–ผ ๐Ÿ“ฅ โš™๏ธ `PATCH` โ†ฉ๏ธ โšซ๏ธ โœ ๐Ÿ‘ซ โš™๏ธ ๐Ÿ’ผ.
!!! note
๐Ÿ‘€ ๐Ÿ‘ˆ ๐Ÿ”ข ๐Ÿท โœ”.
, ๐Ÿšฅ ๐Ÿ‘† ๐Ÿ’š ๐Ÿ“จ ๐Ÿ• โ„น ๐Ÿ‘ˆ ๐Ÿ’ช ๐Ÿšซ ๐ŸŒ ๐Ÿ”ข, ๐Ÿ‘† ๐Ÿ’ช โœ”๏ธ ๐Ÿท โฎ๏ธ ๐ŸŒ ๐Ÿ”ข โ„ข ๐Ÿ“ฆ (โฎ๏ธ ๐Ÿ”ข ๐Ÿ’ฒ โš–๏ธ `None`).
๐Ÿ”ฌ โšช๏ธโžก๏ธ ๐Ÿท โฎ๏ธ ๐ŸŒ ๐Ÿ“ฆ ๐Ÿ’ฒ **โ„น** &amp; ๐Ÿท โฎ๏ธ โœ” ๐Ÿ’ฒ **๐Ÿ—**, ๐Ÿ‘† ๐Ÿ’ช โš™๏ธ ๐Ÿ’ญ ๐Ÿ”ฌ [โž• ๐Ÿท](extra-models.md){.internal-link target=_blank}.

213
docs/em/docs/tutorial/body.md

@ -0,0 +1,213 @@
# ๐Ÿ“จ ๐Ÿ’ช
๐Ÿ•โ” ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ“จ ๐Ÿ“Š โšช๏ธโžก๏ธ ๐Ÿ‘ฉโ€๐Ÿ’ป (โžก๏ธ ๐Ÿ’ฌ, ๐Ÿ–ฅ) ๐Ÿ‘† ๐Ÿ› ๏ธ, ๐Ÿ‘† ๐Ÿ“จ โšซ๏ธ **๐Ÿ“จ ๐Ÿ’ช**.
**๐Ÿ“จ** ๐Ÿ’ช ๐Ÿ“Š ๐Ÿ“จ ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ‘† ๐Ÿ› ๏ธ. **๐Ÿ“จ** ๐Ÿ’ช ๐Ÿ’ฝ ๐Ÿ‘† ๐Ÿ› ๏ธ ๐Ÿ“จ ๐Ÿ‘ฉโ€๐Ÿ’ป.
๐Ÿ‘† ๐Ÿ› ๏ธ ๐ŸŒ– ๐Ÿ•ง โœ”๏ธ ๐Ÿ“จ **๐Ÿ“จ** ๐Ÿ’ช. โœ‹๏ธ ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿšซ ๐ŸŽฏ ๐Ÿ’ช ๐Ÿ“จ **๐Ÿ“จ** ๐Ÿ’ช ๐ŸŒ ๐Ÿ•ฐ.
๐Ÿ“ฃ **๐Ÿ“จ** ๐Ÿ’ช, ๐Ÿ‘† โš™๏ธ <a href="https://pydantic-docs.helpmanual.io/" class="external-link" target="_blank">Pydantic</a> ๐Ÿท โฎ๏ธ ๐ŸŒ ๐Ÿ‘ซ ๐Ÿ‹๏ธ &amp; ๐Ÿ’ฐ.
!!! info
๐Ÿ“จ ๐Ÿ’ฝ, ๐Ÿ‘† ๐Ÿ”œ โš™๏ธ 1๏ธโƒฃ: `POST` (๐ŸŒ… โš ), `PUT`, `DELETE` โš–๏ธ `PATCH`.
๐Ÿ“จ ๐Ÿ’ช โฎ๏ธ `GET` ๐Ÿ“จ โœ”๏ธ โš  ๐ŸŽญ ๐Ÿ”ง, ๐Ÿ‘, โšซ๏ธ ๐Ÿ•โ€๐Ÿฆบ FastAPI, ๐Ÿ•ด ๐Ÿ“ถ ๐Ÿ—/๐Ÿ˜• โš™๏ธ ๐Ÿ’ผ.
โšซ๏ธ ๐Ÿšซ, ๐ŸŽ“ ๐Ÿฉบ โฎ๏ธ ๐Ÿฆ ๐ŸŽš ๐Ÿ† ๐Ÿšซ ๐ŸŽฆ ๐Ÿงพ ๐Ÿ’ช ๐Ÿ•โ” โš™๏ธ `GET`, &amp; ๐Ÿ—ณ ๐Ÿ–• ๐Ÿ’ช ๐Ÿšซ ๐Ÿ•โ€๐Ÿฆบ โšซ๏ธ.
## ๐Ÿ—„ Pydantic `BaseModel`
๐Ÿฅ‡, ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ—„ `BaseModel` โšช๏ธโžก๏ธ `pydantic`:
=== "๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="4"
{!> ../../../docs_src/body/tutorial001.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.1๏ธโƒฃ0๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="2"
{!> ../../../docs_src/body/tutorial001_py310.py!}
```
## โœ ๐Ÿ‘† ๐Ÿ’ฝ ๐Ÿท
โคด๏ธ ๐Ÿ‘† ๐Ÿ“ฃ ๐Ÿ‘† ๐Ÿ’ฝ ๐Ÿท ๐ŸŽ“ ๐Ÿ‘ˆ ๐Ÿ˜– โšช๏ธโžก๏ธ `BaseModel`.
โš™๏ธ ๐Ÿฉ ๐Ÿ ๐Ÿ†Ž ๐ŸŒ ๐Ÿ”ข:
=== "๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="7-11"
{!> ../../../docs_src/body/tutorial001.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.1๏ธโƒฃ0๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="5-9"
{!> ../../../docs_src/body/tutorial001_py310.py!}
```
๐ŸŽ ๐Ÿ•โ” ๐Ÿ“ฃ ๐Ÿ”ข ๐Ÿ”ข, ๐Ÿ•โ” ๐Ÿท ๐Ÿ”ข โœ”๏ธ ๐Ÿ”ข ๐Ÿ’ฒ, โšซ๏ธ ๐Ÿšซ โœ”. โช, โšซ๏ธ โœ”. โš™๏ธ `None` โš’ โšซ๏ธ ๐Ÿ“ฆ.
๐Ÿ–ผ, ๐Ÿ‘‰ ๐Ÿท ๐Ÿ”› ๐Ÿ“ฃ ๐ŸŽป "`object`" (โš–๏ธ ๐Ÿ `dict`) ๐Ÿ’–:
```JSON
{
"name": "Foo",
"description": "An optional description",
"price": 45.2,
"tax": 3.5
}
```
... `description` &amp; `tax` ๐Ÿ“ฆ (โฎ๏ธ ๐Ÿ”ข ๐Ÿ’ฒ `None`), ๐Ÿ‘‰ ๐ŸŽป "`object`" ๐Ÿ”œ โ˜‘:
```JSON
{
"name": "Foo",
"price": 45.2
}
```
## ๐Ÿ“ฃ โšซ๏ธ ๐Ÿ”ข
๐Ÿšฎ โšซ๏ธ ๐Ÿ‘† *โžก ๐Ÿ› ๏ธ*, ๐Ÿ“ฃ โšซ๏ธ ๐ŸŽ ๐ŸŒŒ ๐Ÿ‘† ๐Ÿ“ฃ โžก &amp; ๐Ÿ”ข ๐Ÿ”ข:
=== "๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="18"
{!> ../../../docs_src/body/tutorial001.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.1๏ธโƒฃ0๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="16"
{!> ../../../docs_src/body/tutorial001_py310.py!}
```
...&amp; ๐Ÿ“ฃ ๐Ÿšฎ ๐Ÿ†Ž ๐Ÿท ๐Ÿ‘† โœ, `Item`.
## ๐Ÿ
โฎ๏ธ ๐Ÿ‘ˆ ๐Ÿ ๐Ÿ†Ž ๐Ÿ“„, **FastAPI** ๐Ÿ”œ:
* โœ ๐Ÿ’ช ๐Ÿ“จ ๐ŸŽป.
* ๐Ÿ—œ ๐Ÿ”— ๐Ÿ†Ž (๐Ÿšฅ ๐Ÿ’ช).
* โœ” ๐Ÿ’ฝ.
* ๐Ÿšฅ ๐Ÿ’ฝ โŒ, โšซ๏ธ ๐Ÿ”œ ๐Ÿ“จ ๐Ÿ‘Œ &amp; ๐Ÿ†‘ โŒ, โ˜ ๏ธ โšซ๏ธโ” ๐ŸŒโ” &amp; โšซ๏ธโ” โŒ ๐Ÿ“Š.
* ๐Ÿค ๐Ÿ‘† ๐Ÿ“จ ๐Ÿ“Š ๐Ÿ”ข `item`.
* ๐Ÿ‘† ๐Ÿ“ฃ โšซ๏ธ ๐Ÿ”ข ๐Ÿ†Ž `Item`, ๐Ÿ‘† ๐Ÿ”œ โœ”๏ธ ๐ŸŒ ๐Ÿ‘จโ€๐ŸŽจ ๐Ÿ•โ€๐Ÿฆบ (๐Ÿ› ๏ธ, โ™’๏ธ) ๐ŸŒ ๐Ÿ”ข &amp; ๐Ÿ‘ซ ๐Ÿ†Ž.
* ๐Ÿ— <a href="https://json-schema.org" class="external-link" target="_blank">๐ŸŽป ๐Ÿ”—</a> ๐Ÿ”‘ ๐Ÿ‘† ๐Ÿท, ๐Ÿ‘† ๐Ÿ’ช โš™๏ธ ๐Ÿ‘ซ ๐Ÿ™† ๐Ÿ™† ๐Ÿ‘† ๐Ÿ’– ๐Ÿšฅ โšซ๏ธ โš’ ๐Ÿ”‘ ๐Ÿ‘† ๐Ÿ—.
* ๐Ÿ‘ˆ ๐Ÿ”— ๐Ÿ”œ ๐Ÿ• ๐Ÿ— ๐Ÿ—„ ๐Ÿ”—, &amp; โš™๏ธ ๐Ÿง ๐Ÿงพ <abbr title="User Interfaces">โšœ</abbr>.
## ๐Ÿง ๐Ÿฉบ
๐ŸŽป ๐Ÿ”— ๐Ÿ‘† ๐Ÿท ๐Ÿ”œ ๐Ÿ• ๐Ÿ‘† ๐Ÿ—„ ๐Ÿ— ๐Ÿ”—, &amp; ๐Ÿ”œ ๐ŸŽฆ ๐ŸŽ“ ๐Ÿ› ๏ธ ๐Ÿฉบ:
<img src="/img/tutorial/body/image01.png">
&amp; ๐Ÿ”œ โš™๏ธ ๐Ÿ› ๏ธ ๐Ÿฉบ ๐Ÿ”˜ ๐Ÿ”  *โžก ๐Ÿ› ๏ธ* ๐Ÿ‘ˆ ๐Ÿ’ช ๐Ÿ‘ซ:
<img src="/img/tutorial/body/image02.png">
## ๐Ÿ‘จโ€๐ŸŽจ ๐Ÿ•โ€๐Ÿฆบ
๐Ÿ‘† ๐Ÿ‘จโ€๐ŸŽจ, ๐Ÿ”˜ ๐Ÿ‘† ๐Ÿ”ข ๐Ÿ‘† ๐Ÿ”œ ๐Ÿคš ๐Ÿ†Ž ๐Ÿ”‘ &amp; ๐Ÿ› ๏ธ ๐ŸŒ (๐Ÿ‘‰ ๐Ÿšซ๐Ÿ”œ ๐Ÿ”จ ๐Ÿšฅ ๐Ÿ‘† ๐Ÿ“จ `dict` โ†ฉ๏ธ Pydantic ๐Ÿท):
<img src="/img/tutorial/body/image03.png">
๐Ÿ‘† ๐Ÿคš โŒ โœ… โŒ ๐Ÿ†Ž ๐Ÿ› ๏ธ:
<img src="/img/tutorial/body/image04.png">
๐Ÿ‘‰ ๐Ÿšซ ๐Ÿคž, ๐ŸŽ‚ ๐Ÿ› ๏ธ ๐Ÿ— ๐Ÿคญ ๐Ÿ‘ˆ ๐Ÿ”ง.
&amp; โšซ๏ธ ๐Ÿ™‡ ๐Ÿ’ฏ ๐Ÿ”ง ๐ŸŒ“, โญ ๐Ÿ™† ๐Ÿ› ๏ธ, ๐Ÿšš โšซ๏ธ ๐Ÿ”œ ๐Ÿ‘ท โฎ๏ธ ๐ŸŒ ๐Ÿ‘จโ€๐ŸŽจ.
๐Ÿ“ค ๐Ÿ”€ Pydantic โšซ๏ธ ๐Ÿ•โ€๐Ÿฆบ ๐Ÿ‘‰.
โฎ๏ธ ๐Ÿ–ผ โœŠ โฎ๏ธ <a href="https://code.visualstudio.com" class="external-link" target="_blank">๐ŸŽ™ ๐ŸŽ™ ๐Ÿ“Ÿ</a>.
โœ‹๏ธ ๐Ÿ‘† ๐Ÿ”œ ๐Ÿคš ๐ŸŽ ๐Ÿ‘จโ€๐ŸŽจ ๐Ÿ•โ€๐Ÿฆบ โฎ๏ธ <a href="https://www.jetbrains.com/pycharm/" class="external-link" target="_blank">๐Ÿ—’</a> &amp; ๐ŸŒ… ๐ŸŽ ๐Ÿ ๐Ÿ‘จโ€๐ŸŽจ:
<img src="/img/tutorial/body/image05.png">
!!! tip
๐Ÿšฅ ๐Ÿ‘† โš™๏ธ <a href="https://www.jetbrains.com/pycharm/" class="external-link" target="_blank">๐Ÿ—’</a> ๐Ÿ‘† ๐Ÿ‘จโ€๐ŸŽจ, ๐Ÿ‘† ๐Ÿ’ช โš™๏ธ <a href="https://github.com/koxudaxi/pydantic-pycharm-plugin/" class="external-link" target="_blank">Pydantic ๐Ÿ—’ ๐Ÿ“</a>.
โšซ๏ธ ๐Ÿ“‰ ๐Ÿ‘จโ€๐ŸŽจ ๐Ÿ•โ€๐Ÿฆบ Pydantic ๐Ÿท, โฎ๏ธ:
* ๐Ÿš˜-๐Ÿ› ๏ธ
* ๐Ÿ†Ž โœ…
* ๐Ÿ› ๏ธ
* ๐Ÿ”Ž
* ๐Ÿ”ฌ
## โš™๏ธ ๐Ÿท
๐Ÿ”˜ ๐Ÿ”ข, ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ” ๐ŸŒ ๐Ÿ”ข ๐Ÿท ๐ŸŽš ๐Ÿ”—:
=== "๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="21"
{!> ../../../docs_src/body/tutorial002.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.1๏ธโƒฃ0๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="19"
{!> ../../../docs_src/body/tutorial002_py310.py!}
```
## ๐Ÿ“จ ๐Ÿ’ช โž• โžก ๐Ÿ”ข
๐Ÿ‘† ๐Ÿ’ช ๐Ÿ“ฃ โžก ๐Ÿ”ข &amp; ๐Ÿ“จ ๐Ÿ’ช ๐ŸŽ ๐Ÿ•ฐ.
**FastAPI** ๐Ÿ”œ ๐Ÿค” ๐Ÿ‘ˆ ๐Ÿ”ข ๐Ÿ”ข ๐Ÿ‘ˆ ๐Ÿ โžก ๐Ÿ”ข ๐Ÿ”œ **โœŠ โšช๏ธโžก๏ธ โžก**, &amp; ๐Ÿ‘ˆ ๐Ÿ”ข ๐Ÿ”ข ๐Ÿ‘ˆ ๐Ÿ“ฃ Pydantic ๐Ÿท ๐Ÿ”œ **โœŠ โšช๏ธโžก๏ธ ๐Ÿ“จ ๐Ÿ’ช**.
=== "๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="17-18"
{!> ../../../docs_src/body/tutorial003.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.1๏ธโƒฃ0๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="15-16"
{!> ../../../docs_src/body/tutorial003_py310.py!}
```
## ๐Ÿ“จ ๐Ÿ’ช โž• โžก โž• ๐Ÿ”ข ๐Ÿ”ข
๐Ÿ‘† ๐Ÿ’ช ๐Ÿ“ฃ **๐Ÿ’ช**, **โžก** &amp; **๐Ÿ”ข** ๐Ÿ”ข, ๐ŸŒ ๐ŸŽ ๐Ÿ•ฐ.
**FastAPI** ๐Ÿ”œ ๐Ÿค” ๐Ÿ”  ๐Ÿ‘ซ &amp; โœŠ ๐Ÿ“Š โšช๏ธโžก๏ธ โ˜‘ ๐Ÿฅ‰.
=== "๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="18"
{!> ../../../docs_src/body/tutorial004.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.1๏ธโƒฃ0๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="16"
{!> ../../../docs_src/body/tutorial004_py310.py!}
```
๐Ÿ”ข ๐Ÿ”ข ๐Ÿ”œ ๐Ÿค” โฉ:
* ๐Ÿšฅ ๐Ÿ”ข ๐Ÿ“ฃ **โžก**, โšซ๏ธ ๐Ÿ”œ โš™๏ธ โžก ๐Ÿ”ข.
* ๐Ÿšฅ ๐Ÿ”ข **โญ ๐Ÿ†Ž** (๐Ÿ’– `int`, `float`, `str`, `bool`, โ™’๏ธ) โšซ๏ธ ๐Ÿ”œ ๐Ÿ”ฌ **๐Ÿ”ข** ๐Ÿ”ข.
* ๐Ÿšฅ ๐Ÿ”ข ๐Ÿ“ฃ ๐Ÿ†Ž **Pydantic ๐Ÿท**, โšซ๏ธ ๐Ÿ”œ ๐Ÿ”ฌ ๐Ÿ“จ **๐Ÿ’ช**.
!!! note
FastAPI ๐Ÿ”œ ๐Ÿ’ญ ๐Ÿ‘ˆ ๐Ÿ’ฒ `q` ๐Ÿšซ โœ” โ†ฉ๏ธ ๐Ÿ”ข ๐Ÿ’ฒ `= None`.
`Union` `Union[str, None]` ๐Ÿšซ โš™๏ธ FastAPI, โœ‹๏ธ ๐Ÿ”œ โœ” ๐Ÿ‘† ๐Ÿ‘จโ€๐ŸŽจ ๐Ÿค ๐Ÿ‘† ๐Ÿ‘ ๐Ÿ•โ€๐Ÿฆบ &amp; ๐Ÿ” โŒ.
## ๐Ÿต Pydantic
๐Ÿšฅ ๐Ÿ‘† ๐Ÿšซ ๐Ÿ’š โš™๏ธ Pydantic ๐Ÿท, ๐Ÿ‘† ๐Ÿ’ช โš™๏ธ **๐Ÿ’ช** ๐Ÿ”ข. ๐Ÿ‘€ ๐Ÿฉบ [๐Ÿ’ช - ๐Ÿ’— ๐Ÿ”ข: โญ ๐Ÿ’ฒ ๐Ÿ’ช](body-multiple-params.md#singular-values-in-body){.internal-link target=_blank}.

49
docs/em/docs/tutorial/cookie-params.md

@ -0,0 +1,49 @@
# ๐Ÿช ๐Ÿ”ข
๐Ÿ‘† ๐Ÿ’ช ๐Ÿ”ฌ ๐Ÿช ๐Ÿ”ข ๐ŸŽ ๐ŸŒŒ ๐Ÿ‘† ๐Ÿ”ฌ `Query` &amp; `Path` ๐Ÿ”ข.
## ๐Ÿ—„ `Cookie`
๐Ÿฅ‡ ๐Ÿ—„ `Cookie`:
=== "๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="3"
{!> ../../../docs_src/cookie_params/tutorial001.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.1๏ธโƒฃ0๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="1"
{!> ../../../docs_src/cookie_params/tutorial001_py310.py!}
```
## ๐Ÿ“ฃ `Cookie` ๐Ÿ”ข
โคด๏ธ ๐Ÿ“ฃ ๐Ÿช ๐Ÿ”ข โš™๏ธ ๐ŸŽ ๐Ÿ“Š โฎ๏ธ `Path` &amp; `Query`.
๐Ÿฅ‡ ๐Ÿ’ฒ ๐Ÿ”ข ๐Ÿ’ฒ, ๐Ÿ‘† ๐Ÿ’ช ๐Ÿšถโ€โ™€๏ธ ๐ŸŒ โž• ๐Ÿ”ฌ โš–๏ธ โœ ๐Ÿ”ข:
=== "๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="9"
{!> ../../../docs_src/cookie_params/tutorial001.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.1๏ธโƒฃ0๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="7"
{!> ../../../docs_src/cookie_params/tutorial001_py310.py!}
```
!!! note "๐Ÿ“ก โ„น"
`Cookie` "๐Ÿ‘ญ" ๐ŸŽ“ `Path` &amp; `Query`. โšซ๏ธ ๐Ÿ˜– โšช๏ธโžก๏ธ ๐ŸŽ โš  `Param` ๐ŸŽ“.
โœ‹๏ธ ๐Ÿ’ญ ๐Ÿ‘ˆ ๐Ÿ•โ” ๐Ÿ‘† ๐Ÿ—„ `Query`, `Path`, `Cookie` &amp; ๐ŸŽ โšช๏ธโžก๏ธ `fastapi`, ๐Ÿ‘ˆ ๐Ÿค™ ๐Ÿ”ข ๐Ÿ‘ˆ ๐Ÿ“จ ๐ŸŽ ๐ŸŽ“.
!!! info
๐Ÿ“ฃ ๐Ÿช, ๐Ÿ‘† ๐Ÿ’ช โš™๏ธ `Cookie`, โ†ฉ๏ธ โช ๐Ÿ”ข ๐Ÿ”œ ๐Ÿ”ฌ ๐Ÿ”ข ๐Ÿ”ข.
## ๐ŸŒƒ
๐Ÿ“ฃ ๐Ÿช โฎ๏ธ `Cookie`, โš™๏ธ ๐ŸŽ โš  โš“ `Query` &amp; `Path`.

84
docs/em/docs/tutorial/cors.md

@ -0,0 +1,84 @@
# โšœ (โœ–๏ธ-๐Ÿ‡จ๐Ÿ‡ณ โ„น ๐Ÿค)
<a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS" class="external-link" target="_blank">โšœ โš–๏ธ "โœ–๏ธ-๐Ÿ‡จ๐Ÿ‡ณ โ„น ๐Ÿค"</a> ๐Ÿ”— โš  ๐Ÿ•โ” ๐Ÿ•ธ ๐Ÿƒโ€โ™‚ ๐Ÿ–ฅ โœ”๏ธ ๐Ÿ•ธ ๐Ÿ“Ÿ ๐Ÿ‘ˆ ๐Ÿ”— โฎ๏ธ ๐Ÿ‘ฉโ€๐Ÿ’ป, &amp; ๐Ÿ‘ฉโ€๐Ÿ’ป ๐ŸŽ "๐Ÿ‡จ๐Ÿ‡ณ" ๐ŸŒ˜ ๐Ÿ•ธ.
## ๐Ÿ‡จ๐Ÿ‡ณ
๐Ÿ‡จ๐Ÿ‡ณ ๐ŸŒ€ ๐Ÿ› ๏ธ (`http`, `https`), ๐Ÿ†” (`myapp.com`, `localhost`, `localhost.tiangolo.com`), &amp; โ›ด (`80`, `443`, `8080`).
, ๐ŸŒ ๐Ÿ‘ซ ๐ŸŽ ๐Ÿ‡จ๐Ÿ‡ณ:
* `http://localhost`
* `https://localhost`
* `http://localhost:8080`
๐Ÿšฅ ๐Ÿ‘ซ ๐ŸŒ `localhost`, ๐Ÿ‘ซ โš™๏ธ ๐ŸŽ ๐Ÿ› ๏ธ โš–๏ธ โ›ด,, ๐Ÿ‘ซ ๐ŸŽ "๐Ÿ‡จ๐Ÿ‡ณ".
## ๐Ÿ”
, โžก๏ธ ๐Ÿ’ฌ ๐Ÿ‘† โœ”๏ธ ๐Ÿ•ธ ๐Ÿƒ ๐Ÿ‘† ๐Ÿ–ฅ `http://localhost:8080`, &amp; ๐Ÿšฎ ๐Ÿ•ธ ๐Ÿ”„ ๐Ÿ”— โฎ๏ธ ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿƒ `http://localhost` (โ†ฉ๏ธ ๐Ÿ‘ฅ ๐Ÿšซ โœ” โ›ด, ๐Ÿ–ฅ ๐Ÿ”œ ๐Ÿค” ๐Ÿ”ข โ›ด `80`).
โคด๏ธ, ๐Ÿ–ฅ ๐Ÿ”œ ๐Ÿ“จ ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ” `OPTIONS` ๐Ÿ“จ ๐Ÿ‘ฉโ€๐Ÿ’ป, &amp; ๐Ÿšฅ ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ“จ โ˜‘ ๐ŸŽš โœ” ๐Ÿ“ป โšช๏ธโžก๏ธ ๐Ÿ‘‰ ๐ŸŽ ๐Ÿ‡จ๐Ÿ‡ณ (`http://localhost:8080`) โคด๏ธ ๐Ÿ–ฅ ๐Ÿ”œ โžก๏ธ ๐Ÿ•ธ ๐Ÿ•ธ ๐Ÿ“จ ๐Ÿšฎ ๐Ÿ“จ ๐Ÿ‘ฉโ€๐Ÿ’ป.
๐Ÿ† ๐Ÿ‘‰, ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ”œ โœ”๏ธ ๐Ÿ“‡ "โœ” ๐Ÿ‡จ๐Ÿ‡ณ".
๐Ÿ‘‰ ๐Ÿ’ผ, โšซ๏ธ ๐Ÿ”œ โœ”๏ธ ๐Ÿ”Œ `http://localhost:8080` ๐Ÿ•ธ ๐Ÿ‘ท โ˜‘.
## ๐Ÿƒ
โšซ๏ธ ๐Ÿ’ช ๐Ÿ“ฃ ๐Ÿ“‡ `"*"` ("๐Ÿƒ") ๐Ÿ’ฌ ๐Ÿ‘ˆ ๐ŸŒ โœ”.
โœ‹๏ธ ๐Ÿ‘ˆ ๐Ÿ”œ ๐Ÿ•ด โœ” ๐ŸŽฏ ๐Ÿ†Ž ๐Ÿ“ป, ๐Ÿšซ ๐ŸŒ ๐Ÿ‘ˆ ๐Ÿ”Œ ๐ŸŽ“: ๐Ÿช, โœ” ๐ŸŽš ๐Ÿ’– ๐Ÿ“š โš™๏ธ โฎ๏ธ ๐Ÿ“จ ๐Ÿค, โ™’๏ธ.
, ๐ŸŒ ๐Ÿ‘ท โ˜‘, โšซ๏ธ ๐Ÿ‘ป โœ” ๐ŸŽฏ โœ” ๐Ÿ‡จ๐Ÿ‡ณ.
## โš™๏ธ `CORSMiddleware`
๐Ÿ‘† ๐Ÿ’ช ๐Ÿ”— โšซ๏ธ ๐Ÿ‘† **FastAPI** ๐Ÿˆธ โš™๏ธ `CORSMiddleware`.
* ๐Ÿ—„ `CORSMiddleware`.
* โœ ๐Ÿ“‡ โœ” ๐Ÿ‡จ๐Ÿ‡ณ (๐ŸŽป).
* ๐Ÿšฎ โšซ๏ธ "๐Ÿ› ๏ธ" ๐Ÿ‘† **FastAPI** ๐Ÿˆธ.
๐Ÿ‘† ๐Ÿ’ช โœ” ๐Ÿšฅ ๐Ÿ‘† ๐Ÿ‘ฉโ€๐Ÿ’ป โœ”:
* ๐ŸŽ“ (โœ” ๐ŸŽš, ๐Ÿช, โ™’๏ธ).
* ๐ŸŽฏ ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ” ๐Ÿ‘ฉโ€๐Ÿ”ฌ (`POST`, `PUT`) โš–๏ธ ๐ŸŒ ๐Ÿ‘ซ โฎ๏ธ ๐Ÿƒ `"*"`.
* ๐ŸŽฏ ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ” ๐ŸŽš โš–๏ธ ๐ŸŒ ๐Ÿ‘ซ โฎ๏ธ ๐Ÿƒ `"*"`.
```Python hl_lines="2 6-11 13-19"
{!../../../docs_src/cors/tutorial001.py!}
```
๐Ÿ”ข ๐Ÿ”ข โš™๏ธ `CORSMiddleware` ๐Ÿ› ๏ธ ๐Ÿšซ ๐Ÿ”ข, ๐Ÿ‘† ๐Ÿ”œ ๐Ÿ’ช ๐ŸŽฏ ๐Ÿ› ๏ธ ๐ŸŽฏ ๐Ÿ‡จ๐Ÿ‡ณ, ๐Ÿ‘ฉโ€๐Ÿ”ฌ, โš–๏ธ ๐ŸŽš, โœ” ๐Ÿ–ฅ โœ” โš™๏ธ ๐Ÿ‘ซ โœ–๏ธ-๐Ÿ†” ๐Ÿ”‘.
๐Ÿ“„ โŒ ๐Ÿ•โ€๐Ÿฆบ:
* `allow_origins` - ๐Ÿ“‡ ๐Ÿ‡จ๐Ÿ‡ณ ๐Ÿ‘ˆ ๐Ÿ”œ โœ” โš’ โœ–๏ธ-๐Ÿ‡จ๐Ÿ‡ณ ๐Ÿ“จ. ๐Ÿคถ โ“‚. `['https://example.org', 'https://www.example.org']`. ๐Ÿ‘† ๐Ÿ’ช โš™๏ธ `['*']` โœ” ๐Ÿ™† ๐Ÿ‡จ๐Ÿ‡ณ.
* `allow_origin_regex` - ๐ŸŽป ๐ŸŽป ๐Ÿ ๐Ÿ›ก ๐Ÿ‡จ๐Ÿ‡ณ ๐Ÿ‘ˆ ๐Ÿ”œ โœ” โš’ โœ–๏ธ-๐Ÿ‡จ๐Ÿ‡ณ ๐Ÿ“จ. โœ… `'https://.*\.example\.org'`.
* `allow_methods` - ๐Ÿ“‡ ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ” ๐Ÿ‘ฉโ€๐Ÿ”ฌ ๐Ÿ‘ˆ ๐Ÿ”œ โœ” โœ–๏ธ-๐Ÿ‡จ๐Ÿ‡ณ ๐Ÿ“จ. ๐Ÿ”ข `['GET']`. ๐Ÿ‘† ๐Ÿ’ช โš™๏ธ `['*']` โœ” ๐ŸŒ ๐Ÿฉ ๐Ÿ‘ฉโ€๐Ÿ”ฌ.
* `allow_headers` - ๐Ÿ“‡ ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ” ๐Ÿ“จ ๐ŸŽš ๐Ÿ‘ˆ ๐Ÿ”œ ๐Ÿ•โ€๐Ÿฆบ โœ–๏ธ-๐Ÿ‡จ๐Ÿ‡ณ ๐Ÿ“จ. ๐Ÿ”ข `[]`. ๐Ÿ‘† ๐Ÿ’ช โš™๏ธ `['*']` โœ” ๐ŸŒ ๐ŸŽš. `Accept`, `Accept-Language`, `Content-Language` &amp; `Content-Type` ๐ŸŽš ๐Ÿ•ง โœ” <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS#simple_requests" class="external-link" rel="noopener" target="_blank">๐Ÿ™… โšœ ๐Ÿ“จ</a>.
* `allow_credentials` - ๐ŸŽฆ ๐Ÿ‘ˆ ๐Ÿช ๐Ÿ”œ ๐Ÿ•โ€๐Ÿฆบ โœ–๏ธ-๐Ÿ‡จ๐Ÿ‡ณ ๐Ÿ“จ. ๐Ÿ”ข `False`. , `allow_origins` ๐Ÿšซ๐Ÿ”œ โš’ `['*']` ๐ŸŽ“ โœ”, ๐Ÿ‡จ๐Ÿ‡ณ ๐Ÿ”œ โœ”.
* `expose_headers` - ๐ŸŽฆ ๐Ÿ™† ๐Ÿ“จ ๐ŸŽš ๐Ÿ‘ˆ ๐Ÿ”œ โš’ โ™ฟ ๐Ÿ–ฅ. ๐Ÿ”ข `[]`.
* `max_age` - โš’ ๐Ÿ”† ๐Ÿ•ฐ ๐Ÿฅˆ ๐Ÿ–ฅ ๐Ÿ’พ โšœ ๐Ÿ“จ. ๐Ÿ”ข `600`.
๐Ÿ› ๏ธ ๐Ÿ“จ 2๏ธโƒฃ ๐ŸŽฏ ๐Ÿ†Ž ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ” ๐Ÿ“จ...
### โšœ ๐Ÿ›ซ ๐Ÿ“จ
๐Ÿ‘‰ ๐Ÿ™† `OPTIONS` ๐Ÿ“จ โฎ๏ธ `Origin` &amp; `Access-Control-Request-Method` ๐ŸŽš.
๐Ÿ‘‰ ๐Ÿ’ผ ๐Ÿ› ๏ธ ๐Ÿ”œ ๐Ÿ†˜ ๐Ÿ“จ ๐Ÿ“จ &amp; ๐Ÿ“จ โฎ๏ธ โ˜‘ โšœ ๐ŸŽš, &amp; ๐Ÿ‘ฏโ€โ™‚๏ธ `200` โš–๏ธ `400` ๐Ÿ“จ ๐ŸŽ“ ๐ŸŽฏ.
### ๐Ÿ™… ๐Ÿ“จ
๐Ÿ™† ๐Ÿ“จ โฎ๏ธ `Origin` ๐ŸŽš. ๐Ÿ‘‰ ๐Ÿ’ผ ๐Ÿ› ๏ธ ๐Ÿ”œ ๐Ÿšถโ€โ™€๏ธ ๐Ÿ“จ ๐Ÿ”˜ ๐Ÿ˜, โœ‹๏ธ ๐Ÿ”œ ๐Ÿ”Œ โ˜‘ โšœ ๐ŸŽš ๐Ÿ”› ๐Ÿ“จ.
## ๐ŸŒ… โ„น
๐ŸŒ– โ„น ๐Ÿ”ƒ <abbr title="Cross-Origin Resource Sharing">โšœ</abbr>, โœ… <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS" class="external-link" target="_blank">๐ŸฆŽ โšœ ๐Ÿงพ</a>.
!!! note "๐Ÿ“ก โ„น"
๐Ÿ‘† ๐Ÿ’ช โš™๏ธ `from starlette.middleware.cors import CORSMiddleware`.
**FastAPI** ๐Ÿšš ๐Ÿ“š ๐Ÿ› ๏ธ `fastapi.middleware` ๐Ÿช ๐Ÿ‘†, ๐Ÿ‘ฉโ€๐Ÿ’ป. โœ‹๏ธ ๐ŸŒ… ๐Ÿ’ช ๐Ÿ› ๏ธ ๐Ÿ‘Ÿ ๐Ÿ”— โšช๏ธโžก๏ธ ๐Ÿ’ƒ.

112
docs/em/docs/tutorial/debugging.md

@ -0,0 +1,112 @@
# ๐Ÿ› ๏ธ
๐Ÿ‘† ๐Ÿ’ช ๐Ÿ”— ๐Ÿ•น ๐Ÿ‘† ๐Ÿ‘จโ€๐ŸŽจ, ๐Ÿ–ผ โฎ๏ธ ๐ŸŽ™ ๐ŸŽ™ ๐Ÿ“Ÿ โš–๏ธ ๐Ÿ—’.
## ๐Ÿค™ `uvicorn`
๐Ÿ‘† FastAPI ๐Ÿˆธ, ๐Ÿ—„ &amp; ๐Ÿƒ `uvicorn` ๐Ÿ”—:
```Python hl_lines="1 15"
{!../../../docs_src/debugging/tutorial001.py!}
```
### ๐Ÿ”ƒ `__name__ == "__main__"`
๐Ÿ‘‘ ๐ŸŽฏ `__name__ == "__main__"` โœ”๏ธ ๐Ÿ“Ÿ ๐Ÿ‘ˆ ๐Ÿ› ๏ธ ๐Ÿ•โ” ๐Ÿ‘† ๐Ÿ“ ๐Ÿค™ โฎ๏ธ:
<div class="termy">
```console
$ python myapp.py
```
</div>
โœ‹๏ธ ๐Ÿšซ ๐Ÿค™ ๐Ÿ•โ” โž•1๏ธโƒฃ ๐Ÿ“ ๐Ÿ—„ โšซ๏ธ, ๐Ÿ’–:
```Python
from myapp import app
```
#### ๐ŸŒ… โ„น
โžก๏ธ ๐Ÿ’ฌ ๐Ÿ‘† ๐Ÿ“ ๐ŸŒŸ `myapp.py`.
๐Ÿšฅ ๐Ÿ‘† ๐Ÿƒ โšซ๏ธ โฎ๏ธ:
<div class="termy">
```console
$ python myapp.py
```
</div>
โคด๏ธ ๐Ÿ”— ๐Ÿ”ข `__name__` ๐Ÿ‘† ๐Ÿ“, โœ ๐Ÿ” ๐Ÿ, ๐Ÿ”œ โœ”๏ธ ๐Ÿ’ฒ ๐ŸŽป `"__main__"`.
, ๐Ÿ“„:
```Python
uvicorn.run(app, host="0.0.0.0", port=8000)
```
๐Ÿ”œ ๐Ÿƒ.
---
๐Ÿ‘‰ ๐Ÿ† ๐Ÿšซ ๐Ÿ”จ ๐Ÿšฅ ๐Ÿ‘† ๐Ÿ—„ ๐Ÿ‘ˆ ๐Ÿ•น (๐Ÿ“).
, ๐Ÿšฅ ๐Ÿ‘† โœ”๏ธ โž•1๏ธโƒฃ ๐Ÿ“ `importer.py` โฎ๏ธ:
```Python
from myapp import app
# Some more code
```
๐Ÿ‘ˆ ๐Ÿ’ผ, ๐Ÿง ๐Ÿ”ข ๐Ÿ”˜ `myapp.py` ๐Ÿ”œ ๐Ÿšซ โœ”๏ธ ๐Ÿ”ข `__name__` โฎ๏ธ ๐Ÿ’ฒ `"__main__"`.
, โธ:
```Python
uvicorn.run(app, host="0.0.0.0", port=8000)
```
๐Ÿ”œ ๐Ÿšซ ๐Ÿ› ๏ธ.
!!! info
๐ŸŒ… โ„น, โœ… <a href="https://docs.python.org/3/library/__main__.html" class="external-link" target="_blank">๐Ÿ›‚ ๐Ÿ ๐Ÿฉบ</a>.
## ๐Ÿƒ ๐Ÿ‘† ๐Ÿ“Ÿ โฎ๏ธ ๐Ÿ‘† ๐Ÿ•น
โ†ฉ๏ธ ๐Ÿ‘† ๐Ÿƒ Uvicorn ๐Ÿ’ฝ ๐Ÿ”— โšช๏ธโžก๏ธ ๐Ÿ‘† ๐Ÿ“Ÿ, ๐Ÿ‘† ๐Ÿ’ช ๐Ÿค™ ๐Ÿ‘† ๐Ÿ ๐Ÿ“‹ (๐Ÿ‘† FastAPI ๐Ÿˆธ) ๐Ÿ”— โšช๏ธโžก๏ธ ๐Ÿ•น.
---
๐Ÿ–ผ, ๐ŸŽ™ ๐ŸŽ™ ๐Ÿ“Ÿ, ๐Ÿ‘† ๐Ÿ’ช:
* ๐Ÿšถ "โ„น" ๐ŸŽ›.
* "๐Ÿšฎ ๐Ÿ“ณ...".
* ๐Ÿ–Š "๐Ÿ"
* ๐Ÿƒ ๐Ÿ•น โฎ๏ธ ๐ŸŽ› "`Python: Current File (Integrated Terminal)`".
โšซ๏ธ ๐Ÿ”œ โคด๏ธ โ–ถ๏ธ ๐Ÿ’ฝ โฎ๏ธ ๐Ÿ‘† **FastAPI** ๐Ÿ“Ÿ, โ›”๏ธ ๐Ÿ‘† 0๏ธโƒฃ, โ™’๏ธ.
๐Ÿ“ฅ โ” โšซ๏ธ ๐Ÿ’ช ๐Ÿ‘€:
<img src="/img/tutorial/debugging/image01.png">
---
๐Ÿšฅ ๐Ÿ‘† โš™๏ธ ๐Ÿ—’, ๐Ÿ‘† ๐Ÿ’ช:
* ๐Ÿ“‚ "๐Ÿƒ" ๐Ÿฃ.
* ๐Ÿ–Š ๐ŸŽ› "โ„น...".
* โคด๏ธ ๐Ÿ”‘ ๐Ÿฃ ๐ŸŽฆ ๐Ÿ†™.
* ๐Ÿ–Š ๐Ÿ“ โ„น (๐Ÿ‘‰ ๐Ÿ’ผ, `main.py`).
โšซ๏ธ ๐Ÿ”œ โคด๏ธ โ–ถ๏ธ ๐Ÿ’ฝ โฎ๏ธ ๐Ÿ‘† **FastAPI** ๐Ÿ“Ÿ, โ›”๏ธ ๐Ÿ‘† 0๏ธโƒฃ, โ™’๏ธ.
๐Ÿ“ฅ โ” โšซ๏ธ ๐Ÿ’ช ๐Ÿ‘€:
<img src="/img/tutorial/debugging/image02.png">

247
docs/em/docs/tutorial/dependencies/classes-as-dependencies.md

@ -0,0 +1,247 @@
# ๐ŸŽ“ ๐Ÿ”—
โญ ๐Ÿคฟ โฌ ๐Ÿ”˜ **๐Ÿ”— ๐Ÿ’‰** โš™๏ธ, โžก๏ธ โ™ป โฎ๏ธ ๐Ÿ–ผ.
## `dict` โšช๏ธโžก๏ธ โฎ๏ธ ๐Ÿ–ผ
โฎ๏ธ ๐Ÿ–ผ, ๐Ÿ‘ฅ ๐Ÿ›ฌ `dict` โšช๏ธโžก๏ธ ๐Ÿ‘† ๐Ÿ”— ("โ˜‘"):
=== "๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="9"
{!> ../../../docs_src/dependencies/tutorial001.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.1๏ธโƒฃ0๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="7"
{!> ../../../docs_src/dependencies/tutorial001_py310.py!}
```
โœ‹๏ธ โคด๏ธ ๐Ÿ‘ฅ ๐Ÿคš `dict` ๐Ÿ”ข `commons` *โžก ๐Ÿ› ๏ธ ๐Ÿ”ข*.
&amp; ๐Ÿ‘ฅ ๐Ÿ’ญ ๐Ÿ‘ˆ ๐Ÿ‘จโ€๐ŸŽจ ๐Ÿ’ช ๐Ÿšซ ๐Ÿšš ๐Ÿ“š ๐Ÿ•โ€๐Ÿฆบ (๐Ÿ’– ๐Ÿ› ๏ธ) `dict`โ“‚, โ†ฉ๏ธ ๐Ÿ‘ซ ๐Ÿ’ช ๐Ÿšซ ๐Ÿ’ญ ๐Ÿ‘ซ ๐Ÿ”‘ &amp; ๐Ÿ’ฒ ๐Ÿ†Ž.
๐Ÿ‘ฅ ๐Ÿ’ช ๐Ÿ‘...
## โšซ๏ธโ” โš’ ๐Ÿ”—
๐Ÿ†™ ๐Ÿ”œ ๐Ÿ‘† โœ”๏ธ ๐Ÿ‘€ ๐Ÿ”— ๐Ÿ“ฃ ๐Ÿ”ข.
โœ‹๏ธ ๐Ÿ‘ˆ ๐Ÿšซ ๐Ÿ•ด ๐ŸŒŒ ๐Ÿ“ฃ ๐Ÿ”— (๐Ÿ‘ โšซ๏ธ ๐Ÿ”œ ๐ŸŽฒ ๐ŸŒ– โš ).
๐Ÿ”‘ โš– ๐Ÿ‘ˆ ๐Ÿ”— ๐Ÿ”œ "๐Ÿ‡ง๐Ÿ‡ฒ".
"**๐Ÿ‡ง๐Ÿ‡ฒ**" ๐Ÿ ๐Ÿ•ณ ๐Ÿ‘ˆ ๐Ÿ ๐Ÿ’ช "๐Ÿค™" ๐Ÿ’– ๐Ÿ”ข.
, ๐Ÿšฅ ๐Ÿ‘† โœ”๏ธ ๐ŸŽš `something` (๐Ÿ‘ˆ ๐Ÿ’ช _๐Ÿšซ_ ๐Ÿ”ข) &amp; ๐Ÿ‘† ๐Ÿ’ช "๐Ÿค™" โšซ๏ธ (๐Ÿ› ๏ธ โšซ๏ธ) ๐Ÿ’–:
```Python
something()
```
โš–๏ธ
```Python
something(some_argument, some_keyword_argument="foo")
```
โคด๏ธ โšซ๏ธ "๐Ÿ‡ง๐Ÿ‡ฒ".
## ๐ŸŽ“ ๐Ÿ”—
๐Ÿ‘† 5๏ธโƒฃ๐Ÿ“† ๐Ÿ‘€ ๐Ÿ‘ˆ โœ ๐Ÿ‘ ๐Ÿ ๐ŸŽ“, ๐Ÿ‘† โš™๏ธ ๐Ÿ‘ˆ ๐ŸŽ โ•.
๐Ÿ–ผ:
```Python
class Cat:
def __init__(self, name: str):
self.name = name
fluffy = Cat(name="Mr Fluffy")
```
๐Ÿ‘‰ ๐Ÿ’ผ, `fluffy` ๐Ÿ‘ ๐ŸŽ“ `Cat`.
&amp; โœ `fluffy`, ๐Ÿ‘† "๐Ÿค™" `Cat`.
, ๐Ÿ ๐ŸŽ“ **๐Ÿ‡ง๐Ÿ‡ฒ**.
โคด๏ธ, **FastAPI**, ๐Ÿ‘† ๐Ÿ’ช โš™๏ธ ๐Ÿ ๐ŸŽ“ ๐Ÿ”—.
โšซ๏ธโ” FastAPI ๐Ÿค™ โœ… ๐Ÿ‘ˆ โšซ๏ธ "๐Ÿ‡ง๐Ÿ‡ฒ" (๐Ÿ”ข, ๐ŸŽ“ โš–๏ธ ๐Ÿ•ณ ๐Ÿ™†) &amp; ๐Ÿ”ข ๐Ÿ”ฌ.
๐Ÿšฅ ๐Ÿ‘† ๐Ÿšถโ€โ™€๏ธ "๐Ÿ‡ง๐Ÿ‡ฒ" ๐Ÿ”— **FastAPI**, โšซ๏ธ ๐Ÿ”œ ๐Ÿ”ฌ ๐Ÿ”ข ๐Ÿ‘ˆ "๐Ÿ‡ง๐Ÿ‡ฒ", &amp; ๐Ÿ› ๏ธ ๐Ÿ‘ซ ๐ŸŽ ๐ŸŒŒ ๐Ÿ”ข *โžก ๐Ÿ› ๏ธ ๐Ÿ”ข*. โœ… ๐ŸŽง-๐Ÿ”—.
๐Ÿ‘ˆ โœ” ๐Ÿ‡ง๐Ÿ‡ฒ โฎ๏ธ ๐Ÿ™…โ€โ™‚ ๐Ÿ”ข ๐ŸŒ. ๐ŸŽ โšซ๏ธ ๐Ÿ”œ *โžก ๐Ÿ› ๏ธ ๐Ÿ”ข* โฎ๏ธ ๐Ÿ™…โ€โ™‚ ๐Ÿ”ข.
โคด๏ธ, ๐Ÿ‘ฅ ๐Ÿ’ช ๐Ÿ”€ ๐Ÿ”— "โ˜‘" `common_parameters` โšช๏ธโžก๏ธ ๐Ÿ”› ๐ŸŽ“ `CommonQueryParams`:
=== "๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="11-15"
{!> ../../../docs_src/dependencies/tutorial002.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.1๏ธโƒฃ0๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="9-13"
{!> ../../../docs_src/dependencies/tutorial002_py310.py!}
```
๐Ÿ’ธ ๐Ÿ™‹ `__init__` ๐Ÿ‘ฉโ€๐Ÿ”ฌ โš™๏ธ โœ ๐Ÿ‘ ๐ŸŽ“:
=== "๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="12"
{!> ../../../docs_src/dependencies/tutorial002.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.1๏ธโƒฃ0๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="10"
{!> ../../../docs_src/dependencies/tutorial002_py310.py!}
```
...โšซ๏ธ โœ”๏ธ ๐ŸŽ ๐Ÿ”ข ๐Ÿ‘† โฎ๏ธ `common_parameters`:
=== "๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="9"
{!> ../../../docs_src/dependencies/tutorial001.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.1๏ธโƒฃ0๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="6"
{!> ../../../docs_src/dependencies/tutorial001_py310.py!}
```
๐Ÿ“š ๐Ÿ”ข โšซ๏ธโ” **FastAPI** ๐Ÿ”œ โš™๏ธ "โŽ" ๐Ÿ”—.
๐Ÿ‘ฏโ€โ™‚๏ธ ๐Ÿ’ผ, โšซ๏ธ ๐Ÿ”œ โœ”๏ธ:
* ๐Ÿ“ฆ `q` ๐Ÿ”ข ๐Ÿ”ข ๐Ÿ‘ˆ `str`.
* `skip` ๐Ÿ”ข ๐Ÿ”ข ๐Ÿ‘ˆ `int`, โฎ๏ธ ๐Ÿ”ข `0`.
* `limit` ๐Ÿ”ข ๐Ÿ”ข ๐Ÿ‘ˆ `int`, โฎ๏ธ ๐Ÿ”ข `100`.
๐Ÿ‘ฏโ€โ™‚๏ธ ๐Ÿ’ผ ๐Ÿ’ฝ ๐Ÿ”œ ๐Ÿ—œ, โœ”, ๐Ÿ“„ ๐Ÿ”› ๐Ÿ—„ ๐Ÿ”—, โ™’๏ธ.
## โš™๏ธ โšซ๏ธ
๐Ÿ”œ ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ“ฃ ๐Ÿ‘† ๐Ÿ”— โš™๏ธ ๐Ÿ‘‰ ๐ŸŽ“.
=== "๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="19"
{!> ../../../docs_src/dependencies/tutorial002.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.1๏ธโƒฃ0๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="17"
{!> ../../../docs_src/dependencies/tutorial002_py310.py!}
```
**FastAPI** ๐Ÿค™ `CommonQueryParams` ๐ŸŽ“. ๐Ÿ‘‰ โœ "๐Ÿ‘" ๐Ÿ‘ˆ ๐ŸŽ“ &amp; ๐Ÿ‘ ๐Ÿ”œ ๐Ÿšถโ€โ™€๏ธ ๐Ÿ”ข `commons` ๐Ÿ‘† ๐Ÿ”ข.
## ๐Ÿ†Ž โœ ๐Ÿ†š `Depends`
๐Ÿ‘€ โ” ๐Ÿ‘ฅ โœ `CommonQueryParams` ๐Ÿ• ๐Ÿ”› ๐Ÿ“Ÿ:
```Python
commons: CommonQueryParams = Depends(CommonQueryParams)
```
๐Ÿ `CommonQueryParams`,:
```Python
... = Depends(CommonQueryParams)
```
...โšซ๏ธโ” **FastAPI** ๐Ÿ”œ ๐Ÿค™ โš™๏ธ ๐Ÿ’ญ โšซ๏ธโ” ๐Ÿ”—.
โšช๏ธโžก๏ธ โšซ๏ธ ๐Ÿ‘ˆ FastAPI ๐Ÿ”œ โš— ๐Ÿ“ฃ ๐Ÿ”ข &amp; ๐Ÿ‘ˆ โšซ๏ธโ” FastAPI ๐Ÿ”œ ๐Ÿค™ ๐Ÿค™.
---
๐Ÿ‘‰ ๐Ÿ’ผ, ๐Ÿฅ‡ `CommonQueryParams`,:
```Python
commons: CommonQueryParams ...
```
...๐Ÿšซ โœ”๏ธ ๐Ÿ™† ๐ŸŽ ๐Ÿ”‘ **FastAPI**. FastAPI ๐Ÿ† ๐Ÿšซ โš™๏ธ โšซ๏ธ ๐Ÿ’ฝ ๐Ÿ› ๏ธ, ๐Ÿ”ฌ, โ™’๏ธ. (โšซ๏ธ โš™๏ธ `= Depends(CommonQueryParams)` ๐Ÿ‘ˆ).
๐Ÿ‘† ๐Ÿ’ช ๐Ÿค™ โœ:
```Python
commons = Depends(CommonQueryParams)
```
...:
=== "๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="19"
{!> ../../../docs_src/dependencies/tutorial003.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.1๏ธโƒฃ0๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="17"
{!> ../../../docs_src/dependencies/tutorial003_py310.py!}
```
โœ‹๏ธ ๐Ÿ“ฃ ๐Ÿ†Ž ๐Ÿ’ก ๐Ÿ‘ˆ ๐ŸŒŒ ๐Ÿ‘† ๐Ÿ‘จโ€๐ŸŽจ ๐Ÿ”œ ๐Ÿ’ญ โšซ๏ธโ” ๐Ÿ”œ ๐Ÿšถโ€โ™€๏ธ ๐Ÿ”ข `commons`, &amp; โคด๏ธ โšซ๏ธ ๐Ÿ’ช โ„น ๐Ÿ‘† โฎ๏ธ ๐Ÿ“Ÿ ๐Ÿ› ๏ธ, ๐Ÿ†Ž โœ…, โ™’๏ธ:
<img src="/img/tutorial/dependencies/image02.png">
## โŒจ
โœ‹๏ธ ๐Ÿ‘† ๐Ÿ‘€ ๐Ÿ‘ˆ ๐Ÿ‘ฅ โœ”๏ธ ๐Ÿ“Ÿ ๐Ÿ” ๐Ÿ“ฅ, โœ `CommonQueryParams` ๐Ÿ•:
```Python
commons: CommonQueryParams = Depends(CommonQueryParams)
```
**FastAPI** ๐Ÿšš โŒจ ๐Ÿ‘ซ ๐Ÿ’ผ, ๐ŸŒโ” ๐Ÿ”— *๐ŸŽฏ* ๐ŸŽ“ ๐Ÿ‘ˆ **FastAPI** ๐Ÿ”œ "๐Ÿค™" โœ ๐Ÿ‘ ๐ŸŽ“ โšซ๏ธ.
๐Ÿ“š ๐ŸŽฏ ๐Ÿ’ผ, ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ“„:
โ†ฉ๏ธ โœ:
```Python
commons: CommonQueryParams = Depends(CommonQueryParams)
```
...๐Ÿ‘† โœ:
```Python
commons: CommonQueryParams = Depends()
```
๐Ÿ‘† ๐Ÿ“ฃ ๐Ÿ”— ๐Ÿ†Ž ๐Ÿ”ข, &amp; ๐Ÿ‘† โš™๏ธ `Depends()` ๐Ÿšฎ "๐Ÿ”ข" ๐Ÿ’ฒ (๐Ÿ‘ˆ โฎ๏ธ `=`) ๐Ÿ‘ˆ ๐Ÿ”ข ๐Ÿ”ข, ๐Ÿต ๐Ÿ™† ๐Ÿ”ข `Depends()`, โ†ฉ๏ธ โœ”๏ธ โœ ๐ŸŒ• ๐ŸŽ“ *๐Ÿ”„* ๐Ÿ”˜ `Depends(CommonQueryParams)`.
๐ŸŽ ๐Ÿ–ผ ๐Ÿ”œ โคด๏ธ ๐Ÿ‘€ ๐Ÿ’–:
=== "๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="19"
{!> ../../../docs_src/dependencies/tutorial004.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.1๏ธโƒฃ0๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="17"
{!> ../../../docs_src/dependencies/tutorial004_py310.py!}
```
...&amp; **FastAPI** ๐Ÿ”œ ๐Ÿ’ญ โšซ๏ธโ”.
!!! tip
๐Ÿšฅ ๐Ÿ‘ˆ ๐Ÿ˜‘ ๐ŸŒ… ๐Ÿ˜จ ๐ŸŒ˜ ๐Ÿ‘, ๐Ÿคทโ€โ™‚ โšซ๏ธ, ๐Ÿ‘† ๐Ÿšซ *๐Ÿ’ช* โšซ๏ธ.
โšซ๏ธ โŒจ. โ†ฉ๏ธ **FastAPI** ๐Ÿ’… ๐Ÿ”ƒ ๐Ÿค ๐Ÿ‘† ๐Ÿ“‰ ๐Ÿ“Ÿ ๐Ÿ”.

71
docs/em/docs/tutorial/dependencies/dependencies-in-path-operation-decorators.md

@ -0,0 +1,71 @@
# ๐Ÿ”— โžก ๐Ÿ› ๏ธ ๐Ÿ‘จโ€๐ŸŽจ
๐Ÿ’ผ ๐Ÿ‘† ๐Ÿšซ ๐Ÿค™ ๐Ÿ’ช ๐Ÿ“จ ๐Ÿ’ฒ ๐Ÿ”— ๐Ÿ”˜ ๐Ÿ‘† *โžก ๐Ÿ› ๏ธ ๐Ÿ”ข*.
โš–๏ธ ๐Ÿ”— ๐Ÿšซ ๐Ÿ“จ ๐Ÿ’ฒ.
โœ‹๏ธ ๐Ÿ‘† ๐Ÿ’ช โšซ๏ธ ๐Ÿ› ๏ธ/โŽ.
๐Ÿ“š ๐Ÿ’ผ, โ†ฉ๏ธ ๐Ÿ“ฃ *โžก ๐Ÿ› ๏ธ ๐Ÿ”ข* ๐Ÿ”ข โฎ๏ธ `Depends`, ๐Ÿ‘† ๐Ÿ’ช ๐Ÿšฎ `list` `dependencies` *โžก ๐Ÿ› ๏ธ ๐Ÿ‘จโ€๐ŸŽจ*.
## ๐Ÿšฎ `dependencies` *โžก ๐Ÿ› ๏ธ ๐Ÿ‘จโ€๐ŸŽจ*
*โžก ๐Ÿ› ๏ธ ๐Ÿ‘จโ€๐ŸŽจ* ๐Ÿ“จ ๐Ÿ“ฆ โŒ `dependencies`.
โšซ๏ธ ๐Ÿ”œ `list` `Depends()`:
```Python hl_lines="17"
{!../../../docs_src/dependencies/tutorial006.py!}
```
๐Ÿ‘‰ ๐Ÿ”— ๐Ÿ”œ ๐Ÿ› ๏ธ/โŽ ๐ŸŽ ๐ŸŒŒ ๐Ÿ˜ ๐Ÿ”—. โœ‹๏ธ ๐Ÿ‘ซ ๐Ÿ’ฒ (๐Ÿšฅ ๐Ÿ‘ซ ๐Ÿ“จ ๐Ÿ™†) ๐Ÿ† ๐Ÿšซ ๐Ÿšถโ€โ™€๏ธ ๐Ÿ‘† *โžก ๐Ÿ› ๏ธ ๐Ÿ”ข*.
!!! tip
๐Ÿ‘จโ€๐ŸŽจ โœ… โ™ป ๐Ÿ”ข ๐Ÿ”ข, &amp; ๐ŸŽฆ ๐Ÿ‘ซ โŒ.
โš™๏ธ ๐Ÿ‘‰ `dependencies` *โžก ๐Ÿ› ๏ธ ๐Ÿ‘จโ€๐ŸŽจ* ๐Ÿ‘† ๐Ÿ’ช โš’ ๐Ÿ’ญ ๐Ÿ‘ซ ๐Ÿ› ๏ธ โช โŽ ๐Ÿ‘จโ€๐ŸŽจ/๐Ÿญ โŒ.
โšซ๏ธ ๐Ÿ’ช โ„น โŽ ๐Ÿ˜จ ๐Ÿ†• ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ‘ˆ ๐Ÿ‘€ โ™ป ๐Ÿ”ข ๐Ÿ‘† ๐Ÿ“Ÿ &amp; ๐Ÿ’ช ๐Ÿ’ญ โšซ๏ธ ๐Ÿ™ƒ.
!!! info
๐Ÿ‘‰ ๐Ÿ–ผ ๐Ÿ‘ฅ โš™๏ธ ๐Ÿ’ญ ๐Ÿ›ƒ ๐ŸŽš `X-Key` &amp; `X-Token`.
โœ‹๏ธ ๐ŸŽฐ ๐Ÿ’ผ, ๐Ÿ•โ” ๐Ÿ› ๏ธ ๐Ÿ’‚โ€โ™‚, ๐Ÿ‘† ๐Ÿ”œ ๐Ÿคš ๐ŸŒ– ๐Ÿ’ฐ โšช๏ธโžก๏ธ โš™๏ธ ๐Ÿ› ๏ธ [๐Ÿ’‚โ€โ™‚ ๐Ÿš™ (โญ ๐Ÿ“ƒ)](../security/index.md){.internal-link target=_blank}.
## ๐Ÿ”— โŒ &amp; ๐Ÿ“จ ๐Ÿ’ฒ
๐Ÿ‘† ๐Ÿ’ช โš™๏ธ ๐ŸŽ ๐Ÿ”— *๐Ÿ”ข* ๐Ÿ‘† โš™๏ธ ๐Ÿ›Ž.
### ๐Ÿ”— ๐Ÿ“„
๐Ÿ‘ซ ๐Ÿ’ช ๐Ÿ“ฃ ๐Ÿ“จ ๐Ÿ“„ (๐Ÿ’– ๐ŸŽš) โš–๏ธ ๐ŸŽ ๐ŸŽง-๐Ÿ”—:
```Python hl_lines="6 11"
{!../../../docs_src/dependencies/tutorial006.py!}
```
### ๐Ÿคš โš 
๐Ÿ‘ซ ๐Ÿ”— ๐Ÿ’ช `raise` โš , ๐ŸŽ ๐Ÿ˜ ๐Ÿ”—:
```Python hl_lines="8 13"
{!../../../docs_src/dependencies/tutorial006.py!}
```
### ๐Ÿ“จ ๐Ÿ’ฒ
&amp; ๐Ÿ‘ซ ๐Ÿ’ช ๐Ÿ“จ ๐Ÿ’ฒ โš–๏ธ ๐Ÿšซ, ๐Ÿ’ฒ ๐Ÿ† ๐Ÿšซ โš™๏ธ.
, ๐Ÿ‘† ๐Ÿ’ช ๐Ÿค-โš™๏ธ ๐Ÿ˜ ๐Ÿ”— (๐Ÿ‘ˆ ๐Ÿ“จ ๐Ÿ’ฒ) ๐Ÿ‘† โช โš™๏ธ ๐Ÿ‘ฑ ๐Ÿ™†, &amp; โœ‹๏ธ ๐Ÿ’ฒ ๐Ÿ† ๐Ÿšซ โš™๏ธ, ๐Ÿ”— ๐Ÿ”œ ๐Ÿ› ๏ธ:
```Python hl_lines="9 14"
{!../../../docs_src/dependencies/tutorial006.py!}
```
## ๐Ÿ”— ๐Ÿ‘ช *โžก ๐Ÿ› ๏ธ*
โช, ๐Ÿ•โ” ๐Ÿ‘‚ ๐Ÿ”ƒ โ” ๐Ÿ“Š ๐Ÿฆ ๐Ÿˆธ ([๐Ÿฆ ๐Ÿˆธ - ๐Ÿ’— ๐Ÿ“](../../tutorial/bigger-applications.md){.internal-link target=_blank}), ๐ŸŽฒ โฎ๏ธ ๐Ÿ’— ๐Ÿ“, ๐Ÿ‘† ๐Ÿ”œ ๐Ÿ’ก โ” ๐Ÿ“ฃ ๐Ÿ‘ `dependencies` ๐Ÿ”ข ๐Ÿ‘ช *โžก ๐Ÿ› ๏ธ*.
## ๐ŸŒ ๐Ÿ”—
โญ ๐Ÿ‘ฅ ๐Ÿ”œ ๐Ÿ‘€ โ” ๐Ÿšฎ ๐Ÿ”— ๐ŸŽ‚ `FastAPI` ๐Ÿˆธ, ๐Ÿ‘ˆ ๐Ÿ‘ซ โœ” ๐Ÿ”  *โžก ๐Ÿ› ๏ธ*.

219
docs/em/docs/tutorial/dependencies/dependencies-with-yield.md

@ -0,0 +1,219 @@
# ๐Ÿ”— โฎ๏ธ ๐ŸŒพ
FastAPI ๐Ÿ•โ€๐Ÿฆบ ๐Ÿ”— ๐Ÿ‘ˆ <abbr title='sometimes also called "exit", "cleanup", "teardown", "close", "context managers", ...'>โž• ๐Ÿ” โฎ๏ธ ๐Ÿ</abbr>.
๐Ÿ‘‰, โš™๏ธ `yield` โ†ฉ๏ธ `return`, &amp; โœ โž• ๐Ÿ” โฎ๏ธ.
!!! tip
โš’ ๐Ÿ’ญ โš™๏ธ `yield` 1๏ธโƒฃ ๐Ÿ‘ ๐Ÿ•ฐ.
!!! note "๐Ÿ“ก โ„น"
๐Ÿ™† ๐Ÿ”ข ๐Ÿ‘ˆ โ˜‘ โš™๏ธ โฎ๏ธ:
* <a href="https://docs.python.org/3/library/contextlib.html#contextlib.contextmanager" class="external-link" target="_blank">`@contextlib.contextmanager`</a> โš–๏ธ
* <a href="https://docs.python.org/3/library/contextlib.html#contextlib.asynccontextmanager" class="external-link" target="_blank">`@contextlib.asynccontextmanager`</a>
๐Ÿ”œ โ˜‘ โš™๏ธ **FastAPI** ๐Ÿ”—.
๐Ÿ‘, FastAPI โš™๏ธ ๐Ÿ“š 2๏ธโƒฃ ๐Ÿ‘จโ€๐ŸŽจ ๐Ÿ”˜.
## ๐Ÿ’ฝ ๐Ÿ”— โฎ๏ธ `yield`
๐Ÿ–ผ, ๐Ÿ‘† ๐Ÿ’ช โš™๏ธ ๐Ÿ‘‰ โœ ๐Ÿ’ฝ ๐ŸŽ‰ &amp; ๐Ÿ” โšซ๏ธ โฎ๏ธ ๐Ÿ.
๐Ÿ•ด ๐Ÿ“Ÿ โญ &amp; ๐Ÿ”Œ `yield` ๐Ÿ“„ ๐Ÿ› ๏ธ โญ ๐Ÿ“จ ๐Ÿ“จ:
```Python hl_lines="2-4"
{!../../../docs_src/dependencies/tutorial007.py!}
```
๐ŸŒพ ๐Ÿ’ฒ โšซ๏ธโ” ๐Ÿ’‰ ๐Ÿ”˜ *โžก ๐Ÿ› ๏ธ* &amp; ๐ŸŽ ๐Ÿ”—:
```Python hl_lines="4"
{!../../../docs_src/dependencies/tutorial007.py!}
```
๐Ÿ“Ÿ ๐Ÿ“„ `yield` ๐Ÿ“„ ๐Ÿ› ๏ธ โฎ๏ธ ๐Ÿ“จ โœ”๏ธ ๐Ÿšš:
```Python hl_lines="5-6"
{!../../../docs_src/dependencies/tutorial007.py!}
```
!!! tip
๐Ÿ‘† ๐Ÿ’ช โš™๏ธ `async` โš–๏ธ ๐Ÿ˜ ๐Ÿ”ข.
**FastAPI** ๐Ÿ”œ โ–ถ๏ธ๏ธ ๐Ÿ‘œ โฎ๏ธ ๐Ÿ” , ๐ŸŽ โฎ๏ธ ๐Ÿ˜ ๐Ÿ”—.
## ๐Ÿ”— โฎ๏ธ `yield` &amp; `try`
๐Ÿšฅ ๐Ÿ‘† โš™๏ธ `try` ๐Ÿซ ๐Ÿ”— โฎ๏ธ `yield`, ๐Ÿ‘† ๐Ÿ”œ ๐Ÿ“จ ๐Ÿ™† โš  ๐Ÿ‘ˆ ๐Ÿšฎ ๐Ÿ•โ” โš™๏ธ ๐Ÿ”—.
๐Ÿ–ผ, ๐Ÿšฅ ๐Ÿ“Ÿ โ˜ ๐Ÿ–•, โž•1๏ธโƒฃ ๐Ÿ”— โš–๏ธ *โžก ๐Ÿ› ๏ธ*, โš’ ๐Ÿ’ฝ ๐Ÿ’ต "๐Ÿ’พ" โš–๏ธ โœ ๐Ÿ™† ๐ŸŽ โŒ, ๐Ÿ‘† ๐Ÿ”œ ๐Ÿ“จ โš  ๐Ÿ‘† ๐Ÿ”—.
, ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ‘€ ๐Ÿ‘ˆ ๐ŸŽฏ โš  ๐Ÿ”˜ ๐Ÿ”— โฎ๏ธ `except SomeException`.
๐ŸŽ ๐ŸŒŒ, ๐Ÿ‘† ๐Ÿ’ช โš™๏ธ `finally` โš’ ๐Ÿ’ญ ๐Ÿšช ๐Ÿ“ถ ๐Ÿ› ๏ธ, ๐Ÿ™…โ€โ™‚ ๐Ÿค” ๐Ÿšฅ ๐Ÿ“ค โš  โš–๏ธ ๐Ÿšซ.
```Python hl_lines="3 5"
{!../../../docs_src/dependencies/tutorial007.py!}
```
## ๐ŸŽง-๐Ÿ”— โฎ๏ธ `yield`
๐Ÿ‘† ๐Ÿ’ช โœ”๏ธ ๐ŸŽง-๐Ÿ”— &amp; "๐ŸŒฒ" ๐ŸŽง-๐Ÿ”— ๐Ÿ™† ๐Ÿ“ &amp; ๐Ÿ’ , &amp; ๐Ÿ™† โš–๏ธ ๐ŸŒ ๐Ÿ‘ซ ๐Ÿ’ช โš™๏ธ `yield`.
**FastAPI** ๐Ÿ”œ โš’ ๐Ÿ’ญ ๐Ÿ‘ˆ "๐Ÿšช ๐Ÿ“Ÿ" ๐Ÿ”  ๐Ÿ”— โฎ๏ธ `yield` ๐Ÿƒ โ˜‘ โœ”.
๐Ÿ–ผ, `dependency_c` ๐Ÿ’ช โœ”๏ธ ๐Ÿ”— ๐Ÿ”› `dependency_b`, &amp; `dependency_b` ๐Ÿ”› `dependency_a`:
```Python hl_lines="4 12 20"
{!../../../docs_src/dependencies/tutorial008.py!}
```
&amp; ๐ŸŒ ๐Ÿ‘ซ ๐Ÿ’ช โš™๏ธ `yield`.
๐Ÿ‘‰ ๐Ÿ’ผ `dependency_c`, ๐Ÿ› ๏ธ ๐Ÿšฎ ๐Ÿšช ๐Ÿ“Ÿ, ๐Ÿ’ช ๐Ÿ’ฒ โšช๏ธโžก๏ธ `dependency_b` (๐Ÿ“ฅ ๐Ÿ“› `dep_b`) ๐Ÿ’ช.
&amp; , ๐Ÿ”„, `dependency_b` ๐Ÿ’ช ๐Ÿ’ฒ โšช๏ธโžก๏ธ `dependency_a` (๐Ÿ“ฅ ๐Ÿ“› `dep_a`) ๐Ÿ’ช ๐Ÿšฎ ๐Ÿšช ๐Ÿ“Ÿ.
```Python hl_lines="16-17 24-25"
{!../../../docs_src/dependencies/tutorial008.py!}
```
๐ŸŽ ๐ŸŒŒ, ๐Ÿ‘† ๐Ÿ’ช โœ”๏ธ ๐Ÿ”— โฎ๏ธ `yield` &amp; `return` ๐ŸŒ€.
&amp; ๐Ÿ‘† ๐Ÿ’ช โœ”๏ธ ๐Ÿ‘ ๐Ÿ”— ๐Ÿ‘ˆ ๐Ÿšš ๐Ÿ“š ๐ŸŽ ๐Ÿ”— โฎ๏ธ `yield`, โ™’๏ธ.
๐Ÿ‘† ๐Ÿ’ช โœ”๏ธ ๐Ÿ™† ๐ŸŒ€ ๐Ÿ”— ๐Ÿ‘ˆ ๐Ÿ‘† ๐Ÿ’š.
**FastAPI** ๐Ÿ”œ โš’ ๐Ÿ’ญ ๐ŸŒ ๐Ÿƒ โ˜‘ โœ”.
!!! note "๐Ÿ“ก โ„น"
๐Ÿ‘‰ ๐Ÿ‘ท ๐Ÿ‘ ๐Ÿ <a href="https://docs.python.org/3/library/contextlib.html" class="external-link" target="_blank">๐Ÿ”‘ ๐Ÿ‘จโ€๐Ÿ’ผ</a>.
**FastAPI** โš™๏ธ ๐Ÿ‘ซ ๐Ÿ”˜ ๐Ÿ† ๐Ÿ‘‰.
## ๐Ÿ”— โฎ๏ธ `yield` &amp; `HTTPException`
๐Ÿ‘† ๐Ÿ‘€ ๐Ÿ‘ˆ ๐Ÿ‘† ๐Ÿ’ช โš™๏ธ ๐Ÿ”— โฎ๏ธ `yield` &amp; โœ”๏ธ `try` ๐Ÿซ ๐Ÿ‘ˆ โœŠ โš .
โšซ๏ธ 5๏ธโƒฃ๐Ÿ“† ๐Ÿ˜‹ ๐Ÿคš `HTTPException` โš–๏ธ ๐ŸŽ ๐Ÿšช ๐Ÿ“Ÿ, โฎ๏ธ `yield`. โœ‹๏ธ **โšซ๏ธ ๐Ÿ† ๐Ÿšซ ๐Ÿ‘ท**.
๐Ÿšช ๐Ÿ“Ÿ ๐Ÿ”— โฎ๏ธ `yield` ๐Ÿ› ๏ธ *โฎ๏ธ* ๐Ÿ“จ ๐Ÿ“จ, [โš  ๐Ÿ•โ€๐Ÿฆบ](../handling-errors.md#install-custom-exception-handlers){.internal-link target=_blank} ๐Ÿ”œ โœ”๏ธ โช ๐Ÿƒ. ๐Ÿ“ค ๐Ÿ•ณ ๐Ÿ˜ฝ โš  ๐Ÿšฎ ๐Ÿ‘† ๐Ÿ”— ๐Ÿšช ๐Ÿ“Ÿ (โฎ๏ธ `yield`).
, ๐Ÿšฅ ๐Ÿ‘† ๐Ÿคš `HTTPException` โฎ๏ธ `yield`, ๐Ÿ”ข (โš–๏ธ ๐Ÿ™† ๐Ÿ›ƒ) โš  ๐Ÿ•โ€๐Ÿฆบ ๐Ÿ‘ˆ โœŠ `HTTPException`โ“‚ &amp; ๐Ÿ“จ ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ” 4๏ธโƒฃ0๏ธโƒฃ0๏ธโƒฃ ๐Ÿ“จ ๐Ÿ† ๐Ÿšซ ๐Ÿ“ค โœŠ ๐Ÿ‘ˆ โš  ๐Ÿšซ๐Ÿ”œ.
๐Ÿ‘‰ โšซ๏ธโ” โœ” ๐Ÿ•ณ โš’ ๐Ÿ”— (โœ… ๐Ÿ’ฝ ๐ŸŽ‰), ๐Ÿ–ผ, โš™๏ธ ๐Ÿ–ฅ ๐Ÿ“‹.
๐Ÿ–ฅ ๐Ÿ“‹ ๐Ÿƒ *โฎ๏ธ* ๐Ÿ“จ โœ”๏ธ ๐Ÿ“จ. ๐Ÿ“ค ๐Ÿ™…โ€โ™‚ ๐ŸŒŒ ๐Ÿคš `HTTPException` โ†ฉ๏ธ ๐Ÿ“ค ๐Ÿšซ ๐ŸŒŒ ๐Ÿ”€ ๐Ÿ“จ ๐Ÿ‘ˆ *โช ๐Ÿ“จ*.
โœ‹๏ธ ๐Ÿšฅ ๐Ÿ–ฅ ๐Ÿ“‹ โœ ๐Ÿ’ฝ โŒ, ๐ŸŒ˜ ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ’พ โš–๏ธ ๐Ÿ˜ฌ ๐Ÿ” ๐ŸŽ‰ ๐Ÿ”— โฎ๏ธ `yield`, &amp; ๐ŸŽฒ ๐Ÿ•น โŒ โš–๏ธ ๐Ÿ“„ โšซ๏ธ ๐Ÿ›ฐ ๐Ÿ•ต โš™๏ธ.
๐Ÿšฅ ๐Ÿ‘† โœ”๏ธ ๐Ÿ“Ÿ ๐Ÿ‘ˆ ๐Ÿ‘† ๐Ÿ’ญ ๐Ÿ’ช ๐Ÿคš โš , ๐Ÿ† ๐Ÿ˜/"๐Ÿ™ƒ" ๐Ÿ‘œ &amp; ๐Ÿšฎ `try` ๐Ÿซ ๐Ÿ‘ˆ ๐Ÿ“„ ๐Ÿ“Ÿ.
๐Ÿšฅ ๐Ÿ‘† โœ”๏ธ ๐Ÿ›ƒ โš  ๐Ÿ‘ˆ ๐Ÿ‘† ๐Ÿ”œ ๐Ÿ’– ๐Ÿต *โญ* ๐Ÿ›ฌ ๐Ÿ“จ &amp; ๐ŸŽฒ โŽ ๐Ÿ“จ, ๐ŸŽฒ ๐Ÿ™‹โ€โ™€ `HTTPException`, โœ [๐Ÿ›ƒ โš  ๐Ÿ•โ€๐Ÿฆบ](../handling-errors.md#install-custom-exception-handlers){.internal-link target=_blank}.
!!! tip
๐Ÿ‘† ๐Ÿ’ช ๐Ÿคš โš  ๐Ÿ”Œ `HTTPException` *โญ* `yield`. โœ‹๏ธ ๐Ÿšซ โฎ๏ธ.
๐Ÿ” ๐Ÿ› ๏ธ ๐ŸŒ… โš–๏ธ ๐ŸŒ˜ ๐Ÿ’– ๐Ÿ‘‰ ๐Ÿ“Š. ๐Ÿ•ฐ ๐Ÿ’ง โšช๏ธโžก๏ธ ๐Ÿ” ๐Ÿ”. &amp; ๐Ÿ”  ๐Ÿ“ 1๏ธโƒฃ ๐Ÿ• ๐Ÿ”— โš–๏ธ ๐Ÿ› ๏ธ ๐Ÿ“Ÿ.
```mermaid
sequenceDiagram
participant client as Client
participant handler as Exception handler
participant dep as Dep with yield
participant operation as Path Operation
participant tasks as Background tasks
Note over client,tasks: Can raise exception for dependency, handled after response is sent
Note over client,operation: Can raise HTTPException and can change the response
client ->> dep: Start request
Note over dep: Run code up to yield
opt raise
dep -->> handler: Raise HTTPException
handler -->> client: HTTP error response
dep -->> dep: Raise other exception
end
dep ->> operation: Run dependency, e.g. DB session
opt raise
operation -->> dep: Raise HTTPException
dep -->> handler: Auto forward exception
handler -->> client: HTTP error response
operation -->> dep: Raise other exception
dep -->> handler: Auto forward exception
end
operation ->> client: Return response to client
Note over client,operation: Response is already sent, can't change it anymore
opt Tasks
operation -->> tasks: Send background tasks
end
opt Raise other exception
tasks -->> dep: Raise other exception
end
Note over dep: After yield
opt Handle other exception
dep -->> dep: Handle exception, can't change response. E.g. close DB session.
end
```
!!! info
๐Ÿ•ด **1๏ธโƒฃ ๐Ÿ“จ** ๐Ÿ”œ ๐Ÿ“จ ๐Ÿ‘ฉโ€๐Ÿ’ป. โšซ๏ธ ๐Ÿ’ช 1๏ธโƒฃ โŒ ๐Ÿ“จ โš–๏ธ โšซ๏ธ ๐Ÿ”œ ๐Ÿ“จ โšช๏ธโžก๏ธ *โžก ๐Ÿ› ๏ธ*.
โฎ๏ธ 1๏ธโƒฃ ๐Ÿ“š ๐Ÿ“จ ๐Ÿ“จ, ๐Ÿ™…โ€โ™‚ ๐ŸŽ ๐Ÿ“จ ๐Ÿ’ช ๐Ÿ“จ.
!!! tip
๐Ÿ‘‰ ๐Ÿ“Š ๐ŸŽฆ `HTTPException`, โœ‹๏ธ ๐Ÿ‘† ๐Ÿ’ช ๐Ÿคš ๐Ÿ™† ๐ŸŽ โš  โ” ๐Ÿ‘† โœ [๐Ÿ›ƒ โš  ๐Ÿ•โ€๐Ÿฆบ](../handling-errors.md#install-custom-exception-handlers){.internal-link target=_blank}.
๐Ÿšฅ ๐Ÿ‘† ๐Ÿคš ๐Ÿ™† โš , โšซ๏ธ ๐Ÿ”œ ๐Ÿšถโ€โ™€๏ธ ๐Ÿ”— โฎ๏ธ ๐ŸŒพ, ๐Ÿ”Œ `HTTPException`, &amp; โคด๏ธ **๐Ÿ”„** โš  ๐Ÿ•โ€๐Ÿฆบ. ๐Ÿšฅ ๐Ÿ“ค ๐Ÿ™…โ€โ™‚ โš  ๐Ÿ•โ€๐Ÿฆบ ๐Ÿ‘ˆ โš , โšซ๏ธ ๐Ÿ”œ โคด๏ธ ๐Ÿต ๐Ÿ”ข ๐Ÿ”— `ServerErrorMiddleware`, ๐Ÿ›ฌ 5๏ธโƒฃ0๏ธโƒฃ0๏ธโƒฃ ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ” ๐Ÿ‘” ๐Ÿ“Ÿ, โžก๏ธ ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ’ญ ๐Ÿ‘ˆ ๐Ÿ“ค โŒ ๐Ÿ’ฝ.
## ๐Ÿ”‘ ๐Ÿ‘จโ€๐Ÿ’ผ
### โšซ๏ธโ” "๐Ÿ”‘ ๐Ÿ‘จโ€๐Ÿ’ผ"
"๐Ÿ”‘ ๐Ÿ‘จโ€๐Ÿ’ผ" ๐Ÿ™† ๐Ÿ‘ˆ ๐Ÿ ๐ŸŽš ๐Ÿ‘ˆ ๐Ÿ‘† ๐Ÿ’ช โš™๏ธ `with` ๐Ÿ“„.
๐Ÿ–ผ, <a href="https://docs.python.org/3/tutorial/inputoutput.html#reading-and-writing-files" class="external-link" target="_blank">๐Ÿ‘† ๐Ÿ’ช โš™๏ธ `with` โœ ๐Ÿ“</a>:
```Python
with open("./somefile.txt") as f:
contents = f.read()
print(contents)
```
๐Ÿ”˜, `open("./somefile.txt")` โœ ๐ŸŽš ๐Ÿ‘ˆ ๐Ÿค™ "๐Ÿ”‘ ๐Ÿ‘จโ€๐Ÿ’ผ".
๐Ÿ•โ” `with` ๐Ÿซ ๐Ÿ, โšซ๏ธ โš’ ๐Ÿ’ญ ๐Ÿ” ๐Ÿ“, ๐Ÿšฅ ๐Ÿ“ค โš .
๐Ÿ•โ” ๐Ÿ‘† โœ ๐Ÿ”— โฎ๏ธ `yield`, **FastAPI** ๐Ÿ”œ ๐Ÿ”˜ ๐Ÿ—œ โšซ๏ธ ๐Ÿ”‘ ๐Ÿ‘จโ€๐Ÿ’ผ, &amp; ๐ŸŒ€ โšซ๏ธ โฎ๏ธ ๐ŸŽ ๐Ÿ”— ๐Ÿงฐ.
### โš™๏ธ ๐Ÿ”‘ ๐Ÿ‘จโ€๐Ÿ’ผ ๐Ÿ”— โฎ๏ธ `yield`
!!! warning
๐Ÿ‘‰, ๐ŸŒ… โš–๏ธ ๐ŸŒ˜, "๐Ÿง" ๐Ÿ’ญ.
๐Ÿšฅ ๐Ÿ‘† โ–ถ๏ธ โฎ๏ธ **FastAPI** ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ’š ๐Ÿšถ โšซ๏ธ ๐Ÿ”œ.
๐Ÿ, ๐Ÿ‘† ๐Ÿ’ช โœ ๐Ÿ”‘ ๐Ÿ‘จโ€๐Ÿ’ผ <a href="https://docs.python.org/3/reference/datamodel.html#context-managers" class="external-link" target="_blank">๐Ÿ— ๐ŸŽ“ โฎ๏ธ 2๏ธโƒฃ ๐Ÿ‘ฉโ€๐Ÿ”ฌ: `__enter__()` &amp; `__exit__()`</a>.
๐Ÿ‘† ๐Ÿ’ช โš™๏ธ ๐Ÿ‘ซ ๐Ÿ”˜ **FastAPI** ๐Ÿ”— โฎ๏ธ `yield` โš™๏ธ
`with` โš–๏ธ `async with` ๐Ÿ“„ ๐Ÿ”˜ ๐Ÿ”— ๐Ÿ”ข:
```Python hl_lines="1-9 13"
{!../../../docs_src/dependencies/tutorial010.py!}
```
!!! tip
โž•1๏ธโƒฃ ๐ŸŒŒ โœ ๐Ÿ”‘ ๐Ÿ‘จโ€๐Ÿ’ผ โฎ๏ธ:
* <a href="https://docs.python.org/3/library/contextlib.html#contextlib.contextmanager" class="external-link" target="_blank">`@contextlib.contextmanager`</a> โš–๏ธ
* <a href="https://docs.python.org/3/library/contextlib.html#contextlib.asynccontextmanager" class="external-link" target="_blank">`@contextlib.asynccontextmanager`</a>
โš™๏ธ ๐Ÿ‘ซ ๐ŸŽ€ ๐Ÿ”ข โฎ๏ธ ๐Ÿ‘ `yield`.
๐Ÿ‘ˆ โšซ๏ธโ” **FastAPI** โš™๏ธ ๐Ÿ”˜ ๐Ÿ”— โฎ๏ธ `yield`.
โœ‹๏ธ ๐Ÿ‘† ๐Ÿšซ โœ”๏ธ โš™๏ธ ๐Ÿ‘จโ€๐ŸŽจ FastAPI ๐Ÿ”— (&amp; ๐Ÿ‘† ๐Ÿšซ๐Ÿ”œ ๐Ÿšซ).
FastAPI ๐Ÿ”œ โšซ๏ธ ๐Ÿ‘† ๐Ÿ”˜.

17
docs/em/docs/tutorial/dependencies/global-dependencies.md

@ -0,0 +1,17 @@
# ๐ŸŒ ๐Ÿ”—
๐Ÿ†Ž ๐Ÿˆธ ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ’š ๐Ÿšฎ ๐Ÿ”— ๐ŸŽ‚ ๐Ÿˆธ.
๐ŸŽ ๐ŸŒŒ ๐Ÿ‘† ๐Ÿ’ช [๐Ÿšฎ `dependencies` *โžก ๐Ÿ› ๏ธ ๐Ÿ‘จโ€๐ŸŽจ*](dependencies-in-path-operation-decorators.md){.internal-link target=_blank}, ๐Ÿ‘† ๐Ÿ’ช ๐Ÿšฎ ๐Ÿ‘ซ `FastAPI` ๐Ÿˆธ.
๐Ÿ‘ˆ ๐Ÿ’ผ, ๐Ÿ‘ซ ๐Ÿ”œ โœ” ๐ŸŒ *โžก ๐Ÿ› ๏ธ* ๐Ÿˆธ:
```Python hl_lines="15"
{!../../../docs_src/dependencies/tutorial012.py!}
```
&amp; ๐ŸŒ ๐Ÿ’ญ ๐Ÿ“„ ๐Ÿ”ƒ [โŽ `dependencies` *โžก ๐Ÿ› ๏ธ ๐Ÿ‘จโ€๐ŸŽจ*](dependencies-in-path-operation-decorators.md){.internal-link target=_blank} โœ”, โœ‹๏ธ ๐Ÿ‘‰ ๐Ÿ’ผ, ๐ŸŒ *โžก ๐Ÿ› ๏ธ* ๐Ÿ“ฑ.
## ๐Ÿ”— ๐Ÿ‘ช *โžก ๐Ÿ› ๏ธ*
โช, ๐Ÿ•โ” ๐Ÿ‘‚ ๐Ÿ”ƒ โ” ๐Ÿ“Š ๐Ÿฆ ๐Ÿˆธ ([๐Ÿฆ ๐Ÿˆธ - ๐Ÿ’— ๐Ÿ“](../../tutorial/bigger-applications.md){.internal-link target=_blank}), ๐ŸŽฒ โฎ๏ธ ๐Ÿ’— ๐Ÿ“, ๐Ÿ‘† ๐Ÿ”œ ๐Ÿ’ก โ” ๐Ÿ“ฃ ๐Ÿ‘ `dependencies` ๐Ÿ”ข ๐Ÿ‘ช *โžก ๐Ÿ› ๏ธ*.

233
docs/em/docs/tutorial/dependencies/index.md

@ -0,0 +1,233 @@
# ๐Ÿ”— - ๐Ÿฅ‡ ๐Ÿ”
**FastAPI** โœ”๏ธ ๐Ÿ“ถ ๐Ÿ‹๏ธ โœ‹๏ธ ๐Ÿ‹๏ธ **<abbr title="also known as components, resources, providers, services, injectables">๐Ÿ”— ๐Ÿ’‰</abbr>** โš™๏ธ.
โšซ๏ธ ๐Ÿ— ๐Ÿ“ถ ๐Ÿ™… โš™๏ธ, &amp; โš’ โšซ๏ธ ๐Ÿ“ถ โฉ ๐Ÿ™† ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ› ๏ธ ๐ŸŽ ๐Ÿฆฒ โฎ๏ธ **FastAPI**.
## โšซ๏ธโ” "๐Ÿ”— ๐Ÿ’‰"
**"๐Ÿ”— ๐Ÿ’‰"** โ›“, ๐Ÿ“‹, ๐Ÿ‘ˆ ๐Ÿ“ค ๐ŸŒŒ ๐Ÿ‘† ๐Ÿ“Ÿ (๐Ÿ‘‰ ๐Ÿ’ผ, ๐Ÿ‘† *โžก ๐Ÿ› ๏ธ ๐Ÿ”ข*) ๐Ÿ“ฃ ๐Ÿ‘œ ๐Ÿ‘ˆ โšซ๏ธ ๐Ÿšš ๐Ÿ‘ท &amp; โš™๏ธ: "๐Ÿ”—".
&amp; โคด๏ธ, ๐Ÿ‘ˆ โš™๏ธ (๐Ÿ‘‰ ๐Ÿ’ผ **FastAPI**) ๐Ÿ”œ โœŠ ๐Ÿ’… ๐Ÿ”จ โšซ๏ธโ” ๐Ÿ’ช ๐Ÿšš ๐Ÿ‘† ๐Ÿ“Ÿ โฎ๏ธ ๐Ÿ“š ๐Ÿ’ช ๐Ÿ”— ("๐Ÿ’‰" ๐Ÿ”—).
๐Ÿ‘‰ ๐Ÿ“ถ โš  ๐Ÿ•โ” ๐Ÿ‘† ๐Ÿ’ช:
* โœ”๏ธ ๐Ÿ’ฐ โš› (๐ŸŽ ๐Ÿ“Ÿ โš› ๐Ÿ”„ &amp; ๐Ÿ”„).
* ๐Ÿ’ฐ ๐Ÿ’ฝ ๐Ÿ”—.
* ๐Ÿ› ๏ธ ๐Ÿ’‚โ€โ™‚, ๐Ÿค, ๐Ÿ”‘ ๐Ÿ“„, โ™’๏ธ.
* &amp; ๐Ÿ“š ๐ŸŽ ๐Ÿ‘œ...
๐ŸŒ ๐Ÿ‘ซ, โช ๐Ÿ“‰ ๐Ÿ“Ÿ ๐Ÿ”.
## ๐Ÿฅ‡ ๐Ÿ”
โžก๏ธ ๐Ÿ‘€ ๐Ÿ“ถ ๐Ÿ™… ๐Ÿ–ผ. โšซ๏ธ ๐Ÿ”œ ๐Ÿ™… ๐Ÿ‘ˆ โšซ๏ธ ๐Ÿšซ ๐Ÿ“ถ โš , ๐Ÿ”œ.
โœ‹๏ธ ๐Ÿ‘‰ ๐ŸŒŒ ๐Ÿ‘ฅ ๐Ÿ’ช ๐ŸŽฏ ๐Ÿ”› โ” **๐Ÿ”— ๐Ÿ’‰** โš™๏ธ ๐Ÿ‘ท.
### โœ ๐Ÿ”—, โš–๏ธ "โ˜‘"
โžก๏ธ ๐Ÿฅ‡ ๐ŸŽฏ ๐Ÿ”› ๐Ÿ”—.
โšซ๏ธ ๐Ÿ”ข ๐Ÿ‘ˆ ๐Ÿ’ช โœŠ ๐ŸŒ ๐ŸŽ ๐Ÿ”ข ๐Ÿ‘ˆ *โžก ๐Ÿ› ๏ธ ๐Ÿ”ข* ๐Ÿ’ช โœŠ:
=== "๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="8-11"
{!> ../../../docs_src/dependencies/tutorial001.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.1๏ธโƒฃ0๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="6-7"
{!> ../../../docs_src/dependencies/tutorial001_py310.py!}
```
๐Ÿ‘ˆ โšซ๏ธ.
**2๏ธโƒฃ โธ**.
&amp; โšซ๏ธ โœ”๏ธ ๐ŸŽ ๐Ÿ’  &amp; ๐Ÿ“Š ๐Ÿ‘ˆ ๐ŸŒ ๐Ÿ‘† *โžก ๐Ÿ› ๏ธ ๐Ÿ”ข* โœ”๏ธ.
๐Ÿ‘† ๐Ÿ’ช ๐Ÿ’ญ โšซ๏ธ *โžก ๐Ÿ› ๏ธ ๐Ÿ”ข* ๐Ÿต "๐Ÿ‘จโ€๐ŸŽจ" (๐Ÿต `@app.get("/some-path")`).
&amp; โšซ๏ธ ๐Ÿ’ช ๐Ÿ“จ ๐Ÿ•ณ ๐Ÿ‘† ๐Ÿ’š.
๐Ÿ‘‰ ๐Ÿ’ผ, ๐Ÿ‘‰ ๐Ÿ”— โŒ›:
* ๐Ÿ“ฆ ๐Ÿ”ข ๐Ÿ”ข `q` ๐Ÿ‘ˆ `str`.
* ๐Ÿ“ฆ ๐Ÿ”ข ๐Ÿ”ข `skip` ๐Ÿ‘ˆ `int`, &amp; ๐Ÿ”ข `0`.
* ๐Ÿ“ฆ ๐Ÿ”ข ๐Ÿ”ข `limit` ๐Ÿ‘ˆ `int`, &amp; ๐Ÿ”ข `100`.
&amp; โคด๏ธ โšซ๏ธ ๐Ÿ“จ `dict` โš— ๐Ÿ“š ๐Ÿ’ฒ.
### ๐Ÿ—„ `Depends`
=== "๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="3"
{!> ../../../docs_src/dependencies/tutorial001.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.1๏ธโƒฃ0๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="1"
{!> ../../../docs_src/dependencies/tutorial001_py310.py!}
```
### ๐Ÿ“ฃ ๐Ÿ”—, "โš“๏ธ"
๐ŸŽ ๐ŸŒŒ ๐Ÿ‘† โš™๏ธ `Body`, `Query`, โ™’๏ธ. โฎ๏ธ ๐Ÿ‘† *โžก ๐Ÿ› ๏ธ ๐Ÿ”ข* ๐Ÿ”ข, โš™๏ธ `Depends` โฎ๏ธ ๐Ÿ†• ๐Ÿ”ข:
=== "๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="15 20"
{!> ../../../docs_src/dependencies/tutorial001.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.1๏ธโƒฃ0๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="11 16"
{!> ../../../docs_src/dependencies/tutorial001_py310.py!}
```
๐Ÿ‘ ๐Ÿ‘† โš™๏ธ `Depends` ๐Ÿ”ข ๐Ÿ‘† ๐Ÿ”ข ๐ŸŽ ๐ŸŒŒ ๐Ÿ‘† โš™๏ธ `Body`, `Query`, โ™’๏ธ, `Depends` ๐Ÿ‘ท ๐Ÿ‘„ ๐ŸŽ.
๐Ÿ‘† ๐Ÿ•ด ๐Ÿค `Depends` ๐Ÿ‘ ๐Ÿ”ข.
๐Ÿ‘‰ ๐Ÿ”ข ๐Ÿ”œ ๐Ÿ•ณ ๐Ÿ’– ๐Ÿ”ข.
&amp; ๐Ÿ‘ˆ ๐Ÿ”ข โœŠ ๐Ÿ”ข ๐ŸŽ ๐ŸŒŒ ๐Ÿ‘ˆ *โžก ๐Ÿ› ๏ธ ๐Ÿ”ข* .
!!! tip
๐Ÿ‘† ๐Ÿ”œ ๐Ÿ‘€ โšซ๏ธโ” ๐ŸŽ "๐Ÿ‘œ", โ†–๏ธ โšช๏ธโžก๏ธ ๐Ÿ”ข, ๐Ÿ’ช โš™๏ธ ๐Ÿ”— โญ ๐Ÿ“ƒ.
๐Ÿ•โ” ๐Ÿ†• ๐Ÿ“จ ๐Ÿ›ฌ, **FastAPI** ๐Ÿ”œ โœŠ ๐Ÿ’…:
* ๐Ÿค™ ๐Ÿ‘† ๐Ÿ”— ("โ˜‘") ๐Ÿ”ข โฎ๏ธ โ˜‘ ๐Ÿ”ข.
* ๐Ÿคš ๐Ÿ โšช๏ธโžก๏ธ ๐Ÿ‘† ๐Ÿ”ข.
* ๐Ÿ› ๏ธ ๐Ÿ‘ˆ ๐Ÿ ๐Ÿ”ข ๐Ÿ‘† *โžก ๐Ÿ› ๏ธ ๐Ÿ”ข*.
```mermaid
graph TB
common_parameters(["common_parameters"])
read_items["/items/"]
read_users["/users/"]
common_parameters --> read_items
common_parameters --> read_users
```
๐Ÿ‘‰ ๐ŸŒŒ ๐Ÿ‘† โœ ๐Ÿ”— ๐Ÿ“Ÿ ๐Ÿ• &amp; **FastAPI** โœŠ ๐Ÿ’… ๐Ÿค™ โšซ๏ธ ๐Ÿ‘† *โžก ๐Ÿ› ๏ธ*.
!!! check
๐Ÿ‘€ ๐Ÿ‘ˆ ๐Ÿ‘† ๐Ÿšซ โœ”๏ธ โœ ๐ŸŽ ๐ŸŽ“ &amp; ๐Ÿšถโ€โ™€๏ธ โšซ๏ธ ๐Ÿ‘ฑ **FastAPI** "ยฎ" โšซ๏ธ โš–๏ธ ๐Ÿ•ณ ๐ŸŽ.
๐Ÿ‘† ๐Ÿšถโ€โ™€๏ธ โšซ๏ธ `Depends` &amp; **FastAPI** ๐Ÿ’ญ โ” ๐ŸŽ‚.
## `async` โš–๏ธ ๐Ÿšซ `async`
๐Ÿ”— ๐Ÿ”œ ๐Ÿค™ **FastAPI** (๐ŸŽ ๐Ÿ‘† *โžก ๐Ÿ› ๏ธ ๐Ÿ”ข*), ๐ŸŽ ๐Ÿšซ โœ” โช ๐Ÿ”ฌ ๐Ÿ‘† ๐Ÿ”ข.
๐Ÿ‘† ๐Ÿ’ช โš™๏ธ `async def` โš–๏ธ ๐Ÿ˜ `def`.
&amp; ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ“ฃ ๐Ÿ”— โฎ๏ธ `async def` ๐Ÿ”˜ ๐Ÿ˜ `def` *โžก ๐Ÿ› ๏ธ ๐Ÿ”ข*, โš–๏ธ `def` ๐Ÿ”— ๐Ÿ”˜ `async def` *โžก ๐Ÿ› ๏ธ ๐Ÿ”ข*, โ™’๏ธ.
โšซ๏ธ ๐Ÿšซ ๐Ÿค”. **FastAPI** ๐Ÿ”œ ๐Ÿ’ญ โšซ๏ธโ”.
!!! note
๐Ÿšฅ ๐Ÿ‘† ๐Ÿšซ ๐Ÿ’ญ, โœ… [๐Ÿ”: *"๐Ÿƒ โ“" *](../../async.md){.internal-link target=_blank} ๐Ÿ“„ ๐Ÿ”ƒ `async` &amp; `await` ๐Ÿฉบ.
## ๐Ÿ› ๏ธ โฎ๏ธ ๐Ÿ—„
๐ŸŒ ๐Ÿ“จ ๐Ÿ“„, ๐Ÿ”ฌ &amp; ๐Ÿ“„ ๐Ÿ‘† ๐Ÿ”— (&amp; ๐ŸŽง-๐Ÿ”—) ๐Ÿ”œ ๐Ÿ› ๏ธ ๐ŸŽ ๐Ÿ—„ ๐Ÿ”—.
, ๐ŸŽ“ ๐Ÿฉบ ๐Ÿ”œ โœ”๏ธ ๐ŸŒ โ„น โšช๏ธโžก๏ธ ๐Ÿ‘ซ ๐Ÿ”— ๐Ÿ’โ€โ™‚๏ธ:
<img src="/img/tutorial/dependencies/image01.png">
## ๐Ÿ™… โš™๏ธ
๐Ÿšฅ ๐Ÿ‘† ๐Ÿ‘€ โšซ๏ธ, *โžก ๐Ÿ› ๏ธ ๐Ÿ”ข* ๐Ÿ“ฃ โš™๏ธ ๐Ÿ•โ” *โžก* &amp; *๐Ÿ› ๏ธ* ๐Ÿ, &amp; โคด๏ธ **FastAPI** โœŠ ๐Ÿ’… ๐Ÿค™ ๐Ÿ”ข โฎ๏ธ โ˜‘ ๐Ÿ”ข, โŽ ๐Ÿ“Š โšช๏ธโžก๏ธ ๐Ÿ“จ.
๐Ÿค™, ๐ŸŒ (โš–๏ธ ๐Ÿ†) ๐Ÿ•ธ ๐Ÿ› ๏ธ ๐Ÿ‘ท ๐Ÿ‘‰ ๐ŸŽ ๐ŸŒŒ.
๐Ÿ‘† ๐Ÿ™… ๐Ÿค™ ๐Ÿ‘ˆ ๐Ÿ”ข ๐Ÿ”—. ๐Ÿ‘ซ ๐Ÿค™ ๐Ÿ‘† ๐Ÿ› ๏ธ (๐Ÿ‘‰ ๐Ÿ’ผ, **FastAPI**).
โฎ๏ธ ๐Ÿ”— ๐Ÿ’‰ โš™๏ธ, ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ’ฌ **FastAPI** ๐Ÿ‘ˆ ๐Ÿ‘† *โžก ๐Ÿ› ๏ธ ๐Ÿ”ข* "๐Ÿช€" ๐Ÿ”› ๐Ÿ•ณ ๐Ÿ™† ๐Ÿ‘ˆ ๐Ÿ”œ ๐Ÿ› ๏ธ โญ ๐Ÿ‘† *โžก ๐Ÿ› ๏ธ ๐Ÿ”ข*, &amp; **FastAPI** ๐Ÿ”œ โœŠ ๐Ÿ’… ๐Ÿ› ๏ธ โšซ๏ธ &amp; "๐Ÿ’‰" ๐Ÿ.
๐ŸŽ โš  โš– ๐Ÿ‘‰ ๐ŸŽ ๐Ÿ’ญ "๐Ÿ”— ๐Ÿ’‰":
* โ„น
* ๐Ÿ•โ€๐Ÿฆบ
* ๐Ÿ•โ€๐Ÿฆบ
* ๐Ÿ’‰
* ๐Ÿฆฒ
## **FastAPI** ๐Ÿ”Œ-๐Ÿ”Œ
๐Ÿ› ๏ธ &amp; "๐Ÿ”Œ-"โ“‚ ๐Ÿ’ช ๐Ÿ— โš™๏ธ **๐Ÿ”— ๐Ÿ’‰** โš™๏ธ. โœ‹๏ธ ๐Ÿ‘, ๐Ÿ“ค ๐Ÿค™ **๐Ÿ™…โ€โ™‚ ๐Ÿ’ช โœ "๐Ÿ”Œ-๐Ÿ”Œ"**, โš™๏ธ ๐Ÿ”— โšซ๏ธ ๐Ÿ’ช ๐Ÿ“ฃ โ™พ ๐Ÿ”ข ๐Ÿ› ๏ธ &amp; ๐Ÿ”— ๐Ÿ‘ˆ โ–ถ๏ธ๏ธ ๐Ÿ’ช ๐Ÿ‘† *โžก ๐Ÿ› ๏ธ ๐Ÿ”ข*.
&amp; ๐Ÿ”— ๐Ÿ’ช โœ ๐Ÿ“ถ ๐Ÿ™… &amp; ๐Ÿ‹๏ธ ๐ŸŒŒ ๐Ÿ‘ˆ โœ” ๐Ÿ‘† ๐Ÿ—„ ๐Ÿ ๐Ÿ“ฆ ๐Ÿ‘† ๐Ÿ’ช, &amp; ๐Ÿ› ๏ธ ๐Ÿ‘ซ โฎ๏ธ ๐Ÿ‘† ๐Ÿ› ๏ธ ๐Ÿ”ข ๐Ÿ‘ฉโ€โคโ€๐Ÿ‘จ โธ ๐Ÿ“Ÿ, *๐ŸŒ–*.
๐Ÿ‘† ๐Ÿ”œ ๐Ÿ‘€ ๐Ÿ–ผ ๐Ÿ‘‰ โญ ๐Ÿ“ƒ, ๐Ÿ”ƒ ๐Ÿ”— &amp; โ˜ ๐Ÿ’ฝ, ๐Ÿ’‚โ€โ™‚, โ™’๏ธ.
## **FastAPI** ๐Ÿ”—
๐Ÿฆ ๐Ÿ”— ๐Ÿ’‰ โš™๏ธ โš’ **FastAPI** ๐Ÿ”— โฎ๏ธ:
* ๐ŸŒ ๐Ÿ”— ๐Ÿ’ฝ
* โ˜ ๐Ÿ’ฝ
* ๐Ÿ”ข ๐Ÿ“ฆ
* ๐Ÿ”ข ๐Ÿ”—
* ๐Ÿค &amp; โœ” โš™๏ธ
* ๐Ÿ› ๏ธ โš™๏ธ โš– โš™๏ธ
* ๐Ÿ“จ ๐Ÿ’ฝ ๐Ÿ’‰ โš™๏ธ
* โ™’๏ธ.
## ๐Ÿ™… &amp; ๐Ÿ‹๏ธ
๐Ÿ‘ ๐Ÿ”— ๐Ÿ”— ๐Ÿ’‰ โš™๏ธ ๐Ÿ“ถ ๐Ÿ™… ๐Ÿ”ฌ &amp; โš™๏ธ, โšซ๏ธ ๐Ÿ“ถ ๐Ÿ‹๏ธ.
๐Ÿ‘† ๐Ÿ’ช ๐Ÿ”ฌ ๐Ÿ”— ๐Ÿ‘ˆ ๐Ÿ”„ ๐Ÿ’ช ๐Ÿ”ฌ ๐Ÿ”— ๐Ÿ‘ซ.
๐Ÿ”š, ๐Ÿ”— ๐ŸŒฒ ๐Ÿ”— ๐Ÿ—, &amp; **๐Ÿ”— ๐Ÿ’‰** โš™๏ธ โœŠ ๐Ÿ’… ๐Ÿ”ฌ ๐ŸŒ ๐Ÿ‘‰ ๐Ÿ”— ๐Ÿ‘† (&amp; ๐Ÿ‘ซ ๐ŸŽง-๐Ÿ”—) &amp; ๐Ÿšš (๐Ÿ’‰) ๐Ÿ ๐Ÿ”  ๐Ÿ”.
๐Ÿ–ผ, โžก๏ธ ๐Ÿ’ฌ ๐Ÿ‘† โœ”๏ธ 4๏ธโƒฃ ๐Ÿ› ๏ธ ๐Ÿ”— (*โžก ๐Ÿ› ๏ธ*):
* `/items/public/`
* `/items/private/`
* `/users/{user_id}/activate`
* `/items/pro/`
โคด๏ธ ๐Ÿ‘† ๐Ÿ’ช ๐Ÿšฎ ๐ŸŽ โœ” ๐Ÿ“„ ๐Ÿ”  ๐Ÿ‘ซ โฎ๏ธ ๐Ÿ”— &amp; ๐ŸŽง-๐Ÿ”—:
```mermaid
graph TB
current_user(["current_user"])
active_user(["active_user"])
admin_user(["admin_user"])
paying_user(["paying_user"])
public["/items/public/"]
private["/items/private/"]
activate_user["/users/{user_id}/activate"]
pro_items["/items/pro/"]
current_user --> active_user
active_user --> admin_user
active_user --> paying_user
current_user --> public
active_user --> private
admin_user --> activate_user
paying_user --> pro_items
```
## ๐Ÿ› ๏ธ โฎ๏ธ **๐Ÿ—„**
๐ŸŒ ๐Ÿ‘ซ ๐Ÿ”—, โช ๐Ÿ“ฃ ๐Ÿ‘ซ ๐Ÿ“„, ๐Ÿšฎ ๐Ÿ”ข, ๐Ÿ”ฌ, โ™’๏ธ. ๐Ÿ‘† *โžก ๐Ÿ› ๏ธ*.
**FastAPI** ๐Ÿ”œ โœŠ ๐Ÿ’… ๐Ÿšฎ โšซ๏ธ ๐ŸŒ ๐Ÿ—„ ๐Ÿ”—, ๐Ÿ‘ˆ โšซ๏ธ ๐ŸŽฆ ๐ŸŽ“ ๐Ÿงพ โš™๏ธ.

110
docs/em/docs/tutorial/dependencies/sub-dependencies.md

@ -0,0 +1,110 @@
# ๐ŸŽง-๐Ÿ”—
๐Ÿ‘† ๐Ÿ’ช โœ ๐Ÿ”— ๐Ÿ‘ˆ โœ”๏ธ **๐ŸŽง-๐Ÿ”—**.
๐Ÿ‘ซ ๐Ÿ’ช **โฌ** ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ‘ซ.
**FastAPI** ๐Ÿ”œ โœŠ ๐Ÿ’… ๐Ÿ”ฌ ๐Ÿ‘ซ.
## ๐Ÿฅ‡ ๐Ÿ”— "โ˜‘"
๐Ÿ‘† ๐Ÿ’ช โœ ๐Ÿฅ‡ ๐Ÿ”— ("โ˜‘") ๐Ÿ’–:
=== "๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="8-9"
{!> ../../../docs_src/dependencies/tutorial005.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.1๏ธโƒฃ0๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="6-7"
{!> ../../../docs_src/dependencies/tutorial005_py310.py!}
```
โšซ๏ธ ๐Ÿ“ฃ ๐Ÿ“ฆ ๐Ÿ”ข ๐Ÿ”ข `q` `str`, &amp; โคด๏ธ โšซ๏ธ ๐Ÿ“จ โšซ๏ธ.
๐Ÿ‘‰ ๐Ÿ™… (๐Ÿšซ ๐Ÿ“ถ โš ), โœ‹๏ธ ๐Ÿ”œ โ„น ๐Ÿ‘ฅ ๐ŸŽฏ ๐Ÿ”› โ” ๐ŸŽง-๐Ÿ”— ๐Ÿ‘ท.
## ๐Ÿฅˆ ๐Ÿ”—, "โ˜‘" &amp; "โš“๏ธ"
โคด๏ธ ๐Ÿ‘† ๐Ÿ’ช โœ โž•1๏ธโƒฃ ๐Ÿ”— ๐Ÿ”ข ("โ˜‘") ๐Ÿ‘ˆ ๐ŸŽ ๐Ÿ•ฐ ๐Ÿ“ฃ ๐Ÿ”— ๐Ÿšฎ ๐Ÿ‘ (โšซ๏ธ "โš“๏ธ" ๐Ÿ’โ€โ™‚๏ธ):
=== "๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="13"
{!> ../../../docs_src/dependencies/tutorial005.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.1๏ธโƒฃ0๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="11"
{!> ../../../docs_src/dependencies/tutorial005_py310.py!}
```
โžก๏ธ ๐ŸŽฏ ๐Ÿ”› ๐Ÿ”ข ๐Ÿ“ฃ:
* โœ‹๏ธ ๐Ÿ‘‰ ๐Ÿ”ข ๐Ÿ”— ("โ˜‘") โšซ๏ธ, โšซ๏ธ ๐Ÿ“ฃ โž•1๏ธโƒฃ ๐Ÿ”— (โšซ๏ธ "๐Ÿช€" ๐Ÿ”› ๐Ÿ•ณ ๐Ÿ™†).
* โšซ๏ธ ๐Ÿช€ ๐Ÿ”› `query_extractor`, &amp; ๐Ÿ› ๏ธ ๐Ÿ’ฒ ๐Ÿ“จ โšซ๏ธ ๐Ÿ”ข `q`.
* โšซ๏ธ ๐Ÿ“ฃ ๐Ÿ“ฆ `last_query` ๐Ÿช, `str`.
* ๐Ÿšฅ ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿšซ ๐Ÿšš ๐Ÿ™† ๐Ÿ”ข `q`, ๐Ÿ‘ฅ โš™๏ธ ๐Ÿ ๐Ÿ”ข โš™๏ธ, โ” ๐Ÿ‘ฅ ๐Ÿ–Š ๐Ÿช โญ.
## โš™๏ธ ๐Ÿ”—
โคด๏ธ ๐Ÿ‘ฅ ๐Ÿ’ช โš™๏ธ ๐Ÿ”— โฎ๏ธ:
=== "๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="22"
{!> ../../../docs_src/dependencies/tutorial005.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.1๏ธโƒฃ0๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="19"
{!> ../../../docs_src/dependencies/tutorial005_py310.py!}
```
!!! info
๐Ÿ‘€ ๐Ÿ‘ˆ ๐Ÿ‘ฅ ๐Ÿ•ด ๐Ÿ“ฃ 1๏ธโƒฃ ๐Ÿ”— *โžก ๐Ÿ› ๏ธ ๐Ÿ”ข*, `query_or_cookie_extractor`.
โœ‹๏ธ **FastAPI** ๐Ÿ”œ ๐Ÿ’ญ ๐Ÿ‘ˆ โšซ๏ธ โœ”๏ธ โŽ `query_extractor` ๐Ÿฅ‡, ๐Ÿšถโ€โ™€๏ธ ๐Ÿ ๐Ÿ‘ˆ `query_or_cookie_extractor` โช ๐Ÿค™ โšซ๏ธ.
```mermaid
graph TB
query_extractor(["query_extractor"])
query_or_cookie_extractor(["query_or_cookie_extractor"])
read_query["/items/"]
query_extractor --> query_or_cookie_extractor --> read_query
```
## โš™๏ธ ๐ŸŽ ๐Ÿ”— ๐Ÿ’— ๐Ÿ•ฐ
๐Ÿšฅ 1๏ธโƒฃ ๐Ÿ‘† ๐Ÿ”— ๐Ÿ“ฃ ๐Ÿ’— ๐Ÿ•ฐ ๐ŸŽ *โžก ๐Ÿ› ๏ธ*, ๐Ÿ–ผ, ๐Ÿ’— ๐Ÿ”— โœ”๏ธ โš  ๐ŸŽง-๐Ÿ”—, **FastAPI** ๐Ÿ”œ ๐Ÿ’ญ ๐Ÿค™ ๐Ÿ‘ˆ ๐ŸŽง-๐Ÿ”— ๐Ÿ•ด ๐Ÿ• ๐Ÿ“ ๐Ÿ“จ.
&amp; โšซ๏ธ ๐Ÿ”œ ๐Ÿ–Š ๐Ÿ“จ ๐Ÿ’ฒ <abbr title="A utility/system to store computed/generated values, to re-use them instead of computing them again.">"๐Ÿ’พ"</abbr> &amp; ๐Ÿšถโ€โ™€๏ธ โšซ๏ธ ๐ŸŒ "โš“๏ธ" ๐Ÿ‘ˆ ๐Ÿ’ช โšซ๏ธ ๐Ÿ‘ˆ ๐ŸŽฏ ๐Ÿ“จ, โ†ฉ๏ธ ๐Ÿค™ ๐Ÿ”— ๐Ÿ’— ๐Ÿ•ฐ ๐ŸŽ ๐Ÿ“จ.
๐Ÿง ๐Ÿ˜ ๐ŸŒโ” ๐Ÿ‘† ๐Ÿ’ญ ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ”— ๐Ÿค™ ๐Ÿ”  ๐Ÿ” (๐ŸŽฒ ๐Ÿ’— ๐Ÿ•ฐ) ๐ŸŽ ๐Ÿ“จ โ†ฉ๏ธ โš™๏ธ "๐Ÿ’พ" ๐Ÿ’ฒ, ๐Ÿ‘† ๐Ÿ’ช โš’ ๐Ÿ”ข `use_cache=False` ๐Ÿ•โ” โš™๏ธ `Depends`:
```Python hl_lines="1"
async def needy_dependency(fresh_value: str = Depends(get_value, use_cache=False)):
return {"fresh_value": fresh_value}
```
## ๐ŸŒƒ
โ†–๏ธ โšช๏ธโžก๏ธ ๐ŸŒ ๐ŸŽ€ ๐Ÿ”ค โš™๏ธ ๐Ÿ“ฅ, **๐Ÿ”— ๐Ÿ’‰** โš™๏ธ ๐Ÿ™….
๐Ÿ”ข ๐Ÿ‘ˆ ๐Ÿ‘€ ๐ŸŽ *โžก ๐Ÿ› ๏ธ ๐Ÿ”ข*.
โœ‹๏ธ, โšซ๏ธ ๐Ÿ“ถ ๐Ÿ‹๏ธ, &amp; โœ” ๐Ÿ‘† ๐Ÿ“ฃ ๐ŸŽฒ ๐Ÿ™‡ ๐Ÿฆ ๐Ÿ”— "๐Ÿ“Š" (๐ŸŒฒ).
!!! tip
๐ŸŒ ๐Ÿ‘‰ ๐Ÿ’ช ๐Ÿšซ ๐Ÿ˜‘ โš  โฎ๏ธ ๐Ÿ‘ซ ๐Ÿ™… ๐Ÿ–ผ.
โœ‹๏ธ ๐Ÿ‘† ๐Ÿ”œ ๐Ÿ‘€ โ” โš  โšซ๏ธ ๐Ÿ“ƒ ๐Ÿ”ƒ **๐Ÿ’‚โ€โ™‚**.
&amp; ๐Ÿ‘† ๐Ÿ”œ ๐Ÿ‘€ ๐Ÿ’ธ ๐Ÿ“Ÿ โšซ๏ธ ๐Ÿ”œ ๐Ÿ–Š ๐Ÿ‘†.

42
docs/em/docs/tutorial/encoder.md

@ -0,0 +1,42 @@
# ๐ŸŽป ๐Ÿ”— ๐Ÿ”ข
๐Ÿ“ค ๐Ÿ’ผ ๐ŸŒโ” ๐Ÿ‘† 5๏ธโƒฃ๐Ÿ“† ๐Ÿ’ช ๐Ÿ—œ ๐Ÿ’ฝ ๐Ÿ†Ž (๐Ÿ’– Pydantic ๐Ÿท) ๐Ÿ•ณ ๐Ÿ”— โฎ๏ธ ๐ŸŽป (๐Ÿ’– `dict`, `list`, โ™’๏ธ).
๐Ÿ–ผ, ๐Ÿšฅ ๐Ÿ‘† ๐Ÿ’ช ๐Ÿช โšซ๏ธ ๐Ÿ’ฝ.
๐Ÿ‘ˆ, **FastAPI** ๐Ÿšš `jsonable_encoder()` ๐Ÿ”ข.
## โš™๏ธ `jsonable_encoder`
โžก๏ธ ๐ŸŒˆ ๐Ÿ‘ˆ ๐Ÿ‘† โœ”๏ธ ๐Ÿ’ฝ `fake_db` ๐Ÿ‘ˆ ๐Ÿ•ด ๐Ÿ“จ ๐ŸŽป ๐Ÿ”— ๐Ÿ’ฝ.
๐Ÿ–ผ, โšซ๏ธ ๐Ÿšซ ๐Ÿ“จ `datetime` ๐ŸŽš, ๐Ÿ‘ˆ ๐Ÿšซ ๐Ÿ”— โฎ๏ธ ๐ŸŽป.
, `datetime` ๐ŸŽš ๐Ÿ”œ โœ”๏ธ ๐Ÿ—œ `str` โš— ๐Ÿ’ฝ <a href="https://en.wikipedia.org/wiki/ISO_8601" class="external-link" target="_blank">๐Ÿ’พ ๐Ÿ“</a>.
๐ŸŽ ๐ŸŒŒ, ๐Ÿ‘‰ ๐Ÿ’ฝ ๐Ÿšซ๐Ÿ”œ ๐Ÿ“จ Pydantic ๐Ÿท (๐ŸŽš โฎ๏ธ ๐Ÿ”ข), ๐Ÿ•ด `dict`.
๐Ÿ‘† ๐Ÿ’ช โš™๏ธ `jsonable_encoder` ๐Ÿ‘ˆ.
โšซ๏ธ ๐Ÿ“จ ๐ŸŽš, ๐Ÿ’– Pydantic ๐Ÿท, &amp; ๐Ÿ“จ ๐ŸŽป ๐Ÿ”— โฌ:
=== "๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="5 22"
{!> ../../../docs_src/encoder/tutorial001.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.1๏ธโƒฃ0๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="4 21"
{!> ../../../docs_src/encoder/tutorial001_py310.py!}
```
๐Ÿ‘‰ ๐Ÿ–ผ, โšซ๏ธ ๐Ÿ”œ ๐Ÿ—œ Pydantic ๐Ÿท `dict`, &amp; `datetime` `str`.
๐Ÿ ๐Ÿค™ โšซ๏ธ ๐Ÿ•ณ ๐Ÿ‘ˆ ๐Ÿ’ช ๐Ÿ—œ โฎ๏ธ ๐Ÿ ๐Ÿฉ <a href="https://docs.python.org/3/library/json.html#json.dumps" class="external-link" target="_blank">`json.dumps()`</a>.
โšซ๏ธ ๐Ÿšซ ๐Ÿ“จ โญ• `str` โš— ๐Ÿ’ฝ ๐ŸŽป ๐Ÿ“ (๐ŸŽป). โšซ๏ธ ๐Ÿ“จ ๐Ÿ ๐Ÿฉ ๐Ÿ’ฝ ๐Ÿ“Š (โœ… `dict`) โฎ๏ธ ๐Ÿ’ฒ &amp; ๐ŸŽง-๐Ÿ’ฒ ๐Ÿ‘ˆ ๐ŸŒ ๐Ÿ”— โฎ๏ธ ๐ŸŽป.
!!! note
`jsonable_encoder` ๐Ÿค™ โš™๏ธ **FastAPI** ๐Ÿ”˜ ๐Ÿ—œ ๐Ÿ’ฝ. โœ‹๏ธ โšซ๏ธ โš  ๐Ÿ“š ๐ŸŽ ๐Ÿ˜.

82
docs/em/docs/tutorial/extra-data-types.md

@ -0,0 +1,82 @@
# โž• ๐Ÿ’ฝ ๐Ÿ†Ž
๐Ÿ†™ ๐Ÿ”œ, ๐Ÿ‘† โœ”๏ธ โš™๏ธ โš  ๐Ÿ“Š ๐Ÿ†Ž, ๐Ÿ’–:
* `int`
* `float`
* `str`
* `bool`
โœ‹๏ธ ๐Ÿ‘† ๐Ÿ’ช โš™๏ธ ๐ŸŒ… ๐Ÿ— ๐Ÿ“Š ๐Ÿ†Ž.
&amp; ๐Ÿ‘† ๐Ÿ”œ โœ”๏ธ ๐ŸŽ โš’ ๐Ÿ‘€ ๐Ÿ†™ ๐Ÿ”œ:
* ๐Ÿ‘‘ ๐Ÿ‘จโ€๐ŸŽจ ๐Ÿ•โ€๐Ÿฆบ.
* ๐Ÿ’ฝ ๐Ÿ› ๏ธ โšช๏ธโžก๏ธ ๐Ÿ“จ ๐Ÿ“จ.
* ๐Ÿ’ฝ ๐Ÿ› ๏ธ ๐Ÿ“จ ๐Ÿ’ฝ.
* ๐Ÿ’ฝ ๐Ÿ”ฌ.
* ๐Ÿง โœ &amp; ๐Ÿงพ.
## ๐ŸŽ ๐Ÿ’ฝ ๐Ÿ†Ž
๐Ÿ“ฅ ๐ŸŒ– ๐Ÿ“Š ๐Ÿ†Ž ๐Ÿ‘† ๐Ÿ’ช โš™๏ธ:
* `UUID`:
* ๐Ÿฉ "โญ ๐Ÿ˜ ๐Ÿ†”", โš  ๐Ÿ†” ๐Ÿ“š ๐Ÿ’ฝ &amp; โš™๏ธ.
* ๐Ÿ“จ &amp; ๐Ÿ“จ ๐Ÿ”œ ๐ŸŽจ `str`.
* `datetime.datetime`:
* ๐Ÿ `datetime.datetime`.
* ๐Ÿ“จ &amp; ๐Ÿ“จ ๐Ÿ”œ ๐ŸŽจ `str` ๐Ÿ’พ 8๏ธโƒฃ6๏ธโƒฃ0๏ธโƒฃ1๏ธโƒฃ ๐Ÿ“, ๐Ÿ’–: `2008-09-15T15:53:00+05:00`.
* `datetime.date`:
* ๐Ÿ `datetime.date`.
* ๐Ÿ“จ &amp; ๐Ÿ“จ ๐Ÿ”œ ๐ŸŽจ `str` ๐Ÿ’พ 8๏ธโƒฃ6๏ธโƒฃ0๏ธโƒฃ1๏ธโƒฃ ๐Ÿ“, ๐Ÿ’–: `2008-09-15`.
* `datetime.time`:
* ๐Ÿ `datetime.time`.
* ๐Ÿ“จ &amp; ๐Ÿ“จ ๐Ÿ”œ ๐ŸŽจ `str` ๐Ÿ’พ 8๏ธโƒฃ6๏ธโƒฃ0๏ธโƒฃ1๏ธโƒฃ ๐Ÿ“, ๐Ÿ’–: `14:23:55.003`.
* `datetime.timedelta`:
* ๐Ÿ `datetime.timedelta`.
* ๐Ÿ“จ &amp; ๐Ÿ“จ ๐Ÿ”œ ๐ŸŽจ `float` ๐ŸŒ ๐Ÿฅˆ.
* Pydantic โœ” ๐ŸŽฆ โšซ๏ธ "๐Ÿ’พ 8๏ธโƒฃ6๏ธโƒฃ0๏ธโƒฃ1๏ธโƒฃ ๐Ÿ•ฐ โž• ๐Ÿ”ข", <a href="https://pydantic-docs.helpmanual.io/usage/exporting_models/#json_encoders" class="external-link" target="_blank">๐Ÿ‘€ ๐Ÿฉบ ๐ŸŒ… โ„น</a>.
* `frozenset`:
* ๐Ÿ“จ &amp; ๐Ÿ“จ, ๐Ÿ˜ฅ ๐ŸŽ `set`:
* ๐Ÿ“จ, ๐Ÿ“‡ ๐Ÿ”œ โœ, โŽ โŽ &amp; ๐Ÿญ โšซ๏ธ `set`.
* ๐Ÿ“จ, `set` ๐Ÿ”œ ๐Ÿ—œ `list`.
* ๐Ÿ— ๐Ÿ”— ๐Ÿ”œ โœ” ๐Ÿ‘ˆ `set` ๐Ÿ’ฒ ๐Ÿ˜ (โš™๏ธ ๐ŸŽป ๐Ÿ”— `uniqueItems`).
* `bytes`:
* ๐Ÿฉ ๐Ÿ `bytes`.
* ๐Ÿ“จ &amp; ๐Ÿ“จ ๐Ÿ”œ ๐Ÿ˜ฅ `str`.
* ๐Ÿ— ๐Ÿ”— ๐Ÿ”œ โœ” ๐Ÿ‘ˆ โšซ๏ธ `str` โฎ๏ธ `binary` "๐Ÿ“".
* `Decimal`:
* ๐Ÿฉ ๐Ÿ `Decimal`.
* ๐Ÿ“จ &amp; ๐Ÿ“จ, ๐Ÿต ๐ŸŽ `float`.
* ๐Ÿ‘† ๐Ÿ’ช โœ… ๐ŸŒ โ˜‘ Pydantic ๐Ÿ“Š ๐Ÿ†Ž ๐Ÿ“ฅ: <a href="https://pydantic-docs.helpmanual.io/usage/types" class="external-link" target="_blank">Pydantic ๐Ÿ“Š ๐Ÿ†Ž</a>.
## ๐Ÿ–ผ
๐Ÿ“ฅ ๐Ÿ–ผ *โžก ๐Ÿ› ๏ธ* โฎ๏ธ ๐Ÿ”ข โš™๏ธ ๐Ÿ”› ๐Ÿ†Ž.
=== "๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="1 3 12-16"
{!> ../../../docs_src/extra_data_types/tutorial001.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.1๏ธโƒฃ0๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="1 2 11-15"
{!> ../../../docs_src/extra_data_types/tutorial001_py310.py!}
```
๐Ÿ—’ ๐Ÿ‘ˆ ๐Ÿ”ข ๐Ÿ”˜ ๐Ÿ”ข โœ”๏ธ ๐Ÿ‘ซ ๐Ÿ  ๐Ÿ’ฝ ๐Ÿ†Ž, &amp; ๐Ÿ‘† ๐Ÿ’ช, ๐Ÿ–ผ, ๐ŸŽญ ๐Ÿ˜ ๐Ÿ“… ๐ŸŽญ, ๐Ÿ’–:
=== "๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="18-19"
{!> ../../../docs_src/extra_data_types/tutorial001.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.1๏ธโƒฃ0๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="17-18"
{!> ../../../docs_src/extra_data_types/tutorial001_py310.py!}
```

252
docs/em/docs/tutorial/extra-models.md

@ -0,0 +1,252 @@
# โž• ๐Ÿท
โ–ถ๏ธ โฎ๏ธ โฎ๏ธ ๐Ÿ–ผ, โšซ๏ธ ๐Ÿ”œ โš  โœ”๏ธ ๐ŸŒ… ๐ŸŒ˜ 1๏ธโƒฃ ๐Ÿ”— ๐Ÿท.
๐Ÿ‘‰ โœด๏ธ ๐Ÿ’ผ ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿท, โ†ฉ๏ธ:
* **๐Ÿ”ข ๐Ÿท** ๐Ÿ’ช ๐Ÿ’ช โœ”๏ธ ๐Ÿ”.
* **๐Ÿ”ข ๐Ÿท** ๐Ÿ”œ ๐Ÿšซ โœ”๏ธ ๐Ÿ”.
* **๐Ÿ’ฝ ๐Ÿท** ๐Ÿ”œ ๐ŸŽฒ ๐Ÿ’ช โœ”๏ธ #๏ธโƒฃ ๐Ÿ”.
!!! danger
๐Ÿ™… ๐Ÿช ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ”ข ๐Ÿ”. ๐Ÿ•ง ๐Ÿช "๐Ÿ” #๏ธโƒฃ" ๐Ÿ‘ˆ ๐Ÿ‘† ๐Ÿ’ช โคด๏ธ โœ”.
๐Ÿšฅ ๐Ÿ‘† ๐Ÿšซ ๐Ÿ’ญ, ๐Ÿ‘† ๐Ÿ”œ ๐Ÿ’ก โšซ๏ธโ” "๐Ÿ”#๏ธโƒฃ" [๐Ÿ’‚โ€โ™‚ ๐Ÿ“ƒ](security/simple-oauth2.md#password-hashing){.internal-link target=_blank}.
## ๐Ÿ’— ๐Ÿท
๐Ÿ“ฅ ๐Ÿข ๐Ÿ’ญ โ” ๐Ÿท ๐Ÿ’ช ๐Ÿ‘€ ๐Ÿ’– โฎ๏ธ ๐Ÿ‘ซ ๐Ÿ” ๐Ÿ‘ &amp; ๐Ÿฅ‰ ๐ŸŒโ” ๐Ÿ‘ซ โš™๏ธ:
=== "๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="9 11 16 22 24 29-30 33-35 40-41"
{!> ../../../docs_src/extra_models/tutorial001.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.1๏ธโƒฃ0๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="7 9 14 20 22 27-28 31-33 38-39"
{!> ../../../docs_src/extra_models/tutorial001_py310.py!}
```
### ๐Ÿ”ƒ `**user_in.dict()`
#### Pydantic `.dict()`
`user_in` Pydantic ๐Ÿท ๐ŸŽ“ `UserIn`.
Pydantic ๐Ÿท โœ”๏ธ `.dict()` ๐Ÿ‘ฉโ€๐Ÿ”ฌ ๐Ÿ‘ˆ ๐Ÿ“จ `dict` โฎ๏ธ ๐Ÿท ๐Ÿ’ฝ.
, ๐Ÿšฅ ๐Ÿ‘ฅ โœ Pydantic ๐ŸŽš `user_in` ๐Ÿ’–:
```Python
user_in = UserIn(username="john", password="secret", email="[email protected]")
```
&amp; โคด๏ธ ๐Ÿ‘ฅ ๐Ÿค™:
```Python
user_dict = user_in.dict()
```
๐Ÿ‘ฅ ๐Ÿ”œ โœ”๏ธ `dict` โฎ๏ธ ๐Ÿ’ฝ ๐Ÿ”ข `user_dict` (โšซ๏ธ `dict` โ†ฉ๏ธ Pydantic ๐Ÿท ๐ŸŽš).
&amp; ๐Ÿšฅ ๐Ÿ‘ฅ ๐Ÿค™:
```Python
print(user_dict)
```
๐Ÿ‘ฅ ๐Ÿ”œ ๐Ÿคš ๐Ÿ `dict` โฎ๏ธ:
```Python
{
'username': 'john',
'password': 'secret',
'email': '[email protected]',
'full_name': None,
}
```
#### ๐ŸŽ `dict`
๐Ÿšฅ ๐Ÿ‘ฅ โœŠ `dict` ๐Ÿ’– `user_dict` &amp; ๐Ÿšถโ€โ™€๏ธ โšซ๏ธ ๐Ÿ”ข (โš–๏ธ ๐ŸŽ“) โฎ๏ธ `**user_dict`, ๐Ÿ ๐Ÿ”œ "๐ŸŽ" โšซ๏ธ. โšซ๏ธ ๐Ÿ”œ ๐Ÿšถโ€โ™€๏ธ ๐Ÿ”‘ &amp; ๐Ÿ’ฒ `user_dict` ๐Ÿ”— ๐Ÿ”‘-๐Ÿ’ฒ โŒ.
, โ–ถ๏ธ โฎ๏ธ `user_dict` โšช๏ธโžก๏ธ ๐Ÿ”›, โœ:
```Python
UserInDB(**user_dict)
```
๐Ÿ”œ ๐Ÿ ๐Ÿ•ณ ๐ŸŒ“:
```Python
UserInDB(
username="john",
password="secret",
email="[email protected]",
full_name=None,
)
```
โš–๏ธ ๐ŸŒ… โšซ๏ธโ”, โš™๏ธ `user_dict` ๐Ÿ”—, โฎ๏ธ โšซ๏ธโ” ๐ŸŽš โšซ๏ธ ๐Ÿ’ช โœ”๏ธ ๐Ÿ”ฎ:
```Python
UserInDB(
username = user_dict["username"],
password = user_dict["password"],
email = user_dict["email"],
full_name = user_dict["full_name"],
)
```
#### Pydantic ๐Ÿท โšช๏ธโžก๏ธ ๐ŸŽš โž•1๏ธโƒฃ
๐Ÿ–ผ ๐Ÿ”› ๐Ÿ‘ฅ ๐Ÿคš `user_dict` โšช๏ธโžก๏ธ `user_in.dict()`, ๐Ÿ‘‰ ๐Ÿ“Ÿ:
```Python
user_dict = user_in.dict()
UserInDB(**user_dict)
```
๐Ÿ”œ ๐ŸŒ“:
```Python
UserInDB(**user_in.dict())
```
...โ†ฉ๏ธ `user_in.dict()` `dict`, &amp; โคด๏ธ ๐Ÿ‘ฅ โš’ ๐Ÿ "๐ŸŽ" โšซ๏ธ ๐Ÿšถโ€โ™€๏ธ โšซ๏ธ `UserInDB` ๐Ÿ”  โฎ๏ธ `**`.
, ๐Ÿ‘ฅ ๐Ÿคš Pydantic ๐Ÿท โšช๏ธโžก๏ธ ๐Ÿ’ฝ โž•1๏ธโƒฃ Pydantic ๐Ÿท.
#### ๐ŸŽ `dict` &amp; โž• ๐Ÿ‡จ๐Ÿ‡ป
&amp; โคด๏ธ โŽ โž• ๐Ÿ‡จ๐Ÿ‡ป โŒ `hashed_password=hashed_password`, ๐Ÿ’–:
```Python
UserInDB(**user_in.dict(), hashed_password=hashed_password)
```
...๐Ÿ”š ๐Ÿ†™ ๐Ÿ’†โ€โ™‚ ๐Ÿ’–:
```Python
UserInDB(
username = user_dict["username"],
password = user_dict["password"],
email = user_dict["email"],
full_name = user_dict["full_name"],
hashed_password = hashed_password,
)
```
!!! warning
๐Ÿ”— ๐ŸŒ– ๐Ÿ”ข ๐Ÿค– ๐Ÿ’ช ๐Ÿ’ง ๐Ÿ’ฝ, โœ‹๏ธ ๐Ÿ‘ซ โ†—๏ธ ๐Ÿšซ ๐Ÿšš ๐Ÿ™† ๐ŸŽฐ ๐Ÿ’‚โ€โ™‚.
## ๐Ÿ“‰ โŽ
๐Ÿ“‰ ๐Ÿ“Ÿ โŽ 1๏ธโƒฃ ๐Ÿš ๐Ÿ’ญ **FastAPI**.
๐Ÿ“Ÿ โŽ ๐Ÿ“ˆ ๐Ÿคž ๐Ÿ›, ๐Ÿ’‚โ€โ™‚ โ”, ๐Ÿ“Ÿ ๐Ÿ” โ” (๐Ÿ•โ” ๐Ÿ‘† โ„น 1๏ธโƒฃ ๐Ÿฅ‰ โœ‹๏ธ ๐Ÿšซ ๐ŸŽ), โ™’๏ธ.
&amp; ๐Ÿ‘‰ ๐Ÿท ๐ŸŒ ๐Ÿค ๐Ÿ“š ๐Ÿ’ฝ &amp; โŽ ๐Ÿ”ข ๐Ÿ“› &amp; ๐Ÿ†Ž.
๐Ÿ‘ฅ ๐Ÿ’ช ๐Ÿ‘ป.
๐Ÿ‘ฅ ๐Ÿ’ช ๐Ÿ“ฃ `UserBase` ๐Ÿท ๐Ÿ‘ˆ ๐Ÿฆ ๐Ÿงข ๐Ÿ‘† ๐ŸŽ ๐Ÿท. &amp; โคด๏ธ ๐Ÿ‘ฅ ๐Ÿ’ช โš’ ๐Ÿฟ ๐Ÿ‘ˆ ๐Ÿท ๐Ÿ‘ˆ ๐Ÿ˜– ๐Ÿšฎ ๐Ÿ”ข (๐Ÿ†Ž ๐Ÿ“„, ๐Ÿ”ฌ, โ™’๏ธ).
๐ŸŒ ๐Ÿ’ฝ ๐Ÿ› ๏ธ, ๐Ÿ”ฌ, ๐Ÿงพ, โ™’๏ธ. ๐Ÿ”œ ๐Ÿ‘ท ๐Ÿ›Ž.
๐Ÿ‘ˆ ๐ŸŒŒ, ๐Ÿ‘ฅ ๐Ÿ’ช ๐Ÿ“ฃ ๐Ÿ”บ ๐Ÿ–– ๐Ÿท (โฎ๏ธ ๐Ÿ”ข `password`, โฎ๏ธ `hashed_password` &amp; ๐Ÿต ๐Ÿ”):
=== "๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="9 15-16 19-20 23-24"
{!> ../../../docs_src/extra_models/tutorial002.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.1๏ธโƒฃ0๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="7 13-14 17-18 21-22"
{!> ../../../docs_src/extra_models/tutorial002_py310.py!}
```
## `Union` โš–๏ธ `anyOf`
๐Ÿ‘† ๐Ÿ’ช ๐Ÿ“ฃ ๐Ÿ“จ `Union` 2๏ธโƒฃ ๐Ÿ†Ž, ๐Ÿ‘ˆ โ›“, ๐Ÿ‘ˆ ๐Ÿ“จ ๐Ÿ”œ ๐Ÿ™† 2๏ธโƒฃ.
โšซ๏ธ ๐Ÿ”œ ๐Ÿ”ฌ ๐Ÿ—„ โฎ๏ธ `anyOf`.
๐Ÿ‘ˆ, โš™๏ธ ๐Ÿฉ ๐Ÿ ๐Ÿ†Ž ๐Ÿ”‘ <a href="https://docs.python.org/3/library/typing.html#typing.Union" class="external-link" target="_blank">`typing.Union`</a>:
!!! note
๐Ÿ•โ” โš– <a href="https://pydantic-docs.helpmanual.io/usage/types/#unions" class="external-link" target="_blank">`Union`</a>, ๐Ÿ”Œ ๐Ÿ† ๐ŸŽฏ ๐Ÿ†Ž ๐Ÿฅ‡, โฉ ๐ŸŒ˜ ๐ŸŽฏ ๐Ÿ†Ž. ๐Ÿ–ผ ๐Ÿ”›, ๐ŸŒ– ๐ŸŽฏ `PlaneItem` ๐Ÿ‘Ÿ โญ `CarItem` `Union[PlaneItem, CarItem]`.
=== "๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="1 14-15 18-20 33"
{!> ../../../docs_src/extra_models/tutorial003.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.1๏ธโƒฃ0๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="1 14-15 18-20 33"
{!> ../../../docs_src/extra_models/tutorial003_py310.py!}
```
### `Union` ๐Ÿ 3๏ธโƒฃ.1๏ธโƒฃ0๏ธโƒฃ
๐Ÿ‘‰ ๐Ÿ–ผ ๐Ÿ‘ฅ ๐Ÿšถโ€โ™€๏ธ `Union[PlaneItem, CarItem]` ๐Ÿ’ฒ โŒ `response_model`.
โ†ฉ๏ธ ๐Ÿ‘ฅ ๐Ÿšถโ€โ™€๏ธ โšซ๏ธ **๐Ÿ’ฒ โŒ** โ†ฉ๏ธ ๐Ÿšฎ โšซ๏ธ **๐Ÿ†Ž โœ**, ๐Ÿ‘ฅ โœ”๏ธ โš™๏ธ `Union` ๐Ÿ 3๏ธโƒฃ.1๏ธโƒฃ0๏ธโƒฃ.
๐Ÿšฅ โšซ๏ธ ๐Ÿ†Ž โœ ๐Ÿ‘ฅ ๐Ÿ’ช โœ”๏ธ โš™๏ธ โธ โธ,:
```Python
some_variable: PlaneItem | CarItem
```
โœ‹๏ธ ๐Ÿšฅ ๐Ÿ‘ฅ ๐Ÿšฎ ๐Ÿ‘ˆ `response_model=PlaneItem | CarItem` ๐Ÿ‘ฅ ๐Ÿ”œ ๐Ÿคš โŒ, โ†ฉ๏ธ ๐Ÿ ๐Ÿ”œ ๐Ÿ”„ ๐ŸŽญ **โŒ ๐Ÿ› ๏ธ** ๐Ÿ–– `PlaneItem` &amp; `CarItem` โ†ฉ๏ธ ๐Ÿ”ฌ ๐Ÿ‘ˆ ๐Ÿ†Ž โœ.
## ๐Ÿ“‡ ๐Ÿท
๐ŸŽ ๐ŸŒŒ, ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ“ฃ ๐Ÿ“จ ๐Ÿ“‡ ๐ŸŽš.
๐Ÿ‘ˆ, โš™๏ธ ๐Ÿฉ ๐Ÿ `typing.List` (โš–๏ธ `list` ๐Ÿ 3๏ธโƒฃ.9๏ธโƒฃ &amp; ๐Ÿ”›):
=== "๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="1 20"
{!> ../../../docs_src/extra_models/tutorial004.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.9๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="18"
{!> ../../../docs_src/extra_models/tutorial004_py39.py!}
```
## ๐Ÿ“จ โฎ๏ธ โŒ `dict`
๐Ÿ‘† ๐Ÿ’ช ๐Ÿ“ฃ ๐Ÿ“จ โš™๏ธ โœ… โŒ `dict`, ๐Ÿ“ฃ ๐Ÿ†Ž ๐Ÿ”‘ &amp; ๐Ÿ’ฒ, ๐Ÿต โš™๏ธ Pydantic ๐Ÿท.
๐Ÿ‘‰ โš  ๐Ÿšฅ ๐Ÿ‘† ๐Ÿšซ ๐Ÿ’ญ โ˜‘ ๐Ÿ‘/๐Ÿ”ข ๐Ÿ“› (๐Ÿ‘ˆ ๐Ÿ”œ ๐Ÿ’ช Pydantic ๐Ÿท) โช.
๐Ÿ‘‰ ๐Ÿ’ผ, ๐Ÿ‘† ๐Ÿ’ช โš™๏ธ `typing.Dict` (โš–๏ธ `dict` ๐Ÿ 3๏ธโƒฃ.9๏ธโƒฃ &amp; ๐Ÿ”›):
=== "๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="1 8"
{!> ../../../docs_src/extra_models/tutorial005.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.9๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="6"
{!> ../../../docs_src/extra_models/tutorial005_py39.py!}
```
## ๐ŸŒƒ
โš™๏ธ ๐Ÿ’— Pydantic ๐Ÿท &amp; ๐Ÿ˜– โžก ๐Ÿ”  ๐Ÿ’ผ.
๐Ÿ‘† ๐Ÿšซ ๐Ÿ’ช โœ”๏ธ ๐Ÿ‘ ๐Ÿ’ฝ ๐Ÿท ๐Ÿ“ ๐Ÿ‘จโ€๐Ÿ’ผ ๐Ÿšฅ ๐Ÿ‘ˆ ๐Ÿ‘จโ€๐Ÿ’ผ ๐Ÿ”œ ๐Ÿ’ช โœ”๏ธ ๐ŸŽ "๐Ÿ‡ต๐Ÿ‡ธ". ๐Ÿ’ผ โฎ๏ธ ๐Ÿ‘ฉโ€๐Ÿ’ป "๐Ÿ‘จโ€๐Ÿ’ผ" โฎ๏ธ ๐Ÿ‡ต๐Ÿ‡ธ โœ… `password`, `password_hash` &amp; ๐Ÿ™…โ€โ™‚ ๐Ÿ”.

333
docs/em/docs/tutorial/first-steps.md

@ -0,0 +1,333 @@
# ๐Ÿฅ‡ ๐Ÿ”
๐Ÿ™… FastAPI ๐Ÿ“ ๐Ÿ’ช ๐Ÿ‘€ ๐Ÿ’– ๐Ÿ‘‰:
```Python
{!../../../docs_src/first_steps/tutorial001.py!}
```
๐Ÿ“ ๐Ÿ‘ˆ ๐Ÿ“ `main.py`.
๐Ÿƒ ๐Ÿ–– ๐Ÿ’ฝ:
<div class="termy">
```console
$ uvicorn main:app --reload
<span style="color: green;">INFO</span>: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
<span style="color: green;">INFO</span>: Started reloader process [28720]
<span style="color: green;">INFO</span>: Started server process [28722]
<span style="color: green;">INFO</span>: Waiting for application startup.
<span style="color: green;">INFO</span>: Application startup complete.
```
</div>
!!! note
๐Ÿ“‹ `uvicorn main:app` ๐Ÿ”—:
* `main`: ๐Ÿ“ `main.py` (๐Ÿ "๐Ÿ•น").
* `app`: ๐ŸŽš โœ ๐Ÿ”˜ `main.py` โฎ๏ธ โธ `app = FastAPI()`.
* `--reload`: โš’ ๐Ÿ’ฝ โ โฎ๏ธ ๐Ÿ“Ÿ ๐Ÿ”€. ๐Ÿ•ด โš™๏ธ ๐Ÿ› ๏ธ.
๐Ÿ”ข, ๐Ÿ“ค โธ โฎ๏ธ ๐Ÿ•ณ ๐Ÿ’–:
```hl_lines="4"
INFO: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
```
๐Ÿ‘ˆ โธ ๐ŸŽฆ ๐Ÿ“› ๐ŸŒโ” ๐Ÿ‘† ๐Ÿ“ฑ โž– ๐Ÿฆ, ๐Ÿ‘† ๐Ÿ‡ง๐Ÿ‡ฟ ๐ŸŽฐ.
### โœ… โšซ๏ธ
๐Ÿ“‚ ๐Ÿ‘† ๐Ÿ–ฅ <a href="http://127.0.0.1:8000" class="external-link" target="_blank">http://127.0.0.1:8000</a>.
๐Ÿ‘† ๐Ÿ”œ ๐Ÿ‘€ ๐ŸŽป ๐Ÿ“จ:
```JSON
{"message": "Hello World"}
```
### ๐ŸŽ“ ๐Ÿ› ๏ธ ๐Ÿฉบ
๐Ÿ”œ ๐Ÿšถ <a href="http://127.0.0.1:8000/docs" class="external-link" target="_blank">http://127.0.0.1:8000/docs</a>.
๐Ÿ‘† ๐Ÿ”œ ๐Ÿ‘€ ๐Ÿง ๐ŸŽ“ ๐Ÿ› ๏ธ ๐Ÿงพ (๐Ÿšš <a href="https://github.com/swagger-api/swagger-ui" class="external-link" target="_blank">๐Ÿฆ ๐ŸŽš</a>):
![Swagger UI](https://fastapi.tiangolo.com/img/index/index-01-swagger-ui-simple.png)
### ๐ŸŽ› ๐Ÿ› ๏ธ ๐Ÿฉบ
&amp; ๐Ÿ”œ, ๐Ÿšถ <a href="http://127.0.0.1:8000/redoc" class="external-link" target="_blank">http://127.0.0.1:8000/redoc</a>.
๐Ÿ‘† ๐Ÿ”œ ๐Ÿ‘€ ๐ŸŽ› ๐Ÿง ๐Ÿงพ (๐Ÿšš <a href="https://github.com/Rebilly/ReDoc" class="external-link" target="_blank">๐Ÿ“„</a>):
![ReDoc](https://fastapi.tiangolo.com/img/index/index-02-redoc-simple.png)
### ๐Ÿ—„
**FastAPI** ๐Ÿ— "๐Ÿ”—" โฎ๏ธ ๐ŸŒ ๐Ÿ‘† ๐Ÿ› ๏ธ โš™๏ธ **๐Ÿ—„** ๐Ÿฉ โš– ๐Ÿ”—.
#### "๐Ÿ”—"
"๐Ÿ”—" ๐Ÿ”‘ โš–๏ธ ๐Ÿ“› ๐Ÿ•ณ. ๐Ÿšซ ๐Ÿ“Ÿ ๐Ÿ‘ˆ ๐Ÿ› ๏ธ โšซ๏ธ, โœ‹๏ธ ๐Ÿ“ ๐Ÿ“›.
#### ๐Ÿ› ๏ธ "๐Ÿ”—"
๐Ÿ‘‰ ๐Ÿ’ผ, <a href="https://github.com/OAI/OpenAPI-Specification" class="external-link" target="_blank">๐Ÿ—„</a> ๐Ÿ”ง ๐Ÿ‘ˆ ๐Ÿค” โ” ๐Ÿ”ฌ ๐Ÿ”— ๐Ÿ‘† ๐Ÿ› ๏ธ.
๐Ÿ‘‰ ๐Ÿ”— ๐Ÿ”‘ ๐Ÿ”Œ ๐Ÿ‘† ๐Ÿ› ๏ธ โžก, ๐Ÿ’ช ๐Ÿ”ข ๐Ÿ‘ซ โœŠ, โ™’๏ธ.
#### ๐Ÿ’ฝ "๐Ÿ”—"
โš– "๐Ÿ”—" ๐Ÿ’ช ๐Ÿ”— ๐Ÿ’  ๐Ÿ’ฝ, ๐Ÿ’– ๐ŸŽป ๐ŸŽš.
๐Ÿ‘ˆ ๐Ÿ’ผ, โšซ๏ธ ๐Ÿ”œ โ›“ ๐ŸŽป ๐Ÿ”ข, &amp; ๐Ÿ“Š ๐Ÿ†Ž ๐Ÿ‘ซ โœ”๏ธ, โ™’๏ธ.
#### ๐Ÿ—„ &amp; ๐ŸŽป ๐Ÿ”—
๐Ÿ—„ ๐Ÿ”ฌ ๐Ÿ› ๏ธ ๐Ÿ”— ๐Ÿ‘† ๐Ÿ› ๏ธ. &amp; ๐Ÿ‘ˆ ๐Ÿ”— ๐Ÿ”Œ ๐Ÿ”‘ (โš–๏ธ "๐Ÿ”—") ๐Ÿ“Š ๐Ÿ“จ &amp; ๐Ÿ“จ ๐Ÿ‘† ๐Ÿ› ๏ธ โš™๏ธ **๐ŸŽป ๐Ÿ”—**, ๐Ÿฉ ๐ŸŽป ๐Ÿ“Š ๐Ÿ”—.
#### โœ… `openapi.json`
๐Ÿšฅ ๐Ÿ‘† ๐Ÿ˜Ÿ ๐Ÿ”ƒ โ” ๐Ÿฃ ๐Ÿ—„ ๐Ÿ”— ๐Ÿ‘€ ๐Ÿ’–, FastAPI ๐Ÿ” ๐Ÿ— ๐ŸŽป (๐Ÿ”—) โฎ๏ธ ๐Ÿ“› ๐ŸŒ ๐Ÿ‘† ๐Ÿ› ๏ธ.
๐Ÿ‘† ๐Ÿ’ช ๐Ÿ‘€ โšซ๏ธ ๐Ÿ”—: <a href="http://127.0.0.1:8000/openapi.json" class="external-link" target="_blank">http://127.0.0.1:8000/openapi.json</a>.
โšซ๏ธ ๐Ÿ”œ ๐ŸŽฆ ๐ŸŽป โ–ถ๏ธ โฎ๏ธ ๐Ÿ•ณ ๐Ÿ’–:
```JSON
{
"openapi": "3.0.2",
"info": {
"title": "FastAPI",
"version": "0.1.0"
},
"paths": {
"/items/": {
"get": {
"responses": {
"200": {
"description": "Successful Response",
"content": {
"application/json": {
...
```
#### โšซ๏ธโ” ๐Ÿ—„
๐Ÿ—„ ๐Ÿ”— โšซ๏ธโ” ๐Ÿ‹๏ธ 2๏ธโƒฃ ๐ŸŽ“ ๐Ÿงพ โš™๏ธ ๐Ÿ”Œ.
&amp; ๐Ÿ“ค ๐Ÿ’ฏ ๐ŸŽ›, ๐ŸŒ โš“๏ธ ๐Ÿ”› ๐Ÿ—„. ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ’ช ๐Ÿšฎ ๐Ÿ™† ๐Ÿ“š ๐ŸŽ› ๐Ÿ‘† ๐Ÿˆธ ๐Ÿ— โฎ๏ธ **FastAPI**.
๐Ÿ‘† ๐Ÿ’ช โš™๏ธ โšซ๏ธ ๐Ÿ— ๐Ÿ“Ÿ ๐Ÿ”, ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ‘ˆ ๐Ÿ”— โฎ๏ธ ๐Ÿ‘† ๐Ÿ› ๏ธ. ๐Ÿ–ผ, ๐Ÿ•ธ, ๐Ÿ“ฑ โš–๏ธ โ˜ ๐Ÿˆธ.
## ๐ŸŒƒ, ๐Ÿ” ๐Ÿ”
### ๐Ÿ” 1๏ธโƒฃ: ๐Ÿ—„ `FastAPI`
```Python hl_lines="1"
{!../../../docs_src/first_steps/tutorial001.py!}
```
`FastAPI` ๐Ÿ ๐ŸŽ“ ๐Ÿ‘ˆ ๐Ÿšš ๐ŸŒ ๐Ÿ› ๏ธ ๐Ÿ‘† ๐Ÿ› ๏ธ.
!!! note "๐Ÿ“ก โ„น"
`FastAPI` ๐ŸŽ“ ๐Ÿ‘ˆ ๐Ÿ˜– ๐Ÿ”— โšช๏ธโžก๏ธ `Starlette`.
๐Ÿ‘† ๐Ÿ’ช โš™๏ธ ๐ŸŒ <a href="https://www.starlette.io/" class="external-link" target="_blank">๐Ÿ’ƒ</a> ๐Ÿ› ๏ธ โฎ๏ธ `FastAPI` ๐Ÿ’โ€โ™‚๏ธ.
### ๐Ÿ” 2๏ธโƒฃ: โœ `FastAPI` "๐Ÿ‘"
```Python hl_lines="3"
{!../../../docs_src/first_steps/tutorial001.py!}
```
๐Ÿ“ฅ `app` ๐Ÿ”ข ๐Ÿ”œ "๐Ÿ‘" ๐ŸŽ“ `FastAPI`.
๐Ÿ‘‰ ๐Ÿ”œ ๐Ÿ‘‘ โ˜ ๐Ÿ”— โœ ๐ŸŒ ๐Ÿ‘† ๐Ÿ› ๏ธ.
๐Ÿ‘‰ `app` ๐ŸŽ 1๏ธโƒฃ ๐Ÿ”— `uvicorn` ๐Ÿ“‹:
<div class="termy">
```console
$ uvicorn main:app --reload
<span style="color: green;">INFO</span>: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
```
</div>
๐Ÿšฅ ๐Ÿ‘† โœ ๐Ÿ‘† ๐Ÿ“ฑ ๐Ÿ’–:
```Python hl_lines="3"
{!../../../docs_src/first_steps/tutorial002.py!}
```
&amp; ๐Ÿšฎ โšซ๏ธ ๐Ÿ“ `main.py`, โคด๏ธ ๐Ÿ‘† ๐Ÿ”œ ๐Ÿค™ `uvicorn` ๐Ÿ’–:
<div class="termy">
```console
$ uvicorn main:my_awesome_api --reload
<span style="color: green;">INFO</span>: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
```
</div>
### ๐Ÿ” 3๏ธโƒฃ: โœ *โžก ๐Ÿ› ๏ธ*
#### โžก
"โžก" ๐Ÿ“ฅ ๐Ÿ”— ๐Ÿ ๐Ÿ• ๐Ÿ“› โ–ถ๏ธ โšช๏ธโžก๏ธ ๐Ÿฅ‡ `/`.
, ๐Ÿ“› ๐Ÿ’–:
```
https://example.com/items/foo
```
...โžก ๐Ÿ”œ:
```
/items/foo
```
!!! info
"โžก" ๐Ÿ›Ž ๐Ÿค™ "๐Ÿ”—" โš–๏ธ "๐Ÿ›ฃ".
โช ๐Ÿ— ๐Ÿ› ๏ธ, "โžก" ๐Ÿ‘‘ ๐ŸŒŒ ๐ŸŽ "โš " &amp; "โ„น".
#### ๐Ÿ› ๏ธ
"๐Ÿ› ๏ธ" ๐Ÿ“ฅ ๐Ÿ”— 1๏ธโƒฃ ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ” "๐Ÿ‘ฉโ€๐Ÿ”ฌ".
1๏ธโƒฃ:
* `POST`
* `GET`
* `PUT`
* `DELETE`
...&amp; ๐ŸŒ… ๐Ÿ˜ ๐Ÿ•:
* `OPTIONS`
* `HEAD`
* `PATCH`
* `TRACE`
๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ” ๐Ÿ› ๏ธ, ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ”— ๐Ÿ”  โžก โš™๏ธ 1๏ธโƒฃ (โš–๏ธ ๐ŸŒ…) ๐Ÿ‘ซ "๐Ÿ‘ฉโ€๐Ÿ”ฌ".
---
๐Ÿ•โ” ๐Ÿ— ๐Ÿ”—, ๐Ÿ‘† ๐Ÿ›Ž โš™๏ธ ๐Ÿ‘ซ ๐ŸŽฏ ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ” ๐Ÿ‘ฉโ€๐Ÿ”ฌ ๐ŸŽญ ๐ŸŽฏ ๐ŸŽฏ.
๐Ÿ›Ž ๐Ÿ‘† โš™๏ธ:
* `POST`: โœ ๐Ÿ’ฝ.
* `GET`: โœ ๐Ÿ’ฝ.
* `PUT`: โ„น ๐Ÿ’ฝ.
* `DELETE`: โŽ ๐Ÿ’ฝ.
, ๐Ÿ—„, ๐Ÿ”  ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ” ๐Ÿ‘ฉโ€๐Ÿ”ฌ ๐Ÿค™ "๐Ÿ› ๏ธ".
๐Ÿ‘ฅ ๐Ÿ”œ ๐Ÿค™ ๐Ÿ‘ซ "**๐Ÿ› ๏ธ**" ๐Ÿ’โ€โ™‚๏ธ.
#### ๐Ÿ”ฌ *โžก ๐Ÿ› ๏ธ ๐Ÿ‘จโ€๐ŸŽจ*
```Python hl_lines="6"
{!../../../docs_src/first_steps/tutorial001.py!}
```
`@app.get("/")` ๐Ÿ’ฌ **FastAPI** ๐Ÿ‘ˆ ๐Ÿ”ข โ–ถ๏ธ๏ธ ๐Ÿ”› ๐Ÿˆš ๐Ÿšš ๐Ÿ“จ ๐Ÿ‘ˆ ๐Ÿšถ:
* โžก `/`
* โš™๏ธ <abbr title="an HTTP GET method"><code>get</code> ๐Ÿ› ๏ธ</abbr>
!!! info "`@decorator` โ„น"
๐Ÿ‘ˆ `@something` โ• ๐Ÿ ๐Ÿค™ "๐Ÿ‘จโ€๐ŸŽจ".
๐Ÿ‘† ๐Ÿšฎ โšซ๏ธ ๐Ÿ”› ๐Ÿ” ๐Ÿ”ข. ๐Ÿ’– ๐Ÿ“ถ ๐Ÿ“” ๐Ÿ‘’ (๐Ÿ‘ค ๐Ÿ’ญ ๐Ÿ‘ˆ ๐ŸŒโ” โš– ๐Ÿ‘Ÿ โšช๏ธโžก๏ธ).
"๐Ÿ‘จโ€๐ŸŽจ" โœŠ ๐Ÿ”ข ๐Ÿ”› &amp; ๐Ÿ”จ ๐Ÿ•ณ โฎ๏ธ โšซ๏ธ.
๐Ÿ‘† ๐Ÿ’ผ, ๐Ÿ‘‰ ๐Ÿ‘จโ€๐ŸŽจ ๐Ÿ’ฌ **FastAPI** ๐Ÿ‘ˆ ๐Ÿ”ข ๐Ÿ”› ๐Ÿ”— **โžก** `/` โฎ๏ธ **๐Ÿ› ๏ธ** `get`.
โšซ๏ธ "**โžก ๐Ÿ› ๏ธ ๐Ÿ‘จโ€๐ŸŽจ**".
๐Ÿ‘† ๐Ÿ’ช โš™๏ธ ๐ŸŽ ๐Ÿ› ๏ธ:
* `@app.post()`
* `@app.put()`
* `@app.delete()`
&amp; ๐ŸŒ… ๐Ÿ˜ ๐Ÿ•:
* `@app.options()`
* `@app.head()`
* `@app.patch()`
* `@app.trace()`
!!! tip
๐Ÿ‘† ๐Ÿ†“ โš™๏ธ ๐Ÿ”  ๐Ÿ› ๏ธ (๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ” ๐Ÿ‘ฉโ€๐Ÿ”ฌ) ๐Ÿ‘† ๐ŸŽ‹.
**FastAPI** ๐Ÿšซ ๐Ÿ› ๏ธ ๐Ÿ™† ๐ŸŽฏ ๐Ÿ”‘.
โ„น ๐Ÿ“ฅ ๐ŸŽ ๐Ÿ“„, ๐Ÿšซ ๐Ÿ“„.
๐Ÿ–ผ, ๐Ÿ•โ” โš™๏ธ ๐Ÿ•น ๐Ÿ‘† ๐Ÿ›Ž ๐ŸŽญ ๐ŸŒ ๐ŸŽฏ โš™๏ธ ๐Ÿ•ด `POST` ๐Ÿ› ๏ธ.
### ๐Ÿ” 4๏ธโƒฃ: ๐Ÿ”ฌ **โžก ๐Ÿ› ๏ธ ๐Ÿ”ข**
๐Ÿ‘‰ ๐Ÿ‘† "**โžก ๐Ÿ› ๏ธ ๐Ÿ”ข**":
* **โžก**: `/`.
* **๐Ÿ› ๏ธ**: `get`.
* **๐Ÿ”ข**: ๐Ÿ”ข ๐Ÿ”› "๐Ÿ‘จโ€๐ŸŽจ" (๐Ÿ”› `@app.get("/")`).
```Python hl_lines="7"
{!../../../docs_src/first_steps/tutorial001.py!}
```
๐Ÿ‘‰ ๐Ÿ ๐Ÿ”ข.
โšซ๏ธ ๐Ÿ”œ ๐Ÿค™ **FastAPI** ๐Ÿ•โ” โšซ๏ธ ๐Ÿ“จ ๐Ÿ“จ ๐Ÿ“› "`/`" โš™๏ธ `GET` ๐Ÿ› ๏ธ.
๐Ÿ‘‰ ๐Ÿ’ผ, โšซ๏ธ `async` ๐Ÿ”ข.
---
๐Ÿ‘† ๐Ÿ’ช ๐Ÿ”ฌ โšซ๏ธ ๐Ÿ˜ ๐Ÿ”ข โ†ฉ๏ธ `async def`:
```Python hl_lines="7"
{!../../../docs_src/first_steps/tutorial003.py!}
```
!!! note
๐Ÿšฅ ๐Ÿ‘† ๐Ÿšซ ๐Ÿ’ญ ๐Ÿ”บ, โœ… [๐Ÿ”: *"๐Ÿƒ โ“"*](../async.md#in-a-hurry){.internal-link target=_blank}.
### ๐Ÿ” 5๏ธโƒฃ: ๐Ÿ“จ ๐ŸŽš
```Python hl_lines="8"
{!../../../docs_src/first_steps/tutorial001.py!}
```
๐Ÿ‘† ๐Ÿ’ช ๐Ÿ“จ `dict`, `list`, โญ ๐Ÿ’ฒ `str`, `int`, โ™’๏ธ.
๐Ÿ‘† ๐Ÿ’ช ๐Ÿ“จ Pydantic ๐Ÿท (๐Ÿ‘† ๐Ÿ”œ ๐Ÿ‘€ ๐ŸŒ… ๐Ÿ”ƒ ๐Ÿ‘ˆ โช).
๐Ÿ“ค ๐Ÿ“š ๐ŸŽ ๐ŸŽš &amp; ๐Ÿท ๐Ÿ‘ˆ ๐Ÿ”œ ๐Ÿ” ๐Ÿ—œ ๐ŸŽป (๐Ÿ”Œ ๐Ÿœ, โ™’๏ธ). ๐Ÿ”„ โš™๏ธ ๐Ÿ‘† ๐Ÿ’• ๐Ÿ•, โšซ๏ธ ๐Ÿ† ๐ŸŽฒ ๐Ÿ‘ˆ ๐Ÿ‘ซ โช ๐Ÿ•โ€๐Ÿฆบ.
## ๐ŸŒƒ
* ๐Ÿ—„ `FastAPI`.
* โœ `app` ๐Ÿ‘.
* โœ **โžก ๐Ÿ› ๏ธ ๐Ÿ‘จโ€๐ŸŽจ** (๐Ÿ’– `@app.get("/")`).
* โœ **โžก ๐Ÿ› ๏ธ ๐Ÿ”ข** (๐Ÿ’– `def root(): ...` ๐Ÿ”›).
* ๐Ÿƒ ๐Ÿ› ๏ธ ๐Ÿ’ฝ (๐Ÿ’– `uvicorn main:app --reload`).

261
docs/em/docs/tutorial/handling-errors.md

@ -0,0 +1,261 @@
# ๐Ÿšš โŒ
๐Ÿ“ค ๐Ÿ“š โš  ๐ŸŒโ” ๐Ÿ‘† ๐Ÿ’ช ๐Ÿšจ โŒ ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ‘ˆ โš™๏ธ ๐Ÿ‘† ๐Ÿ› ๏ธ.
๐Ÿ‘‰ ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ’ช ๐Ÿ–ฅ โฎ๏ธ ๐Ÿ•ธ, ๐Ÿ“Ÿ โšช๏ธโžก๏ธ ๐Ÿ‘ฑ ๐Ÿ™†, โ˜ ๐Ÿ“ณ, โ™’๏ธ.
๐Ÿ‘† ๐Ÿ’ช ๐Ÿ’ช ๐Ÿ’ฌ ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ‘ˆ:
* ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿšซ โœ”๏ธ ๐Ÿฅƒ ๐Ÿ˜Œ ๐Ÿ‘ˆ ๐Ÿ› ๏ธ.
* ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿšซ โœ”๏ธ ๐Ÿ” ๐Ÿ‘ˆ โ„น.
* ๐Ÿฌ ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ”„ ๐Ÿ” ๐Ÿšซ ๐Ÿ”€.
* โ™’๏ธ.
๐Ÿ‘ซ ๐Ÿ’ผ, ๐Ÿ‘† ๐Ÿ”œ ๐Ÿ›Ž ๐Ÿ“จ **๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ” ๐Ÿ‘” ๐Ÿ“Ÿ** โ†” **4๏ธโƒฃ0๏ธโƒฃ0๏ธโƒฃ** (โšช๏ธโžก๏ธ 4๏ธโƒฃ0๏ธโƒฃ0๏ธโƒฃ 4๏ธโƒฃ9๏ธโƒฃ9๏ธโƒฃ).
๐Ÿ‘‰ ๐ŸŽ 2๏ธโƒฃ0๏ธโƒฃ0๏ธโƒฃ ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ” ๐Ÿ‘” ๐Ÿ“Ÿ (โšช๏ธโžก๏ธ 2๏ธโƒฃ0๏ธโƒฃ0๏ธโƒฃ 2๏ธโƒฃ9๏ธโƒฃ9๏ธโƒฃ). ๐Ÿ‘ˆ "2๏ธโƒฃ0๏ธโƒฃ0๏ธโƒฃ" ๐Ÿ‘” ๐Ÿ“Ÿ โ›“ ๐Ÿ‘ˆ ๐Ÿ˜ซ ๐Ÿ“ค "๐Ÿ†" ๐Ÿ“จ.
๐Ÿ‘” ๐Ÿ“Ÿ 4๏ธโƒฃ0๏ธโƒฃ0๏ธโƒฃ โ†” โ›“ ๐Ÿ‘ˆ ๐Ÿ“ค โŒ โšช๏ธโžก๏ธ ๐Ÿ‘ฉโ€๐Ÿ’ป.
๐Ÿ’ญ ๐ŸŒ ๐Ÿ‘ˆ **"4๏ธโƒฃ0๏ธโƒฃ4๏ธโƒฃ ๐Ÿšซ ๐Ÿ”Ž"** โŒ (&amp; ๐Ÿคฃ) โ“
## โš™๏ธ `HTTPException`
๐Ÿ“จ ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ” ๐Ÿ“จ โฎ๏ธ โŒ ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ‘† โš™๏ธ `HTTPException`.
### ๐Ÿ—„ `HTTPException`
```Python hl_lines="1"
{!../../../docs_src/handling_errors/tutorial001.py!}
```
### ๐Ÿคš `HTTPException` ๐Ÿ‘† ๐Ÿ“Ÿ
`HTTPException` ๐Ÿ˜ ๐Ÿ โš  โฎ๏ธ ๐ŸŒ– ๐Ÿ“Š ๐Ÿ”— ๐Ÿ”—.
โ†ฉ๏ธ โšซ๏ธ ๐Ÿ โš , ๐Ÿ‘† ๐Ÿšซ `return` โšซ๏ธ, ๐Ÿ‘† `raise` โšซ๏ธ.
๐Ÿ‘‰ โ›“ ๐Ÿ‘ˆ ๐Ÿšฅ ๐Ÿ‘† ๐Ÿ”˜ ๐Ÿš™ ๐Ÿ”ข ๐Ÿ‘ˆ ๐Ÿ‘† ๐Ÿค™ ๐Ÿ”˜ ๐Ÿ‘† *โžก ๐Ÿ› ๏ธ ๐Ÿ”ข*, &amp; ๐Ÿ‘† ๐Ÿคš `HTTPException` โšช๏ธโžก๏ธ ๐Ÿ”˜ ๐Ÿ‘ˆ ๐Ÿš™ ๐Ÿ”ข, โšซ๏ธ ๐Ÿ† ๐Ÿšซ ๐Ÿƒ ๐ŸŽ‚ ๐Ÿ“Ÿ *โžก ๐Ÿ› ๏ธ ๐Ÿ”ข*, โšซ๏ธ ๐Ÿ”œ โŽ ๐Ÿ‘ˆ ๐Ÿ“จ โ–ถ๏ธ๏ธ โ†–๏ธ &amp; ๐Ÿ“จ ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ” โŒ โšช๏ธโžก๏ธ `HTTPException` ๐Ÿ‘ฉโ€๐Ÿ’ป.
๐Ÿ’ฐ ๐Ÿ™‹โ€โ™€ โš  ๐Ÿคญ `return`๐Ÿ˜… ๐Ÿ’ฒ ๐Ÿ”œ ๐ŸŒ– โญ ๐Ÿ“„ ๐Ÿ”ƒ ๐Ÿ”— &amp; ๐Ÿ’‚โ€โ™‚.
๐Ÿ‘‰ ๐Ÿ–ผ, ๐Ÿ•โ” ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ“จ ๐Ÿฌ ๐Ÿ†” ๐Ÿ‘ˆ ๐Ÿšซ ๐Ÿ”€, ๐Ÿคš โš  โฎ๏ธ ๐Ÿ‘” ๐Ÿ“Ÿ `404`:
```Python hl_lines="11"
{!../../../docs_src/handling_errors/tutorial001.py!}
```
### ๐Ÿ“‰ ๐Ÿ“จ
๐Ÿšฅ ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ“จ `http://example.com/items/foo` ( `item_id` `"foo"`), ๐Ÿ‘ˆ ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ”œ ๐Ÿ“จ ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ” ๐Ÿ‘” ๐Ÿ“Ÿ 2๏ธโƒฃ0๏ธโƒฃ0๏ธโƒฃ, &amp; ๐ŸŽป ๐Ÿ“จ:
```JSON
{
"item": "The Foo Wrestlers"
}
```
โœ‹๏ธ ๐Ÿšฅ ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ“จ `http://example.com/items/bar` (๐Ÿšซ-๐Ÿšซ `item_id` `"bar"`), ๐Ÿ‘ˆ ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ”œ ๐Ÿ“จ ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ” ๐Ÿ‘” ๐Ÿ“Ÿ 4๏ธโƒฃ0๏ธโƒฃ4๏ธโƒฃ ("๐Ÿšซ ๐Ÿ”Ž" โŒ), &amp; ๐ŸŽป ๐Ÿ“จ:
```JSON
{
"detail": "Item not found"
}
```
!!! tip
๐Ÿ•โ” ๐Ÿ™‹โ€โ™€ `HTTPException`, ๐Ÿ‘† ๐Ÿ’ช ๐Ÿšถโ€โ™€๏ธ ๐Ÿ™† ๐Ÿ’ฒ ๐Ÿ‘ˆ ๐Ÿ’ช ๐Ÿ—œ ๐ŸŽป ๐Ÿ”ข `detail`, ๐Ÿšซ ๐Ÿ•ด `str`.
๐Ÿ‘† ๐Ÿ’ช ๐Ÿšถโ€โ™€๏ธ `dict`, `list`, โ™’๏ธ.
๐Ÿ‘ซ ๐Ÿต ๐Ÿ” **FastAPI** &amp; ๐Ÿ—œ ๐ŸŽป.
## ๐Ÿšฎ ๐Ÿ›ƒ ๐ŸŽš
๐Ÿ“ค โš  ๐ŸŒโ” โšซ๏ธ โš  ๐Ÿ’ช ๐Ÿšฎ ๐Ÿ›ƒ ๐ŸŽš ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ” โŒ. ๐Ÿ–ผ, ๐Ÿ†Ž ๐Ÿ’‚โ€โ™‚.
๐Ÿ‘† ๐ŸŽฒ ๐Ÿ† ๐Ÿšซ ๐Ÿ’ช โš™๏ธ โšซ๏ธ ๐Ÿ”— ๐Ÿ‘† ๐Ÿ“Ÿ.
โœ‹๏ธ ๐Ÿ’ผ ๐Ÿ‘† ๐Ÿ’ช โšซ๏ธ ๐Ÿง ๐Ÿ˜, ๐Ÿ‘† ๐Ÿ’ช ๐Ÿšฎ ๐Ÿ›ƒ ๐ŸŽš:
```Python hl_lines="14"
{!../../../docs_src/handling_errors/tutorial002.py!}
```
## โŽ ๐Ÿ›ƒ โš  ๐Ÿ•โ€๐Ÿฆบ
๐Ÿ‘† ๐Ÿ’ช ๐Ÿšฎ ๐Ÿ›ƒ โš  ๐Ÿ•โ€๐Ÿฆบ โฎ๏ธ <a href="https://www.starlette.io/exceptions/" class="external-link" target="_blank">๐ŸŽ โš  ๐Ÿš™ โšช๏ธโžก๏ธ ๐Ÿ’ƒ</a>.
โžก๏ธ ๐Ÿ’ฌ ๐Ÿ‘† โœ”๏ธ ๐Ÿ›ƒ โš  `UnicornException` ๐Ÿ‘ˆ ๐Ÿ‘† (โš–๏ธ ๐Ÿ—ƒ ๐Ÿ‘† โš™๏ธ) ๐Ÿ’ช `raise`.
&amp; ๐Ÿ‘† ๐Ÿ’š ๐Ÿต ๐Ÿ‘‰ โš  ๐ŸŒ โฎ๏ธ FastAPI.
๐Ÿ‘† ๐Ÿ’ช ๐Ÿšฎ ๐Ÿ›ƒ โš  ๐Ÿ•โ€๐Ÿฆบ โฎ๏ธ `@app.exception_handler()`:
```Python hl_lines="5-7 13-18 24"
{!../../../docs_src/handling_errors/tutorial003.py!}
```
๐Ÿ“ฅ, ๐Ÿšฅ ๐Ÿ‘† ๐Ÿ“จ `/unicorns/yolo`, *โžก ๐Ÿ› ๏ธ* ๐Ÿ”œ `raise` `UnicornException`.
โœ‹๏ธ โšซ๏ธ ๐Ÿ”œ ๐Ÿต `unicorn_exception_handler`.
, ๐Ÿ‘† ๐Ÿ”œ ๐Ÿ“จ ๐Ÿงน โŒ, โฎ๏ธ ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ” ๐Ÿ‘” ๐Ÿ“Ÿ `418` &amp; ๐ŸŽป ๐ŸŽš:
```JSON
{"message": "Oops! yolo did something. There goes a rainbow..."}
```
!!! note "๐Ÿ“ก โ„น"
๐Ÿ‘† ๐Ÿ’ช โš™๏ธ `from starlette.requests import Request` &amp; `from starlette.responses import JSONResponse`.
**FastAPI** ๐Ÿšš ๐ŸŽ `starlette.responses` `fastapi.responses` ๐Ÿช ๐Ÿ‘†, ๐Ÿ‘ฉโ€๐Ÿ’ป. โœ‹๏ธ ๐ŸŒ… ๐Ÿ’ช ๐Ÿ“จ ๐Ÿ‘Ÿ ๐Ÿ”— โšช๏ธโžก๏ธ ๐Ÿ’ƒ. ๐ŸŽ โฎ๏ธ `Request`.
## ๐Ÿ” ๐Ÿ”ข โš  ๐Ÿ•โ€๐Ÿฆบ
**FastAPI** โœ”๏ธ ๐Ÿ”ข โš  ๐Ÿ•โ€๐Ÿฆบ.
๐Ÿ‘ซ ๐Ÿ•โ€๐Ÿฆบ ๐Ÿˆš ๐Ÿ›ฌ ๐Ÿ”ข ๐ŸŽป ๐Ÿ“จ ๐Ÿ•โ” ๐Ÿ‘† `raise` `HTTPException` &amp; ๐Ÿ•โ” ๐Ÿ“จ โœ”๏ธ โŒ ๐Ÿ’ฝ.
๐Ÿ‘† ๐Ÿ’ช ๐Ÿ” ๐Ÿ‘ซ โš  ๐Ÿ•โ€๐Ÿฆบ โฎ๏ธ ๐Ÿ‘† ๐Ÿ‘.
### ๐Ÿ” ๐Ÿ“จ ๐Ÿ”ฌ โš 
๐Ÿ•โ” ๐Ÿ“จ ๐Ÿ”Œ โŒ ๐Ÿ“Š, **FastAPI** ๐Ÿ”˜ ๐Ÿคš `RequestValidationError`.
&amp; โšซ๏ธ ๐Ÿ”Œ ๐Ÿ”ข โš  ๐Ÿ•โ€๐Ÿฆบ โšซ๏ธ.
๐Ÿ” โšซ๏ธ, ๐Ÿ—„ `RequestValidationError` &amp; โš™๏ธ โšซ๏ธ โฎ๏ธ `@app.exception_handler(RequestValidationError)` ๐ŸŽ€ โš  ๐Ÿ•โ€๐Ÿฆบ.
โš  ๐Ÿ•โ€๐Ÿฆบ ๐Ÿ”œ ๐Ÿ“จ `Request` &amp; โš .
```Python hl_lines="2 14-16"
{!../../../docs_src/handling_errors/tutorial004.py!}
```
๐Ÿ”œ, ๐Ÿšฅ ๐Ÿ‘† ๐Ÿšถ `/items/foo`, โ†ฉ๏ธ ๐Ÿ’†โ€โ™‚ ๐Ÿ”ข ๐ŸŽป โŒ โฎ๏ธ:
```JSON
{
"detail": [
{
"loc": [
"path",
"item_id"
],
"msg": "value is not a valid integer",
"type": "type_error.integer"
}
]
}
```
๐Ÿ‘† ๐Ÿ”œ ๐Ÿคš โœ โฌ, โฎ๏ธ:
```
1 validation error
path -> item_id
value is not a valid integer (type=type_error.integer)
```
#### `RequestValidationError` ๐Ÿ†š `ValidationError`
!!! warning
๐Ÿ‘ซ ๐Ÿ“ก โ„น ๐Ÿ‘ˆ ๐Ÿ‘† ๐Ÿ’ช ๐Ÿšถ ๐Ÿšฅ โšซ๏ธ ๐Ÿšซ โš  ๐Ÿ‘† ๐Ÿ”œ.
`RequestValidationError` ๐ŸŽง-๐ŸŽ“ Pydantic <a href="https://pydantic-docs.helpmanual.io/usage/models/#error-handling" class="external-link" target="_blank">`ValidationError`</a>.
**FastAPI** โš™๏ธ โšซ๏ธ ๐Ÿ‘ˆ, ๐Ÿšฅ ๐Ÿ‘† โš™๏ธ Pydantic ๐Ÿท `response_model`, &amp; ๐Ÿ‘† ๐Ÿ’ฝ โœ”๏ธ โŒ, ๐Ÿ‘† ๐Ÿ”œ ๐Ÿ‘€ โŒ ๐Ÿ‘† ๐Ÿ•น.
โœ‹๏ธ ๐Ÿ‘ฉโ€๐Ÿ’ป/๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ”œ ๐Ÿšซ ๐Ÿ‘€ โšซ๏ธ. โ†ฉ๏ธ, ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ”œ ๐Ÿ“จ "๐Ÿ”— ๐Ÿ’ฝ โŒ" โฎ๏ธ ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ” ๐Ÿ‘” ๐Ÿ“Ÿ `500`.
โšซ๏ธ ๐Ÿ”œ ๐Ÿ‘‰ ๐ŸŒŒ โ†ฉ๏ธ ๐Ÿšฅ ๐Ÿ‘† โœ”๏ธ Pydantic `ValidationError` ๐Ÿ‘† *๐Ÿ“จ* โš–๏ธ ๐Ÿ™† ๐Ÿ‘† ๐Ÿ“Ÿ (๐Ÿšซ ๐Ÿ‘ฉโ€๐Ÿ’ป *๐Ÿ“จ*), โšซ๏ธ ๐Ÿค™ ๐Ÿ› ๐Ÿ‘† ๐Ÿ“Ÿ.
&amp; โช ๐Ÿ‘† ๐Ÿ”ง โšซ๏ธ, ๐Ÿ‘† ๐Ÿ‘ฉโ€๐Ÿ’ป/๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿšซ๐Ÿ”œ ๐Ÿšซ โœ”๏ธ ๐Ÿ” ๐Ÿ”— โ„น ๐Ÿ”ƒ โŒ, ๐Ÿ‘ˆ ๐Ÿ’ช ๐ŸŽฆ ๐Ÿ’‚โ€โ™‚ โš .
### ๐Ÿ” `HTTPException` โŒ ๐Ÿ•โ€๐Ÿฆบ
๐ŸŽ ๐ŸŒŒ, ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ” `HTTPException` ๐Ÿ•โ€๐Ÿฆบ.
๐Ÿ–ผ, ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ’š ๐Ÿ“จ โœ… โœ ๐Ÿ“จ โ†ฉ๏ธ ๐ŸŽป ๐Ÿ‘ซ โŒ:
```Python hl_lines="3-4 9-11 22"
{!../../../docs_src/handling_errors/tutorial004.py!}
```
!!! note "๐Ÿ“ก โ„น"
๐Ÿ‘† ๐Ÿ’ช โš™๏ธ `from starlette.responses import PlainTextResponse`.
**FastAPI** ๐Ÿšš ๐ŸŽ `starlette.responses` `fastapi.responses` ๐Ÿช ๐Ÿ‘†, ๐Ÿ‘ฉโ€๐Ÿ’ป. โœ‹๏ธ ๐ŸŒ… ๐Ÿ’ช ๐Ÿ“จ ๐Ÿ‘Ÿ ๐Ÿ”— โšช๏ธโžก๏ธ ๐Ÿ’ƒ.
### โš™๏ธ `RequestValidationError` ๐Ÿ’ช
`RequestValidationError` ๐Ÿ”Œ `body` โšซ๏ธ ๐Ÿ“จ โฎ๏ธ โŒ ๐Ÿ’ฝ.
๐Ÿ‘† ๐Ÿ’ช โš™๏ธ โšซ๏ธ โช ๐Ÿ› ๏ธ ๐Ÿ‘† ๐Ÿ“ฑ ๐Ÿ•น ๐Ÿ’ช &amp; โ„น โšซ๏ธ, ๐Ÿ“จ โšซ๏ธ ๐Ÿ‘ฉโ€๐Ÿ’ป, โ™’๏ธ.
```Python hl_lines="14"
{!../../../docs_src/handling_errors/tutorial005.py!}
```
๐Ÿ”œ ๐Ÿ”„ ๐Ÿ“จ โŒ ๐Ÿฌ ๐Ÿ’–:
```JSON
{
"title": "towel",
"size": "XL"
}
```
๐Ÿ‘† ๐Ÿ”œ ๐Ÿ“จ ๐Ÿ“จ ๐Ÿ’ฌ ๐Ÿ‘† ๐Ÿ‘ˆ ๐Ÿ’ฝ โŒ โš— ๐Ÿ“จ ๐Ÿ’ช:
```JSON hl_lines="12-15"
{
"detail": [
{
"loc": [
"body",
"size"
],
"msg": "value is not a valid integer",
"type": "type_error.integer"
}
],
"body": {
"title": "towel",
"size": "XL"
}
}
```
#### FastAPI `HTTPException` ๐Ÿ†š ๐Ÿ’ƒ `HTTPException`
**FastAPI** โœ”๏ธ ๐Ÿšฎ ๐Ÿ‘ `HTTPException`.
&amp; **FastAPI**'โ“‚ `HTTPException` โŒ ๐ŸŽ“ ๐Ÿ˜– โšช๏ธโžก๏ธ ๐Ÿ’ƒ `HTTPException` โŒ ๐ŸŽ“.
๐Ÿ•ด ๐Ÿ”บ, ๐Ÿ‘ˆ **FastAPI**'โ“‚ `HTTPException` โœ” ๐Ÿ‘† ๐Ÿšฎ ๐ŸŽš ๐Ÿ”Œ ๐Ÿ“จ.
๐Ÿ‘‰ ๐Ÿ’ช/โš™๏ธ ๐Ÿ”˜ โœณ 2๏ธโƒฃ.0๏ธโƒฃ &amp; ๐Ÿ’‚โ€โ™‚ ๐Ÿš™.
, ๐Ÿ‘† ๐Ÿ’ช ๐Ÿšง ๐Ÿ™‹โ€โ™€ **FastAPI**'โ“‚ `HTTPException` ๐Ÿ›Ž ๐Ÿ‘† ๐Ÿ“Ÿ.
โœ‹๏ธ ๐Ÿ•โ” ๐Ÿ‘† ยฎ โš  ๐Ÿ•โ€๐Ÿฆบ, ๐Ÿ‘† ๐Ÿ”œ ยฎ โšซ๏ธ ๐Ÿ’ƒ `HTTPException`.
๐Ÿ‘‰ ๐ŸŒŒ, ๐Ÿšฅ ๐Ÿ™† ๐Ÿ• ๐Ÿ’ƒ ๐Ÿ”— ๐Ÿ“Ÿ, โš–๏ธ ๐Ÿ’ƒ โ†” โš–๏ธ ๐Ÿ”Œ -, ๐Ÿคš ๐Ÿ’ƒ `HTTPException`, ๐Ÿ‘† ๐Ÿ•โ€๐Ÿฆบ ๐Ÿ”œ ๐Ÿ’ช โœŠ &amp; ๐Ÿต โšซ๏ธ.
๐Ÿ‘‰ ๐Ÿ–ผ, ๐Ÿ’ช โœ”๏ธ ๐Ÿ‘ฏโ€โ™‚๏ธ `HTTPException`โ“‚ ๐ŸŽ ๐Ÿ“Ÿ, ๐Ÿ’ƒ โš  ๐Ÿ“ `StarletteHTTPException`:
```Python
from starlette.exceptions import HTTPException as StarletteHTTPException
```
### ๐Ÿค-โš™๏ธ **FastAPI**'โ“‚ โš  ๐Ÿ•โ€๐Ÿฆบ
๐Ÿšฅ ๐Ÿ‘† ๐Ÿ’š โš™๏ธ โš  โคด๏ธ โฎ๏ธ ๐ŸŽ ๐Ÿ”ข โš  ๐Ÿ•โ€๐Ÿฆบ โšช๏ธโžก๏ธ **FastAPI**, ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ—„ &amp; ๐Ÿค-โš™๏ธ ๐Ÿ”ข โš  ๐Ÿ•โ€๐Ÿฆบ โšช๏ธโžก๏ธ `fastapi.exception_handlers`:
```Python hl_lines="2-5 15 21"
{!../../../docs_src/handling_errors/tutorial006.py!}
```
๐Ÿ‘‰ ๐Ÿ–ผ ๐Ÿ‘† `print`๐Ÿ˜… โŒ โฎ๏ธ ๐Ÿ“ถ ๐ŸŽจ ๐Ÿ“ง, โœ‹๏ธ ๐Ÿ‘† ๐Ÿคš ๐Ÿ’ญ. ๐Ÿ‘† ๐Ÿ’ช โš™๏ธ โš  &amp; โคด๏ธ ๐Ÿค-โš™๏ธ ๐Ÿ”ข โš  ๐Ÿ•โ€๐Ÿฆบ.

128
docs/em/docs/tutorial/header-params.md

@ -0,0 +1,128 @@
# ๐ŸŽš ๐Ÿ”ข
๐Ÿ‘† ๐Ÿ’ช ๐Ÿ”ฌ ๐ŸŽš ๐Ÿ”ข ๐ŸŽ ๐ŸŒŒ ๐Ÿ‘† ๐Ÿ”ฌ `Query`, `Path` &amp; `Cookie` ๐Ÿ”ข.
## ๐Ÿ—„ `Header`
๐Ÿฅ‡ ๐Ÿ—„ `Header`:
=== "๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="3"
{!> ../../../docs_src/header_params/tutorial001.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.1๏ธโƒฃ0๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="1"
{!> ../../../docs_src/header_params/tutorial001_py310.py!}
```
## ๐Ÿ“ฃ `Header` ๐Ÿ”ข
โคด๏ธ ๐Ÿ“ฃ ๐ŸŽš ๐Ÿ”ข โš™๏ธ ๐ŸŽ ๐Ÿ“Š โฎ๏ธ `Path`, `Query` &amp; `Cookie`.
๐Ÿฅ‡ ๐Ÿ’ฒ ๐Ÿ”ข ๐Ÿ’ฒ, ๐Ÿ‘† ๐Ÿ’ช ๐Ÿšถโ€โ™€๏ธ ๐ŸŒ โž• ๐Ÿ”ฌ โš–๏ธ โœ ๐Ÿ”ข:
=== "๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="9"
{!> ../../../docs_src/header_params/tutorial001.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.1๏ธโƒฃ0๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="7"
{!> ../../../docs_src/header_params/tutorial001_py310.py!}
```
!!! note "๐Ÿ“ก โ„น"
`Header` "๐Ÿ‘ญ" ๐ŸŽ“ `Path`, `Query` &amp; `Cookie`. โšซ๏ธ ๐Ÿ˜– โšช๏ธโžก๏ธ ๐ŸŽ โš  `Param` ๐ŸŽ“.
โœ‹๏ธ ๐Ÿ’ญ ๐Ÿ‘ˆ ๐Ÿ•โ” ๐Ÿ‘† ๐Ÿ—„ `Query`, `Path`, `Header`, &amp; ๐ŸŽ โšช๏ธโžก๏ธ `fastapi`, ๐Ÿ‘ˆ ๐Ÿค™ ๐Ÿ”ข ๐Ÿ‘ˆ ๐Ÿ“จ ๐ŸŽ ๐ŸŽ“.
!!! info
๐Ÿ“ฃ ๐ŸŽš, ๐Ÿ‘† ๐Ÿ’ช โš™๏ธ `Header`, โ†ฉ๏ธ โช ๐Ÿ”ข ๐Ÿ”œ ๐Ÿ”ฌ ๐Ÿ”ข ๐Ÿ”ข.
## ๐Ÿง ๐Ÿ› ๏ธ
`Header` โœ”๏ธ ๐Ÿฅ โž• ๐Ÿ› ๏ธ ๐Ÿ”› ๐Ÿ” โšซ๏ธโ” `Path`, `Query` &amp; `Cookie` ๐Ÿšš.
๐ŸŒ… ๐Ÿฉ ๐ŸŽš ๐ŸŽ "๐Ÿ” " ๐Ÿฆน, ๐Ÿ’ญ "โž– ๐Ÿ”ฃ" (`-`).
โœ‹๏ธ ๐Ÿ”ข ๐Ÿ’– `user-agent` โŒ ๐Ÿ.
, ๐Ÿ”ข, `Header` ๐Ÿ”œ ๐Ÿ—œ ๐Ÿ”ข ๐Ÿ“› ๐Ÿฆน โšช๏ธโžก๏ธ ๐ŸŽฆ (`_`) ๐Ÿ”  (`-`) โš— &amp; ๐Ÿ“„ ๐ŸŽš.
, ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ” ๐ŸŽš ๐Ÿ’ผ-๐Ÿ˜›,, ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ“ฃ ๐Ÿ‘ซ โฎ๏ธ ๐Ÿฉ ๐Ÿ ๐Ÿ‘— (๐Ÿ’ญ "๐Ÿ”ก").
, ๐Ÿ‘† ๐Ÿ’ช โš™๏ธ `user_agent` ๐Ÿ‘† ๐Ÿ›Ž ๐Ÿ”œ ๐Ÿ ๐Ÿ“Ÿ, โ†ฉ๏ธ ๐Ÿ’†โ€โ™‚ ๐ŸŽฏ ๐Ÿฅ‡ ๐Ÿ”ค `User_Agent` โš–๏ธ ๐Ÿ•ณ ๐ŸŽ.
๐Ÿšฅ ๐Ÿค” ๐Ÿ‘† ๐Ÿ’ช โŽ ๐Ÿง ๐Ÿ› ๏ธ ๐ŸŽฆ ๐Ÿ” , โš’ ๐Ÿ”ข `convert_underscores` `Header` `False`:
=== "๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="10"
{!> ../../../docs_src/header_params/tutorial002.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.1๏ธโƒฃ0๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="8"
{!> ../../../docs_src/header_params/tutorial002_py310.py!}
```
!!! warning
โญ โš’ `convert_underscores` `False`, ๐Ÿป ๐Ÿคฏ ๐Ÿ‘ˆ ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ” ๐Ÿ—ณ &amp; ๐Ÿ’ฝ / โš™๏ธ ๐ŸŽš โฎ๏ธ ๐ŸŽฆ.
## โŽ ๐ŸŽš
โšซ๏ธ ๐Ÿ’ช ๐Ÿ“จ โŽ ๐ŸŽš. ๐Ÿ‘ˆ โ›“, ๐ŸŽ ๐ŸŽš โฎ๏ธ ๐Ÿ’— ๐Ÿ’ฒ.
๐Ÿ‘† ๐Ÿ’ช ๐Ÿ”ฌ ๐Ÿ‘ˆ ๐Ÿ’ผ โš™๏ธ ๐Ÿ“‡ ๐Ÿ†Ž ๐Ÿ“„.
๐Ÿ‘† ๐Ÿ”œ ๐Ÿ“จ ๐ŸŒ ๐Ÿ’ฒ โšช๏ธโžก๏ธ โŽ ๐ŸŽš ๐Ÿ `list`.
๐Ÿ–ผ, ๐Ÿ“ฃ ๐ŸŽš `X-Token` ๐Ÿ‘ˆ ๐Ÿ’ช ๐Ÿ˜‘ ๐ŸŒ… ๐ŸŒ˜ ๐Ÿ•, ๐Ÿ‘† ๐Ÿ’ช โœ:
=== "๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="9"
{!> ../../../docs_src/header_params/tutorial003.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.9๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="9"
{!> ../../../docs_src/header_params/tutorial003_py39.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.1๏ธโƒฃ0๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="7"
{!> ../../../docs_src/header_params/tutorial003_py310.py!}
```
๐Ÿšฅ ๐Ÿ‘† ๐Ÿ”— โฎ๏ธ ๐Ÿ‘ˆ *โžก ๐Ÿ› ๏ธ* ๐Ÿ“จ 2๏ธโƒฃ ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ” ๐ŸŽš ๐Ÿ’–:
```
X-Token: foo
X-Token: bar
```
๐Ÿ“จ ๐Ÿ”œ ๐Ÿ’–:
```JSON
{
"X-Token values": [
"bar",
"foo"
]
}
```
## ๐ŸŒƒ
๐Ÿ“ฃ ๐ŸŽš โฎ๏ธ `Header`, โš™๏ธ ๐ŸŽ โš  โš“ `Query`, `Path` &amp; `Cookie`.
&amp; ๐Ÿšซ ๐Ÿ˜Ÿ ๐Ÿ”ƒ ๐ŸŽฆ ๐Ÿ‘† ๐Ÿ”ข, **FastAPI** ๐Ÿ”œ โœŠ ๐Ÿ’… ๐Ÿญ ๐Ÿ‘ซ.

80
docs/em/docs/tutorial/index.md

@ -0,0 +1,80 @@
# ๐Ÿ”ฐ - ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿฆฎ - ๐ŸŽถ
๐Ÿ‘‰ ๐Ÿ”ฐ ๐ŸŽฆ ๐Ÿ‘† โ” โš™๏ธ **FastAPI** โฎ๏ธ ๐ŸŒ… ๐Ÿšฎ โš’, ๐Ÿ” ๐Ÿ”.
๐Ÿ”  ๐Ÿ“„ ๐Ÿ“‰ ๐Ÿ— ๐Ÿ”› โฎ๏ธ ๐Ÿ•, โœ‹๏ธ โšซ๏ธ ๐Ÿ— ๐ŸŽ โ”, ๐Ÿ‘ˆ ๐Ÿ‘† ๐Ÿ’ช ๐Ÿšถ ๐Ÿ”— ๐Ÿ™† ๐ŸŽฏ 1๏ธโƒฃ โŽ ๐Ÿ‘† ๐ŸŽฏ ๐Ÿ› ๏ธ ๐Ÿ’ช.
โšซ๏ธ ๐Ÿ— ๐Ÿ‘ท ๐Ÿ”ฎ ๐Ÿ”—.
๐Ÿ‘† ๐Ÿ’ช ๐Ÿ‘Ÿ ๐Ÿ”™ &amp; ๐Ÿ‘€ โšซ๏ธโ” โšซ๏ธโ” ๐Ÿ‘† ๐Ÿ’ช.
## ๐Ÿƒ ๐Ÿ“Ÿ
๐ŸŒ ๐Ÿ“Ÿ ๐Ÿซ ๐Ÿ’ช ๐Ÿ“ &amp; โš™๏ธ ๐Ÿ”— (๐Ÿ‘ซ ๐Ÿค™ ๐Ÿ’ฏ ๐Ÿ ๐Ÿ“).
๐Ÿƒ ๐Ÿ™† ๐Ÿ–ผ, ๐Ÿ“ ๐Ÿ“Ÿ ๐Ÿ“ `main.py`, &amp; โ–ถ๏ธ `uvicorn` โฎ๏ธ:
<div class="termy">
```console
$ uvicorn main:app --reload
<span style="color: green;">INFO</span>: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
<span style="color: green;">INFO</span>: Started reloader process [28720]
<span style="color: green;">INFO</span>: Started server process [28722]
<span style="color: green;">INFO</span>: Waiting for application startup.
<span style="color: green;">INFO</span>: Application startup complete.
```
</div>
โšซ๏ธ **๐Ÿ† ๐Ÿ’ก** ๐Ÿ‘ˆ ๐Ÿ‘† โœ โš–๏ธ ๐Ÿ“ ๐Ÿ“Ÿ, โœ โšซ๏ธ &amp; ๐Ÿƒ โšซ๏ธ ๐ŸŒ.
โš™๏ธ โšซ๏ธ ๐Ÿ‘† ๐Ÿ‘จโ€๐ŸŽจ โšซ๏ธโ” ๐Ÿค™ ๐ŸŽฆ ๐Ÿ‘† ๐Ÿ’ฐ FastAPI, ๐Ÿ‘€ โ” ๐Ÿฅ ๐Ÿ“Ÿ ๐Ÿ‘† โœ”๏ธ โœ, ๐ŸŒ ๐Ÿ†Ž โœ…, โœ, โ™’๏ธ.
---
## โŽ FastAPI
๐Ÿฅ‡ ๐Ÿ” โŽ FastAPI.
๐Ÿ”ฐ, ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ’š โŽ โšซ๏ธ โฎ๏ธ ๐ŸŒ ๐Ÿ“ฆ ๐Ÿ”— &amp; โš’:
<div class="termy">
```console
$ pip install "fastapi[all]"
---> 100%
```
</div>
...๐Ÿ‘ˆ ๐Ÿ”Œ `uvicorn`, ๐Ÿ‘ˆ ๐Ÿ‘† ๐Ÿ’ช โš™๏ธ ๐Ÿ’ฝ ๐Ÿ‘ˆ ๐Ÿƒ ๐Ÿ‘† ๐Ÿ“Ÿ.
!!! note
๐Ÿ‘† ๐Ÿ’ช โŽ โšซ๏ธ ๐Ÿ• ๐Ÿ•.
๐Ÿ‘‰ โšซ๏ธโ” ๐Ÿ‘† ๐Ÿ”œ ๐ŸŽฒ ๐Ÿ• ๐Ÿ‘† ๐Ÿ’š ๐Ÿ› ๏ธ ๐Ÿ‘† ๐Ÿˆธ ๐Ÿญ:
```
pip install fastapi
```
โŽ `uvicorn` ๐Ÿ‘ท ๐Ÿ’ฝ:
```
pip install "uvicorn[standard]"
```
&amp; ๐ŸŽ ๐Ÿ”  ๐Ÿ“ฆ ๐Ÿ”— ๐Ÿ‘ˆ ๐Ÿ‘† ๐Ÿ’š โš™๏ธ.
## ๐Ÿง ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿฆฎ
๐Ÿ“ค **๐Ÿง ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿฆฎ** ๐Ÿ‘ˆ ๐Ÿ‘† ๐Ÿ’ช โœ โช โฎ๏ธ ๐Ÿ‘‰ **๐Ÿ”ฐ - ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿฆฎ**.
**๐Ÿง ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿฆฎ**, ๐Ÿ— ๐Ÿ”› ๐Ÿ‘‰, โš™๏ธ ๐ŸŽ ๐Ÿ”ง, &amp; ๐Ÿ’ก ๐Ÿ‘† โž• โš’.
โœ‹๏ธ ๐Ÿ‘† ๐Ÿ”œ ๐Ÿฅ‡ โœ **๐Ÿ”ฐ - ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿฆฎ** (โšซ๏ธโ” ๐Ÿ‘† ๐Ÿ‘‚ โ–ถ๏ธ๏ธ ๐Ÿ”œ).
โšซ๏ธ ๐Ÿ”ง ๐Ÿ‘ˆ ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ— ๐Ÿ ๐Ÿˆธ โฎ๏ธ **๐Ÿ”ฐ - ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿฆฎ**, &amp; โคด๏ธ โ†” โšซ๏ธ ๐ŸŽ ๐ŸŒŒ, โš“๏ธ ๐Ÿ”› ๐Ÿ‘† ๐Ÿ’ช, โš™๏ธ ๐ŸŒ– ๐Ÿ’ญ โšช๏ธโžก๏ธ **๐Ÿง ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿฆฎ**.

112
docs/em/docs/tutorial/metadata.md

@ -0,0 +1,112 @@
# ๐Ÿ—ƒ &amp; ๐Ÿฉบ ๐Ÿ“›
๐Ÿ‘† ๐Ÿ’ช ๐Ÿ›ƒ ๐Ÿ“š ๐Ÿ—ƒ ๐Ÿ“ณ ๐Ÿ‘† **FastAPI** ๐Ÿˆธ.
## ๐Ÿ—ƒ ๐Ÿ› ๏ธ
๐Ÿ‘† ๐Ÿ’ช โš’ ๐Ÿ“„ ๐Ÿ‘ ๐Ÿ‘ˆ โš™๏ธ ๐Ÿ—„ ๐Ÿ”ง &amp; ๐Ÿง ๐Ÿ› ๏ธ ๐Ÿฉบ โšœ:
| ๐Ÿ”ข | ๐Ÿ†Ž | ๐Ÿ“› |
|------------|------|-------------|
| `title` | `str` | ๐Ÿ“› ๐Ÿ› ๏ธ. |
| `description` | `str` | ๐Ÿ“ ๐Ÿ“› ๐Ÿ› ๏ธ. โšซ๏ธ ๐Ÿ’ช โš™๏ธ โœ. |
| `version` | `string` | โฌ ๐Ÿ› ๏ธ. ๐Ÿ‘‰ โฌ ๐Ÿ‘† ๐Ÿ‘ ๐Ÿˆธ, ๐Ÿšซ ๐Ÿ—„. ๐Ÿ–ผ `2.5.0`. |
| `terms_of_service` | `str` | ๐Ÿ“› โš– ๐Ÿ•โ€๐Ÿฆบ ๐Ÿ› ๏ธ. ๐Ÿšฅ ๐Ÿšš, ๐Ÿ‘‰ โœ”๏ธ ๐Ÿ“›. |
| `contact` | `dict` | ๐Ÿ“ง โ„น ๐ŸŽฆ ๐Ÿ› ๏ธ. โšซ๏ธ ๐Ÿ’ช ๐Ÿ”Œ ๐Ÿ“š ๐Ÿ‘. <details><summary><code>contact</code> ๐Ÿ‘</summary><table><thead><tr><th>๐Ÿ”ข</th><th>๐Ÿ†Ž</th><th>๐Ÿ“›</th></tr></thead><tbody><tr><td><code>name</code></td><td><code>str</code></td><td>โš– ๐Ÿ“› ๐Ÿ“ง ๐Ÿ‘จโ€๐Ÿ’ผ/๐Ÿข.</td></tr><tr><td><code>url</code></td><td><code>str</code></td><td>๐Ÿ“› โ˜ ๐Ÿ“ง โ„น. ๐Ÿ”œ ๐Ÿ“ ๐Ÿ“›.</td></tr><tr><td><code>email</code></td><td><code>str</code></td><td>๐Ÿ“ง ๐Ÿ“ข ๐Ÿ“ง ๐Ÿ‘จโ€๐Ÿ’ผ/๐Ÿข. ๐Ÿ”œ ๐Ÿ“ ๐Ÿ“ง ๐Ÿ“ข. </td></tr></tbody></table></details> |
| `license_info` | `dict` | ๐Ÿ›‚ โ„น ๐ŸŽฆ ๐Ÿ› ๏ธ. โšซ๏ธ ๐Ÿ’ช ๐Ÿ”Œ ๐Ÿ“š ๐Ÿ‘. <details><summary><code>license_info</code> ๐Ÿ‘</summary><table><thead><tr><th>๐Ÿ”ข</th><th>๐Ÿ†Ž</th><th>๐Ÿ“›</th></tr></thead><tbody><tr><td><code>name</code></td><td><code>str</code></td><td><strong>๐Ÿšš</strong> (๐Ÿšฅ <code>license_info</code> โš’). ๐Ÿ›‚ ๐Ÿ“› โš™๏ธ ๐Ÿ› ๏ธ.</td></tr><tr><td><code>url</code></td><td><code>str</code></td><td>๐Ÿ“› ๐Ÿ›‚ โš™๏ธ ๐Ÿ› ๏ธ. ๐Ÿ”œ ๐Ÿ“ ๐Ÿ“›. </td></tr></tbody></table></details> |
๐Ÿ‘† ๐Ÿ’ช โš’ ๐Ÿ‘ซ โฉ:
```Python hl_lines="3-16 19-31"
{!../../../docs_src/metadata/tutorial001.py!}
```
!!! tip
๐Ÿ‘† ๐Ÿ’ช โœ โœ `description` ๐Ÿ‘ &amp; โšซ๏ธ ๐Ÿ”œ โœ ๐Ÿ”ข.
โฎ๏ธ ๐Ÿ‘‰ ๐Ÿ“ณ, ๐Ÿง ๐Ÿ› ๏ธ ๐Ÿฉบ ๐Ÿ”œ ๐Ÿ‘€ ๐Ÿ’–:
<img src="/img/tutorial/metadata/image01.png">
## ๐Ÿ—ƒ ๐Ÿ”–
๐Ÿ‘† ๐Ÿ’ช ๐Ÿšฎ ๐ŸŒ– ๐Ÿ—ƒ ๐ŸŽ ๐Ÿ”– โš™๏ธ ๐Ÿ‘ช ๐Ÿ‘† โžก ๐Ÿ› ๏ธ โฎ๏ธ ๐Ÿ”ข `openapi_tags`.
โšซ๏ธ โœŠ ๐Ÿ“‡ โš— 1๏ธโƒฃ ๐Ÿ“– ๐Ÿ”  ๐Ÿ”–.
๐Ÿ”  ๐Ÿ“– ๐Ÿ’ช ๐Ÿ”Œ:
* `name` (**โœ”**): `str` โฎ๏ธ ๐ŸŽ ๐Ÿ“› ๐Ÿ‘† โš™๏ธ `tags` ๐Ÿ”ข ๐Ÿ‘† *โžก ๐Ÿ› ๏ธ* &amp; `APIRouter`โ“‚.
* `description`: `str` โฎ๏ธ ๐Ÿ“ ๐Ÿ“› ๐Ÿ”–. โšซ๏ธ ๐Ÿ’ช โœ”๏ธ โœ &amp; ๐Ÿ”œ ๐ŸŽฆ ๐Ÿฉบ ๐ŸŽš.
* `externalDocs`: `dict` ๐Ÿ”ฌ ๐Ÿ”ข ๐Ÿงพ โฎ๏ธ:
* `description`: `str` โฎ๏ธ ๐Ÿ“ ๐Ÿ“› ๐Ÿ”ข ๐Ÿฉบ.
* `url` (**โœ”**): `str` โฎ๏ธ ๐Ÿ“› ๐Ÿ”ข ๐Ÿงพ.
### โœ ๐Ÿ—ƒ ๐Ÿ”–
โžก๏ธ ๐Ÿ”„ ๐Ÿ‘ˆ ๐Ÿ–ผ โฎ๏ธ ๐Ÿ”– `users` &amp; `items`.
โœ ๐Ÿ—ƒ ๐Ÿ‘† ๐Ÿ”– &amp; ๐Ÿšถโ€โ™€๏ธ โšซ๏ธ `openapi_tags` ๐Ÿ”ข:
```Python hl_lines="3-16 18"
{!../../../docs_src/metadata/tutorial004.py!}
```
๐Ÿ‘€ ๐Ÿ‘ˆ ๐Ÿ‘† ๐Ÿ’ช โš™๏ธ โœ ๐Ÿ”˜ ๐Ÿ“›, ๐Ÿ–ผ "๐Ÿ’ณ" ๐Ÿ”œ ๐ŸŽฆ ๐Ÿฆ (**๐Ÿ’ณ**) &amp; "๐ŸŽ€" ๐Ÿ”œ ๐ŸŽฆ โ• (_๐ŸŽ€_).
!!! tip
๐Ÿ‘† ๐Ÿšซ โœ”๏ธ ๐Ÿšฎ ๐Ÿ—ƒ ๐ŸŒ ๐Ÿ”– ๐Ÿ‘ˆ ๐Ÿ‘† โš™๏ธ.
### โš™๏ธ ๐Ÿ‘† ๐Ÿ”–
โš™๏ธ `tags` ๐Ÿ”ข โฎ๏ธ ๐Ÿ‘† *โžก ๐Ÿ› ๏ธ* (&amp; `APIRouter`โ“‚) ๐Ÿ› ๏ธ ๐Ÿ‘ซ ๐ŸŽ ๐Ÿ”–:
```Python hl_lines="21 26"
{!../../../docs_src/metadata/tutorial004.py!}
```
!!! info
โœ ๐ŸŒ… ๐Ÿ”ƒ ๐Ÿ”– [โžก ๐Ÿ› ๏ธ ๐Ÿ“ณ](../path-operation-configuration/#tags){.internal-link target=_blank}.
### โœ… ๐Ÿฉบ
๐Ÿ”œ, ๐Ÿšฅ ๐Ÿ‘† โœ… ๐Ÿฉบ, ๐Ÿ‘ซ ๐Ÿ”œ ๐ŸŽฆ ๐ŸŒ ๐ŸŒ– ๐Ÿ—ƒ:
<img src="/img/tutorial/metadata/image02.png">
### โœ” ๐Ÿ”–
โœ” ๐Ÿ”  ๐Ÿ”– ๐Ÿ—ƒ ๐Ÿ“– ๐Ÿ”ฌ โœ” ๐ŸŽฆ ๐Ÿฉบ ๐ŸŽš.
๐Ÿ–ผ, โœ‹๏ธ `users` ๐Ÿ”œ ๐Ÿšถ โฎ๏ธ `items` ๐Ÿ”ค โœ”, โšซ๏ธ ๐ŸŽฆ โญ ๐Ÿ‘ซ, โ†ฉ๏ธ ๐Ÿ‘ฅ ๐Ÿšฎ ๐Ÿ‘ซ ๐Ÿ—ƒ ๐Ÿฅ‡ ๐Ÿ“– ๐Ÿ“‡.
## ๐Ÿ—„ ๐Ÿ“›
๐Ÿ”ข, ๐Ÿ—„ ๐Ÿ”— ๐Ÿฆ `/openapi.json`.
โœ‹๏ธ ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ”— โšซ๏ธ โฎ๏ธ ๐Ÿ”ข `openapi_url`.
๐Ÿ–ผ, โš’ โšซ๏ธ ๐Ÿฆ `/api/v1/openapi.json`:
```Python hl_lines="3"
{!../../../docs_src/metadata/tutorial002.py!}
```
๐Ÿšฅ ๐Ÿ‘† ๐Ÿ’š โŽ ๐Ÿ—„ ๐Ÿ”— ๐Ÿ• ๐Ÿ‘† ๐Ÿ’ช โš’ `openapi_url=None`, ๐Ÿ‘ˆ ๐Ÿ”œ โŽ ๐Ÿงพ ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ”ข ๐Ÿ‘ˆ โš™๏ธ โšซ๏ธ.
## ๐Ÿฉบ ๐Ÿ“›
๐Ÿ‘† ๐Ÿ’ช ๐Ÿ”— 2๏ธโƒฃ ๐Ÿงพ ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ”ข ๐Ÿ”Œ:
* **๐Ÿฆ ๐ŸŽš**: ๐Ÿฆ `/docs`.
* ๐Ÿ‘† ๐Ÿ’ช โš’ ๐Ÿšฎ ๐Ÿ“› โฎ๏ธ ๐Ÿ”ข `docs_url`.
* ๐Ÿ‘† ๐Ÿ’ช โŽ โšซ๏ธ โš’ `docs_url=None`.
* **๐Ÿ“„**: ๐Ÿฆ `/redoc`.
* ๐Ÿ‘† ๐Ÿ’ช โš’ ๐Ÿšฎ ๐Ÿ“› โฎ๏ธ ๐Ÿ”ข `redoc_url`.
* ๐Ÿ‘† ๐Ÿ’ช โŽ โšซ๏ธ โš’ `redoc_url=None`.
๐Ÿ–ผ, โš’ ๐Ÿฆ ๐ŸŽš ๐Ÿฆ `/documentation` &amp; โŽ ๐Ÿ“„:
```Python hl_lines="3"
{!../../../docs_src/metadata/tutorial003.py!}
```

61
docs/em/docs/tutorial/middleware.md

@ -0,0 +1,61 @@
# ๐Ÿ› ๏ธ
๐Ÿ‘† ๐Ÿ’ช ๐Ÿšฎ ๐Ÿ› ๏ธ **FastAPI** ๐Ÿˆธ.
"๐Ÿ› ๏ธ" ๐Ÿ”ข ๐Ÿ‘ˆ ๐Ÿ‘ท โฎ๏ธ ๐Ÿ”  **๐Ÿ“จ** โญ โšซ๏ธ ๐Ÿ› ๏ธ ๐Ÿ™† ๐ŸŽฏ *โžก ๐Ÿ› ๏ธ*. &amp; โฎ๏ธ ๐Ÿ”  **๐Ÿ“จ** โญ ๐Ÿ›ฌ โšซ๏ธ.
* โšซ๏ธ โœŠ ๐Ÿ”  **๐Ÿ“จ** ๐Ÿ‘ˆ ๐Ÿ‘Ÿ ๐Ÿ‘† ๐Ÿˆธ.
* โšซ๏ธ ๐Ÿ’ช โคด๏ธ ๐Ÿ•ณ ๐Ÿ‘ˆ **๐Ÿ“จ** โš–๏ธ ๐Ÿƒ ๐Ÿ™† ๐Ÿ’ช ๐Ÿ“Ÿ.
* โคด๏ธ โšซ๏ธ ๐Ÿšถโ€โ™€๏ธ **๐Ÿ“จ** ๐Ÿ› ๏ธ ๐ŸŽ‚ ๐Ÿˆธ ( *โžก ๐Ÿ› ๏ธ*).
* โšซ๏ธ โคด๏ธ โœŠ **๐Ÿ“จ** ๐Ÿ— ๐Ÿˆธ ( *โžก ๐Ÿ› ๏ธ*).
* โšซ๏ธ ๐Ÿ’ช ๐Ÿ•ณ ๐Ÿ‘ˆ **๐Ÿ“จ** โš–๏ธ ๐Ÿƒ ๐Ÿ™† ๐Ÿ’ช ๐Ÿ“Ÿ.
* โคด๏ธ โšซ๏ธ ๐Ÿ“จ **๐Ÿ“จ**.
!!! note "๐Ÿ“ก โ„น"
๐Ÿšฅ ๐Ÿ‘† โœ”๏ธ ๐Ÿ”— โฎ๏ธ `yield`, ๐Ÿšช ๐Ÿ“Ÿ ๐Ÿ”œ ๐Ÿƒ *โฎ๏ธ* ๐Ÿ› ๏ธ.
๐Ÿšฅ ๐Ÿ“ค ๐Ÿ™† ๐Ÿ–ฅ ๐Ÿ“‹ (๐Ÿ“„ โช), ๐Ÿ‘ซ ๐Ÿ”œ ๐Ÿƒ *โฎ๏ธ* ๐ŸŒ ๐Ÿ› ๏ธ.
## โœ ๐Ÿ› ๏ธ
โœ ๐Ÿ› ๏ธ ๐Ÿ‘† โš™๏ธ ๐Ÿ‘จโ€๐ŸŽจ `@app.middleware("http")` ๐Ÿ”› ๐Ÿ” ๐Ÿ”ข.
๐Ÿ› ๏ธ ๐Ÿ”ข ๐Ÿ“จ:
* `request`.
* ๐Ÿ”ข `call_next` ๐Ÿ‘ˆ ๐Ÿ”œ ๐Ÿ“จ `request` ๐Ÿ”ข.
* ๐Ÿ‘‰ ๐Ÿ”ข ๐Ÿ”œ ๐Ÿšถโ€โ™€๏ธ `request` ๐Ÿ”— *โžก ๐Ÿ› ๏ธ*.
* โคด๏ธ โšซ๏ธ ๐Ÿ“จ `response` ๐Ÿ— ๐Ÿ”— *โžก ๐Ÿ› ๏ธ*.
* ๐Ÿ‘† ๐Ÿ’ช โคด๏ธ ๐Ÿ”€ ๐ŸŒ… `response` โญ ๐Ÿ›ฌ โšซ๏ธ.
```Python hl_lines="8-9 11 14"
{!../../../docs_src/middleware/tutorial001.py!}
```
!!! tip
โœ”๏ธ ๐Ÿคฏ ๐Ÿ‘ˆ ๐Ÿ›ƒ ยฉ ๐ŸŽš ๐Ÿ’ช ๐Ÿšฎ <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers" class="external-link" target="_blank">โš™๏ธ 'โœ–-' ๐Ÿ”ก</a>.
โœ‹๏ธ ๐Ÿšฅ ๐Ÿ‘† โœ”๏ธ ๐Ÿ›ƒ ๐ŸŽš ๐Ÿ‘ˆ ๐Ÿ‘† ๐Ÿ’š ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ–ฅ ๐Ÿ’ช ๐Ÿ‘€, ๐Ÿ‘† ๐Ÿ’ช ๐Ÿšฎ ๐Ÿ‘ซ ๐Ÿ‘† โšœ ๐Ÿ“ณ ([โšœ (โœ–๏ธ-๐Ÿ‡จ๐Ÿ‡ณ โ„น ๐Ÿค)](cors.md){.internal-link target=_blank}) โš™๏ธ ๐Ÿ”ข `expose_headers` ๐Ÿ“„ <a href="https://www.starlette.io/middleware/#corsmiddleware" class="external-link" target="_blank">๐Ÿ’ƒ โšœ ๐Ÿฉบ</a>.
!!! note "๐Ÿ“ก โ„น"
๐Ÿ‘† ๐Ÿ’ช โš™๏ธ `from starlette.requests import Request`.
**FastAPI** ๐Ÿšš โšซ๏ธ ๐Ÿช ๐Ÿ‘†, ๐Ÿ‘ฉโ€๐Ÿ’ป. โœ‹๏ธ โšซ๏ธ ๐Ÿ‘Ÿ ๐Ÿ”— โšช๏ธโžก๏ธ ๐Ÿ’ƒ.
### โญ &amp; โฎ๏ธ `response`
๐Ÿ‘† ๐Ÿ’ช ๐Ÿšฎ ๐Ÿ“Ÿ ๐Ÿƒ โฎ๏ธ `request`, โญ ๐Ÿ™† *โžก ๐Ÿ› ๏ธ* ๐Ÿ“จ โšซ๏ธ.
&amp; โฎ๏ธ `response` ๐Ÿ—, โญ ๐Ÿ›ฌ โšซ๏ธ.
๐Ÿ–ผ, ๐Ÿ‘† ๐Ÿ’ช ๐Ÿšฎ ๐Ÿ›ƒ ๐ŸŽš `X-Process-Time` โš— ๐Ÿ•ฐ ๐Ÿฅˆ ๐Ÿ‘ˆ โšซ๏ธ โœŠ ๐Ÿ› ๏ธ ๐Ÿ“จ &amp; ๐Ÿ— ๐Ÿ“จ:
```Python hl_lines="10 12-13"
{!../../../docs_src/middleware/tutorial001.py!}
```
## ๐ŸŽ ๐Ÿ› ๏ธ
๐Ÿ‘† ๐Ÿ’ช โช โœ ๐ŸŒ– ๐Ÿ”ƒ ๐ŸŽ ๐Ÿ› ๏ธ [๐Ÿง ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿฆฎ: ๐Ÿง ๐Ÿ› ๏ธ](../advanced/middleware.md){.internal-link target=_blank}.
๐Ÿ‘† ๐Ÿ”œ โœ ๐Ÿ”ƒ โ” ๐Ÿต <abbr title="Cross-Origin Resource Sharing">โšœ</abbr> โฎ๏ธ ๐Ÿ› ๏ธ โญ ๐Ÿ“„.

179
docs/em/docs/tutorial/path-operation-configuration.md

@ -0,0 +1,179 @@
# โžก ๐Ÿ› ๏ธ ๐Ÿ“ณ
๐Ÿ“ค ๐Ÿ“š ๐Ÿ”ข ๐Ÿ‘ˆ ๐Ÿ‘† ๐Ÿ’ช ๐Ÿšถโ€โ™€๏ธ ๐Ÿ‘† *โžก ๐Ÿ› ๏ธ ๐Ÿ‘จโ€๐ŸŽจ* ๐Ÿ”— โšซ๏ธ.
!!! warning
๐Ÿ‘€ ๐Ÿ‘ˆ ๐Ÿ‘ซ ๐Ÿ”ข ๐Ÿšถโ€โ™€๏ธ ๐Ÿ”— *โžก ๐Ÿ› ๏ธ ๐Ÿ‘จโ€๐ŸŽจ*, ๐Ÿšซ ๐Ÿ‘† *โžก ๐Ÿ› ๏ธ ๐Ÿ”ข*.
## ๐Ÿ“จ ๐Ÿ‘” ๐Ÿ“Ÿ
๐Ÿ‘† ๐Ÿ’ช ๐Ÿ”ฌ (๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ”) `status_code` โš™๏ธ ๐Ÿ“จ ๐Ÿ‘† *โžก ๐Ÿ› ๏ธ*.
๐Ÿ‘† ๐Ÿ’ช ๐Ÿšถโ€โ™€๏ธ ๐Ÿ”— `int` ๐Ÿ“Ÿ, ๐Ÿ’– `404`.
โœ‹๏ธ ๐Ÿšฅ ๐Ÿ‘† ๐Ÿšซ ๐Ÿ’ญ โšซ๏ธโ” ๐Ÿ”  ๐Ÿ”ข ๐Ÿ“Ÿ, ๐Ÿ‘† ๐Ÿ’ช โš™๏ธ โŒจ ๐Ÿ“‰ `status`:
=== "๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="3 17"
{!> ../../../docs_src/path_operation_configuration/tutorial001.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.9๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="3 17"
{!> ../../../docs_src/path_operation_configuration/tutorial001_py39.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.1๏ธโƒฃ0๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="1 15"
{!> ../../../docs_src/path_operation_configuration/tutorial001_py310.py!}
```
๐Ÿ‘ˆ ๐Ÿ‘” ๐Ÿ“Ÿ ๐Ÿ”œ โš™๏ธ ๐Ÿ“จ &amp; ๐Ÿ”œ ๐Ÿšฎ ๐Ÿ—„ ๐Ÿ”—.
!!! note "๐Ÿ“ก โ„น"
๐Ÿ‘† ๐Ÿ’ช โš™๏ธ `from starlette import status`.
**FastAPI** ๐Ÿšš ๐ŸŽ `starlette.status` `fastapi.status` ๐Ÿช ๐Ÿ‘†, ๐Ÿ‘ฉโ€๐Ÿ’ป. โœ‹๏ธ โšซ๏ธ ๐Ÿ‘Ÿ ๐Ÿ”— โšช๏ธโžก๏ธ ๐Ÿ’ƒ.
## ๐Ÿ”–
๐Ÿ‘† ๐Ÿ’ช ๐Ÿšฎ ๐Ÿ”– ๐Ÿ‘† *โžก ๐Ÿ› ๏ธ*, ๐Ÿšถโ€โ™€๏ธ ๐Ÿ”ข `tags` โฎ๏ธ `list` `str` (๐Ÿ›Ž 1๏ธโƒฃ `str`):
=== "๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="17 22 27"
{!> ../../../docs_src/path_operation_configuration/tutorial002.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.9๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="17 22 27"
{!> ../../../docs_src/path_operation_configuration/tutorial002_py39.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.1๏ธโƒฃ0๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="15 20 25"
{!> ../../../docs_src/path_operation_configuration/tutorial002_py310.py!}
```
๐Ÿ‘ซ ๐Ÿ”œ ๐Ÿšฎ ๐Ÿ—„ ๐Ÿ”— &amp; โš™๏ธ ๐Ÿง ๐Ÿงพ ๐Ÿ”ข:
<img src="/img/tutorial/path-operation-configuration/image01.png">
### ๐Ÿ”– โฎ๏ธ ๐Ÿ”ข
๐Ÿšฅ ๐Ÿ‘† โœ”๏ธ ๐Ÿฆ ๐Ÿˆธ, ๐Ÿ‘† 5๏ธโƒฃ๐Ÿ“† ๐Ÿ”š ๐Ÿ†™ ๐Ÿ“ˆ **๐Ÿ“š ๐Ÿ”–**, &amp; ๐Ÿ‘† ๐Ÿ”œ ๐Ÿ’š โš’ ๐Ÿ’ญ ๐Ÿ‘† ๐Ÿ•ง โš™๏ธ **๐ŸŽ ๐Ÿ”–** ๐Ÿ”— *โžก ๐Ÿ› ๏ธ*.
๐Ÿ‘ซ ๐Ÿ’ผ, โšซ๏ธ ๐Ÿ’ช โš’ ๐Ÿ”‘ ๐Ÿช ๐Ÿ”– `Enum`.
**FastAPI** ๐Ÿ•โ€๐Ÿฆบ ๐Ÿ‘ˆ ๐ŸŽ ๐ŸŒŒ โฎ๏ธ โœ… ๐ŸŽป:
```Python hl_lines="1 8-10 13 18"
{!../../../docs_src/path_operation_configuration/tutorial002b.py!}
```
## ๐Ÿ“„ &amp; ๐Ÿ“›
๐Ÿ‘† ๐Ÿ’ช ๐Ÿšฎ `summary` &amp; `description`:
=== "๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="20-21"
{!> ../../../docs_src/path_operation_configuration/tutorial003.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.9๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="20-21"
{!> ../../../docs_src/path_operation_configuration/tutorial003_py39.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.1๏ธโƒฃ0๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="18-19"
{!> ../../../docs_src/path_operation_configuration/tutorial003_py310.py!}
```
## ๐Ÿ“› โšช๏ธโžก๏ธ #๏ธโƒฃ
๐Ÿ“› ๐Ÿ˜‘ ๐Ÿ“ &amp; ๐Ÿ“” ๐Ÿ’— โธ, ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ“ฃ *โžก ๐Ÿ› ๏ธ* ๐Ÿ“› ๐Ÿ”ข <abbr title="a multi-line string as the first expression inside a function (not assigned to any variable) used for documentation"> #๏ธโƒฃ </abbr> &amp; **FastAPI** ๐Ÿ”œ โœ โšซ๏ธ โšช๏ธโžก๏ธ ๐Ÿ“ค.
๐Ÿ‘† ๐Ÿ’ช โœ <a href="https://en.wikipedia.org/wiki/Markdown" class="external-link" target="_blank">โœ</a> #๏ธโƒฃ , โšซ๏ธ ๐Ÿ”œ ๐Ÿ”ฌ &amp; ๐Ÿ–ฅ โ˜‘ (โœŠ ๐Ÿ”˜ ๐Ÿง #๏ธโƒฃ ๐Ÿ“).
=== "๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="19-27"
{!> ../../../docs_src/path_operation_configuration/tutorial004.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.9๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="19-27"
{!> ../../../docs_src/path_operation_configuration/tutorial004_py39.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.1๏ธโƒฃ0๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="17-25"
{!> ../../../docs_src/path_operation_configuration/tutorial004_py310.py!}
```
โšซ๏ธ ๐Ÿ”œ โš™๏ธ ๐ŸŽ“ ๐Ÿฉบ:
<img src="/img/tutorial/path-operation-configuration/image02.png">
## ๐Ÿ“จ ๐Ÿ“›
๐Ÿ‘† ๐Ÿ’ช โœ” ๐Ÿ“จ ๐Ÿ“› โฎ๏ธ ๐Ÿ”ข `response_description`:
=== "๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="21"
{!> ../../../docs_src/path_operation_configuration/tutorial005.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.9๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="21"
{!> ../../../docs_src/path_operation_configuration/tutorial005_py39.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.1๏ธโƒฃ0๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="19"
{!> ../../../docs_src/path_operation_configuration/tutorial005_py310.py!}
```
!!! info
๐Ÿ‘€ ๐Ÿ‘ˆ `response_description` ๐Ÿ”— ๐ŸŽฏ ๐Ÿ“จ, `description` ๐Ÿ”— *โžก ๐Ÿ› ๏ธ* ๐Ÿข.
!!! check
๐Ÿ—„ โœ” ๐Ÿ‘ˆ ๐Ÿ”  *โžก ๐Ÿ› ๏ธ* ๐Ÿšš ๐Ÿ“จ ๐Ÿ“›.
, ๐Ÿšฅ ๐Ÿ‘† ๐Ÿšซ ๐Ÿšš 1๏ธโƒฃ, **FastAPI** ๐Ÿ”œ ๐Ÿ” ๐Ÿ— 1๏ธโƒฃ "๐Ÿ† ๐Ÿ“จ".
<img src="/img/tutorial/path-operation-configuration/image03.png">
## ๐Ÿ˜ข *โžก ๐Ÿ› ๏ธ*
๐Ÿšฅ ๐Ÿ‘† ๐Ÿ’ช โ„ข *โžก ๐Ÿ› ๏ธ* <abbr title="obsolete, recommended not to use it">๐Ÿ˜ข</abbr>, โœ‹๏ธ ๐Ÿต โŽ โšซ๏ธ, ๐Ÿšถโ€โ™€๏ธ ๐Ÿ”ข `deprecated`:
```Python hl_lines="16"
{!../../../docs_src/path_operation_configuration/tutorial006.py!}
```
โšซ๏ธ ๐Ÿ”œ ๐ŸŽฏ โ„ข ๐Ÿ˜ข ๐ŸŽ“ ๐Ÿฉบ:
<img src="/img/tutorial/path-operation-configuration/image04.png">
โœ… โ” ๐Ÿ˜ข &amp; ๐Ÿšซ-๐Ÿ˜ข *โžก ๐Ÿ› ๏ธ* ๐Ÿ‘€ ๐Ÿ’–:
<img src="/img/tutorial/path-operation-configuration/image05.png">
## ๐ŸŒƒ
๐Ÿ‘† ๐Ÿ’ช ๐Ÿ”— &amp; ๐Ÿšฎ ๐Ÿ—ƒ ๐Ÿ‘† *โžก ๐Ÿ› ๏ธ* ๐Ÿ’ช ๐Ÿšถโ€โ™€๏ธ ๐Ÿ”ข *โžก ๐Ÿ› ๏ธ ๐Ÿ‘จโ€๐ŸŽจ*.

138
docs/em/docs/tutorial/path-params-numeric-validations.md

@ -0,0 +1,138 @@
# โžก ๐Ÿ”ข &amp; ๐Ÿ”ข ๐Ÿ”ฌ
๐ŸŽ ๐ŸŒŒ ๐Ÿ‘ˆ ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ“ฃ ๐ŸŒ… ๐Ÿ”ฌ &amp; ๐Ÿ—ƒ ๐Ÿ”ข ๐Ÿ”ข โฎ๏ธ `Query`, ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ“ฃ ๐ŸŽ ๐Ÿ†Ž ๐Ÿ”ฌ &amp; ๐Ÿ—ƒ โžก ๐Ÿ”ข โฎ๏ธ `Path`.
## ๐Ÿ—„ โžก
๐Ÿฅ‡, ๐Ÿ—„ `Path` โšช๏ธโžก๏ธ `fastapi`:
=== "๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="3"
{!> ../../../docs_src/path_params_numeric_validations/tutorial001.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.1๏ธโƒฃ0๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="1"
{!> ../../../docs_src/path_params_numeric_validations/tutorial001_py310.py!}
```
## ๐Ÿ“ฃ ๐Ÿ—ƒ
๐Ÿ‘† ๐Ÿ’ช ๐Ÿ“ฃ ๐ŸŒ ๐ŸŽ ๐Ÿ”ข `Query`.
๐Ÿ–ผ, ๐Ÿ“ฃ `title` ๐Ÿ—ƒ ๐Ÿ’ฒ โžก ๐Ÿ”ข `item_id` ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ†Ž:
=== "๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="10"
{!> ../../../docs_src/path_params_numeric_validations/tutorial001.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.1๏ธโƒฃ0๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="8"
{!> ../../../docs_src/path_params_numeric_validations/tutorial001_py310.py!}
```
!!! note
โžก ๐Ÿ”ข ๐Ÿ•ง โœ” โšซ๏ธ โœ”๏ธ ๐Ÿ• โžก.
, ๐Ÿ‘† ๐Ÿ”œ ๐Ÿ“ฃ โšซ๏ธ โฎ๏ธ `...` โ„ข โšซ๏ธ โœ”.
๐Ÿ‘, ๐Ÿšฅ ๐Ÿ‘† ๐Ÿ“ฃ โšซ๏ธ โฎ๏ธ `None` โš–๏ธ โš’ ๐Ÿ”ข ๐Ÿ’ฒ, โšซ๏ธ ๐Ÿ”œ ๐Ÿšซ ๐Ÿ“‰ ๐Ÿ•ณ, โšซ๏ธ ๐Ÿ”œ ๐Ÿ•ง ๐Ÿšš.
## โœ” ๐Ÿ”ข ๐Ÿ‘† ๐Ÿ’ช
โžก๏ธ ๐Ÿ’ฌ ๐Ÿ‘ˆ ๐Ÿ‘† ๐Ÿ’š ๐Ÿ“ฃ ๐Ÿ”ข ๐Ÿ”ข `q` โœ” `str`.
&amp; ๐Ÿ‘† ๐Ÿšซ ๐Ÿ’ช ๐Ÿ“ฃ ๐Ÿ•ณ ๐Ÿ™† ๐Ÿ‘ˆ ๐Ÿ”ข, ๐Ÿ‘† ๐Ÿšซ ๐Ÿค™ ๐Ÿ’ช โš™๏ธ `Query`.
โœ‹๏ธ ๐Ÿ‘† ๐Ÿ’ช โš™๏ธ `Path` `item_id` โžก ๐Ÿ”ข.
๐Ÿ ๐Ÿ”œ ๐Ÿ˜ญ ๐Ÿšฅ ๐Ÿ‘† ๐Ÿšฎ ๐Ÿ’ฒ โฎ๏ธ "๐Ÿ”ข" โญ ๐Ÿ’ฒ ๐Ÿ‘ˆ ๐Ÿšซ โœ”๏ธ "๐Ÿ”ข".
โœ‹๏ธ ๐Ÿ‘† ๐Ÿ’ช ๐Ÿค-โœ” ๐Ÿ‘ซ, &amp; โœ”๏ธ ๐Ÿ’ฒ ๐Ÿต ๐Ÿ”ข (๐Ÿ”ข ๐Ÿ”ข `q`) ๐Ÿฅ‡.
โšซ๏ธ ๐Ÿšซ ๐Ÿค” **FastAPI**. โšซ๏ธ ๐Ÿ”œ ๐Ÿ” ๐Ÿ”ข ๐Ÿ‘ซ ๐Ÿ“›, ๐Ÿ†Ž &amp; ๐Ÿ”ข ๐Ÿ“„ (`Query`, `Path`, โ™’๏ธ), โšซ๏ธ ๐Ÿšซ ๐Ÿ’… ๐Ÿ”ƒ โœ”.
, ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ“ฃ ๐Ÿ‘† ๐Ÿ”ข:
```Python hl_lines="7"
{!../../../docs_src/path_params_numeric_validations/tutorial002.py!}
```
## โœ” ๐Ÿ”ข ๐Ÿ‘† ๐Ÿ’ช, ๐ŸŽฑ
๐Ÿšฅ ๐Ÿ‘† ๐Ÿ’š ๐Ÿ“ฃ `q` ๐Ÿ”ข ๐Ÿ”ข ๐Ÿต `Query` ๐Ÿšซ ๐Ÿ™† ๐Ÿ”ข ๐Ÿ’ฒ, &amp; โžก ๐Ÿ”ข `item_id` โš™๏ธ `Path`, &amp; โœ”๏ธ ๐Ÿ‘ซ ๐ŸŽ โœ”, ๐Ÿ โœ”๏ธ ๐Ÿฅ ๐ŸŽ โ• ๐Ÿ‘ˆ.
๐Ÿšถโ€โ™€๏ธ `*`, ๐Ÿฅ‡ ๐Ÿ”ข ๐Ÿ”ข.
๐Ÿ ๐Ÿ† ๐Ÿšซ ๐Ÿ•ณ โฎ๏ธ ๐Ÿ‘ˆ `*`, โœ‹๏ธ โšซ๏ธ ๐Ÿ”œ ๐Ÿ’ญ ๐Ÿ‘ˆ ๐ŸŒ ๐Ÿ“„ ๐Ÿ”ข ๐Ÿ”œ ๐Ÿค™ ๐Ÿ‡จ๐Ÿ‡ป โŒ (๐Ÿ”‘-๐Ÿ’ฒ ๐Ÿ‘ซ), ๐Ÿ’ญ <abbr title="From: K-ey W-ord Arg-uments"><code>kwargs</code></abbr>. ๐Ÿšฅ ๐Ÿ‘ซ ๐Ÿšซ โœ”๏ธ ๐Ÿ”ข ๐Ÿ’ฒ.
```Python hl_lines="7"
{!../../../docs_src/path_params_numeric_validations/tutorial003.py!}
```
## ๐Ÿ”ข ๐Ÿ”ฌ: ๐Ÿ‘‘ ๐ŸŒ˜ โš–๏ธ ๐ŸŒ“
โฎ๏ธ `Query` &amp; `Path` (&amp; ๐ŸŽ ๐Ÿ‘† ๐Ÿ”œ ๐Ÿ‘€ โช) ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ“ฃ ๐Ÿ”ข โš›.
๐Ÿ“ฅ, โฎ๏ธ `ge=1`, `item_id` ๐Ÿ”œ ๐Ÿ’ช ๐Ÿ”ข ๐Ÿ”ข "`g`๐Ÿ…พ ๐ŸŒ˜ โš–๏ธ `e`๐Ÿ…พ" `1`.
```Python hl_lines="8"
{!../../../docs_src/path_params_numeric_validations/tutorial004.py!}
```
## ๐Ÿ”ข ๐Ÿ”ฌ: ๐ŸŒ˜ ๐ŸŒ˜ &amp; ๐ŸŒ˜ ๐ŸŒ˜ โš–๏ธ ๐ŸŒ“
๐ŸŽ โœ”:
* `gt`: `g`๐Ÿ…พ `t`๐Ÿ‘ฒ
* `le`: `l`๐Ÿ‘ญ ๐ŸŒ˜ โš–๏ธ `e`๐Ÿ…พ
```Python hl_lines="9"
{!../../../docs_src/path_params_numeric_validations/tutorial005.py!}
```
## ๐Ÿ”ข ๐Ÿ”ฌ: ๐ŸŽˆ, ๐ŸŒ˜ ๐ŸŒ˜ &amp; ๐ŸŒ˜ ๐ŸŒ˜
๐Ÿ”ข ๐Ÿ”ฌ ๐Ÿ‘ท `float` ๐Ÿ’ฒ.
๐Ÿ“ฅ ๐ŸŒโ” โšซ๏ธ โ–ถ๏ธ๏ธ โš  ๐Ÿ’ช ๐Ÿ“ฃ <abbr title="greater than"><code>gt</code></abbr> &amp; ๐Ÿšซ <abbr title="greater than or equal"><code>ge</code></abbr>. โฎ๏ธ โšซ๏ธ ๐Ÿ‘† ๐Ÿ’ช ๐Ÿšš, ๐Ÿ–ผ, ๐Ÿ‘ˆ ๐Ÿ’ฒ ๐Ÿ”œ ๐Ÿ‘‘ ๐ŸŒ˜ `0`, ๐Ÿšฅ โšซ๏ธ ๐ŸŒ˜ ๐ŸŒ˜ `1`.
, `0.5` ๐Ÿ”œ โ˜‘ ๐Ÿ’ฒ. โœ‹๏ธ `0.0` โš–๏ธ `0` ๐Ÿ”œ ๐Ÿšซ.
&amp; ๐ŸŽ <abbr title="less than"><code>lt</code></abbr>.
```Python hl_lines="11"
{!../../../docs_src/path_params_numeric_validations/tutorial006.py!}
```
## ๐ŸŒƒ
โฎ๏ธ `Query`, `Path` (&amp; ๐ŸŽ ๐Ÿ‘† ๐Ÿšซ ๐Ÿ‘€) ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ“ฃ ๐Ÿ—ƒ &amp; ๐ŸŽป ๐Ÿ”ฌ ๐ŸŽ ๐ŸŒŒ โฎ๏ธ [๐Ÿ”ข ๐Ÿ”ข &amp; ๐ŸŽป ๐Ÿ”ฌ](query-params-str-validations.md){.internal-link target=_blank}.
&amp; ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ“ฃ ๐Ÿ”ข ๐Ÿ”ฌ:
* `gt`: `g`๐Ÿ…พ `t`๐Ÿ‘ฒ
* `ge`: `g`๐Ÿ…พ ๐ŸŒ˜ โš–๏ธ `e`๐Ÿ…พ
* `lt`: `l`๐Ÿ‘ญ `t`๐Ÿ‘ฒ
* `le`: `l`๐Ÿ‘ญ ๐ŸŒ˜ โš–๏ธ `e`๐Ÿ…พ
!!! info
`Query`, `Path`, &amp; ๐ŸŽ ๐ŸŽ“ ๐Ÿ‘† ๐Ÿ”œ ๐Ÿ‘€ โช ๐Ÿฟ โš  `Param` ๐ŸŽ“.
๐ŸŒ ๐Ÿ‘ซ ๐Ÿ’ฐ ๐ŸŽ ๐Ÿ”ข ๐ŸŒ– ๐Ÿ”ฌ &amp; ๐Ÿ—ƒ ๐Ÿ‘† โœ”๏ธ ๐Ÿ‘€.
!!! note "๐Ÿ“ก โ„น"
๐Ÿ•โ” ๐Ÿ‘† ๐Ÿ—„ `Query`, `Path` &amp; ๐ŸŽ โšช๏ธโžก๏ธ `fastapi`, ๐Ÿ‘ซ ๐Ÿค™ ๐Ÿ”ข.
๐Ÿ‘ˆ ๐Ÿ•โ” ๐Ÿค™, ๐Ÿ“จ ๐Ÿ‘ ๐ŸŽ“ ๐ŸŽ ๐Ÿ“›.
, ๐Ÿ‘† ๐Ÿ—„ `Query`, โ” ๐Ÿ”ข. &amp; ๐Ÿ•โ” ๐Ÿ‘† ๐Ÿค™ โšซ๏ธ, โšซ๏ธ ๐Ÿ“จ ๐Ÿ‘ ๐ŸŽ“ ๐ŸŒŸ `Query`.
๐Ÿ‘ซ ๐Ÿ”ข ๐Ÿ“ค (โ†ฉ๏ธ โš™๏ธ ๐ŸŽ“ ๐Ÿ”—) ๐Ÿ‘ˆ ๐Ÿ‘† ๐Ÿ‘จโ€๐ŸŽจ ๐Ÿšซ โ„ข โŒ ๐Ÿ”ƒ ๐Ÿ‘ซ ๐Ÿ†Ž.
๐Ÿ‘ˆ ๐ŸŒŒ ๐Ÿ‘† ๐Ÿ’ช โš™๏ธ ๐Ÿ‘† ๐Ÿ˜ ๐Ÿ‘จโ€๐ŸŽจ &amp; ๐Ÿ› ๏ธ ๐Ÿงฐ ๐Ÿต โœ”๏ธ ๐Ÿšฎ ๐Ÿ›ƒ ๐Ÿ“ณ ๐Ÿคทโ€โ™‚ ๐Ÿ“š โŒ.

252
docs/em/docs/tutorial/path-params.md

@ -0,0 +1,252 @@
# โžก ๐Ÿ”ข
๐Ÿ‘† ๐Ÿ’ช ๐Ÿ“ฃ โžก "๐Ÿ”ข" โš–๏ธ "๐Ÿ”ข" โฎ๏ธ ๐ŸŽ โ• โš™๏ธ ๐Ÿ ๐Ÿ“ ๐ŸŽป:
```Python hl_lines="6-7"
{!../../../docs_src/path_params/tutorial001.py!}
```
๐Ÿ’ฒ โžก ๐Ÿ”ข `item_id` ๐Ÿ”œ ๐Ÿšถโ€โ™€๏ธ ๐Ÿ‘† ๐Ÿ”ข โŒ `item_id`.
, ๐Ÿšฅ ๐Ÿ‘† ๐Ÿƒ ๐Ÿ‘‰ ๐Ÿ–ผ &amp; ๐Ÿšถ <a href="http://127.0.0.1:8000/items/foo" class="external-link" target="_blank">http://127.0.0.1:8000/items/foo</a>, ๐Ÿ‘† ๐Ÿ”œ ๐Ÿ‘€ ๐Ÿ“จ:
```JSON
{"item_id":"foo"}
```
## โžก ๐Ÿ”ข โฎ๏ธ ๐Ÿ†Ž
๐Ÿ‘† ๐Ÿ’ช ๐Ÿ“ฃ ๐Ÿ†Ž โžก ๐Ÿ”ข ๐Ÿ”ข, โš™๏ธ ๐Ÿฉ ๐Ÿ ๐Ÿ†Ž โœ:
```Python hl_lines="7"
{!../../../docs_src/path_params/tutorial002.py!}
```
๐Ÿ‘‰ ๐Ÿ’ผ, `item_id` ๐Ÿ“ฃ `int`.
!!! check
๐Ÿ‘‰ ๐Ÿ”œ ๐Ÿค ๐Ÿ‘† ๐Ÿ‘จโ€๐ŸŽจ ๐Ÿ•โ€๐Ÿฆบ ๐Ÿ”˜ ๐Ÿ‘† ๐Ÿ”ข, โฎ๏ธ โŒ โœ…, ๐Ÿ› ๏ธ, โ™’๏ธ.
## ๐Ÿ’ฝ <abbr title="also known as: serialization, parsing, marshalling">๐Ÿ› ๏ธ</abbr>
๐Ÿšฅ ๐Ÿ‘† ๐Ÿƒ ๐Ÿ‘‰ ๐Ÿ–ผ &amp; ๐Ÿ“‚ ๐Ÿ‘† ๐Ÿ–ฅ <a href="http://127.0.0.1:8000/items/3" class="external-link" target="_blank">http://127.0.0.1:8000/items/3</a>, ๐Ÿ‘† ๐Ÿ”œ ๐Ÿ‘€ ๐Ÿ“จ:
```JSON
{"item_id":3}
```
!!! check
๐Ÿ‘€ ๐Ÿ‘ˆ ๐Ÿ’ฒ ๐Ÿ‘† ๐Ÿ”ข ๐Ÿ“จ (&amp; ๐Ÿ“จ) `3`, ๐Ÿ `int`, ๐Ÿšซ ๐ŸŽป `"3"`.
, โฎ๏ธ ๐Ÿ‘ˆ ๐Ÿ†Ž ๐Ÿ“„, **FastAPI** ๐Ÿค ๐Ÿ‘† ๐Ÿง ๐Ÿ“จ <abbr title="converting the string that comes from an HTTP request into Python data">"โœ"</abbr>.
## ๐Ÿ’ฝ ๐Ÿ”ฌ
โœ‹๏ธ ๐Ÿšฅ ๐Ÿ‘† ๐Ÿšถ ๐Ÿ–ฅ <a href="http://127.0.0.1:8000/items/foo" class="external-link" target="_blank">http://127.0.0.1:8000/items/foo</a>, ๐Ÿ‘† ๐Ÿ”œ ๐Ÿ‘€ ๐Ÿ‘Œ ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ” โŒ:
```JSON
{
"detail": [
{
"loc": [
"path",
"item_id"
],
"msg": "value is not a valid integer",
"type": "type_error.integer"
}
]
}
```
โ†ฉ๏ธ โžก ๐Ÿ”ข `item_id` โœ”๏ธ ๐Ÿ’ฒ `"foo"`, โ” ๐Ÿšซ `int`.
๐ŸŽ โŒ ๐Ÿ”œ ๐Ÿ˜‘ ๐Ÿšฅ ๐Ÿ‘† ๐Ÿšš `float` โ†ฉ๏ธ `int`,: <a href="http://127.0.0.1:8000/items/4.2" class="external-link" target="_blank">http://127.0.0.1:8000/items/4.2</a>
!!! check
, โฎ๏ธ ๐ŸŽ ๐Ÿ ๐Ÿ†Ž ๐Ÿ“„, **FastAPI** ๐Ÿค ๐Ÿ‘† ๐Ÿ’ฝ ๐Ÿ”ฌ.
๐Ÿ‘€ ๐Ÿ‘ˆ โŒ ๐ŸŽฏ ๐Ÿ‡ต๐Ÿ‡ธ โšซ๏ธโ” โ˜ ๐ŸŒโ” ๐Ÿ”ฌ ๐Ÿšซ ๐Ÿšถโ€โ™€๏ธ.
๐Ÿ‘‰ ๐Ÿ™ƒ ๐Ÿ‘ โช ๐Ÿ› ๏ธ &amp; ๐Ÿ› ๏ธ ๐Ÿ“Ÿ ๐Ÿ‘ˆ ๐Ÿ”— โฎ๏ธ ๐Ÿ‘† ๐Ÿ› ๏ธ.
## ๐Ÿงพ
&amp; ๐Ÿ•โ” ๐Ÿ‘† ๐Ÿ“‚ ๐Ÿ‘† ๐Ÿ–ฅ <a href="http://127.0.0.1:8000/docs" class="external-link" target="_blank">http://127.0.0.1:8000/docs</a>, ๐Ÿ‘† ๐Ÿ”œ ๐Ÿ‘€ ๐Ÿง, ๐ŸŽ“, ๐Ÿ› ๏ธ ๐Ÿงพ ๐Ÿ’–:
<img src="/img/tutorial/path-params/image01.png">
!!! check
๐Ÿ”„, โฎ๏ธ ๐Ÿ‘ˆ ๐ŸŽ ๐Ÿ ๐Ÿ†Ž ๐Ÿ“„, **FastAPI** ๐Ÿค ๐Ÿ‘† ๐Ÿง, ๐ŸŽ“ ๐Ÿงพ (๐Ÿ› ๏ธ ๐Ÿฆ ๐ŸŽš).
๐Ÿ‘€ ๐Ÿ‘ˆ โžก ๐Ÿ”ข ๐Ÿ“ฃ ๐Ÿ”ข.
## ๐Ÿฉ-โš“๏ธ ๐Ÿ’ฐ, ๐ŸŽ› ๐Ÿงพ
&amp; โ†ฉ๏ธ ๐Ÿ— ๐Ÿ”— โšช๏ธโžก๏ธ <a href="https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md" class="external-link" target="_blank">๐Ÿ—„</a> ๐Ÿฉ, ๐Ÿ“ค ๐Ÿ“š ๐Ÿ”— ๐Ÿงฐ.
โ†ฉ๏ธ ๐Ÿ‘‰, **FastAPI** โšซ๏ธ ๐Ÿšš ๐ŸŽ› ๐Ÿ› ๏ธ ๐Ÿงพ (โš™๏ธ ๐Ÿ“„), โ” ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ” <a href="http://127.0.0.1:8000/redoc" class="external-link" target="_blank">http://127.0.0.1:8000/redoc</a>:
<img src="/img/tutorial/path-params/image02.png">
๐ŸŽ ๐ŸŒŒ, ๐Ÿ“ค ๐Ÿ“š ๐Ÿ”— ๐Ÿงฐ. โœ… ๐Ÿ“Ÿ โšก ๐Ÿงฐ ๐Ÿ“š ๐Ÿ‡ช๐Ÿ‡ธ.
## Pydantic
๐ŸŒ ๐Ÿ’ฝ ๐Ÿ”ฌ ๐ŸŽญ ๐Ÿ”ฝ ๐Ÿš˜ <a href="https://pydantic-docs.helpmanual.io/" class="external-link" target="_blank">Pydantic</a>, ๐Ÿ‘† ๐Ÿคš ๐ŸŒ ๐Ÿ’ฐ โšช๏ธโžก๏ธ โšซ๏ธ. &amp; ๐Ÿ‘† ๐Ÿ’ญ ๐Ÿ‘† ๐Ÿ‘ โœ‹.
๐Ÿ‘† ๐Ÿ’ช โš™๏ธ ๐ŸŽ ๐Ÿ†Ž ๐Ÿ“„ โฎ๏ธ `str`, `float`, `bool` &amp; ๐Ÿ“š ๐ŸŽ ๐Ÿ— ๐Ÿ“Š ๐Ÿ†Ž.
๐Ÿ“š ๐Ÿ‘ซ ๐Ÿ”ฌ โญ ๐Ÿ“ƒ ๐Ÿ”ฐ.
## โœ” ๐Ÿค”
๐Ÿ•โ” ๐Ÿ— *โžก ๐Ÿ› ๏ธ*, ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ”Ž โš  ๐ŸŒโ” ๐Ÿ‘† โœ”๏ธ ๐Ÿ”ง โžก.
๐Ÿ’– `/users/me`, โžก๏ธ ๐Ÿ’ฌ ๐Ÿ‘ˆ โšซ๏ธ ๐Ÿคš ๐Ÿ“Š ๐Ÿ”ƒ โฎ๏ธ ๐Ÿ‘ฉโ€๐Ÿ’ป.
&amp; โคด๏ธ ๐Ÿ‘† ๐Ÿ’ช โœ”๏ธ โžก `/users/{user_id}` ๐Ÿคš ๐Ÿ’ฝ ๐Ÿ”ƒ ๐ŸŽฏ ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ†”.
โ†ฉ๏ธ *โžก ๐Ÿ› ๏ธ* ๐Ÿ”ฌ โœ”, ๐Ÿ‘† ๐Ÿ’ช โš’ ๐Ÿ’ญ ๐Ÿ‘ˆ โžก `/users/me` ๐Ÿ“ฃ โญ 1๏ธโƒฃ `/users/{user_id}`:
```Python hl_lines="6 11"
{!../../../docs_src/path_params/tutorial003.py!}
```
โช, โžก `/users/{user_id}` ๐Ÿ”œ ๐Ÿ `/users/me`, "๐Ÿ’ญ" ๐Ÿ‘ˆ โšซ๏ธ ๐Ÿ“จ ๐Ÿ”ข `user_id` โฎ๏ธ ๐Ÿ’ฒ `"me"`.
โžก, ๐Ÿ‘† ๐Ÿšซ๐Ÿ”œ โ†” โžก ๐Ÿ› ๏ธ:
```Python hl_lines="6 11"
{!../../../docs_src/path_params/tutorial003b.py!}
```
๐Ÿฅ‡ ๐Ÿ• ๐Ÿ”œ ๐Ÿ•ง โš™๏ธ โ†ฉ๏ธ โžก ๐Ÿ ๐Ÿฅ‡.
## ๐Ÿ” ๐Ÿ’ฒ
๐Ÿšฅ ๐Ÿ‘† โœ”๏ธ *โžก ๐Ÿ› ๏ธ* ๐Ÿ‘ˆ ๐Ÿ“จ *โžก ๐Ÿ”ข*, โœ‹๏ธ ๐Ÿ‘† ๐Ÿ’š ๐Ÿ’ช โ˜‘ *โžก ๐Ÿ”ข* ๐Ÿ’ฒ ๐Ÿ”, ๐Ÿ‘† ๐Ÿ’ช โš™๏ธ ๐Ÿฉ ๐Ÿ <abbr title="Enumeration">`Enum`</abbr>.
### โœ `Enum` ๐ŸŽ“
๐Ÿ—„ `Enum` &amp; โœ ๐ŸŽง-๐ŸŽ“ ๐Ÿ‘ˆ ๐Ÿ˜– โšช๏ธโžก๏ธ `str` &amp; โšช๏ธโžก๏ธ `Enum`.
๐Ÿ˜– โšช๏ธโžก๏ธ `str` ๐Ÿ› ๏ธ ๐Ÿฉบ ๐Ÿ”œ ๐Ÿ’ช ๐Ÿ’ญ ๐Ÿ‘ˆ ๐Ÿ’ฒ ๐Ÿ”œ ๐Ÿ†Ž `string` &amp; ๐Ÿ”œ ๐Ÿ’ช โœ โ˜‘.
โคด๏ธ โœ ๐ŸŽ“ ๐Ÿ”ข โฎ๏ธ ๐Ÿ”ง ๐Ÿ’ฒ, โ” ๐Ÿ”œ ๐Ÿ’ช โ˜‘ ๐Ÿ’ฒ:
```Python hl_lines="1 6-9"
{!../../../docs_src/path_params/tutorial005.py!}
```
!!! info
<a href="https://docs.python.org/3/library/enum.html" class="external-link" target="_blank">๐Ÿ”ข (โš–๏ธ ๐Ÿ”ข) ๐Ÿ’ช ๐Ÿ</a> โ†ฉ๏ธ โฌ 3๏ธโƒฃ.4๏ธโƒฃ.
!!! tip
๐Ÿšฅ ๐Ÿ‘† ๐Ÿ’ญ, "๐Ÿ“Š", "๐ŸŽ“", &amp; "๐Ÿ" ๐Ÿ“› ๐ŸŽฐ ๐Ÿซ <abbr title="Technically, Deep Learning model architectures">๐Ÿท</abbr>.
### ๐Ÿ“ฃ *โžก ๐Ÿ”ข*
โคด๏ธ โœ *โžก ๐Ÿ”ข* โฎ๏ธ ๐Ÿ†Ž โœ โš™๏ธ ๐Ÿ”ข ๐ŸŽ“ ๐Ÿ‘† โœ (`ModelName`):
```Python hl_lines="16"
{!../../../docs_src/path_params/tutorial005.py!}
```
### โœ… ๐Ÿฉบ
โ†ฉ๏ธ ๐Ÿ’ช ๐Ÿ’ฒ *โžก ๐Ÿ”ข* ๐Ÿ”ข, ๐ŸŽ“ ๐Ÿฉบ ๐Ÿ’ช ๐ŸŽฆ ๐Ÿ‘ซ ๐ŸŽ†:
<img src="/img/tutorial/path-params/image03.png">
### ๐Ÿ‘ท โฎ๏ธ ๐Ÿ *๐Ÿ”ข*
๐Ÿ’ฒ *โžก ๐Ÿ”ข* ๐Ÿ”œ *๐Ÿ”ข ๐Ÿ‘จโ€๐ŸŽ“*.
#### ๐Ÿ”ฌ *๐Ÿ”ข ๐Ÿ‘จโ€๐ŸŽ“*
๐Ÿ‘† ๐Ÿ’ช ๐Ÿ”ฌ โšซ๏ธ โฎ๏ธ *๐Ÿ”ข ๐Ÿ‘จโ€๐ŸŽ“* ๐Ÿ‘† โœ ๐Ÿ”ข `ModelName`:
```Python hl_lines="17"
{!../../../docs_src/path_params/tutorial005.py!}
```
#### ๐Ÿคš *๐Ÿ”ข ๐Ÿ’ฒ*
๐Ÿ‘† ๐Ÿ’ช ๐Ÿคš โ˜‘ ๐Ÿ’ฒ ( `str` ๐Ÿ‘‰ ๐Ÿ’ผ) โš™๏ธ `model_name.value`, โš–๏ธ ๐Ÿข, `your_enum_member.value`:
```Python hl_lines="20"
{!../../../docs_src/path_params/tutorial005.py!}
```
!!! tip
๐Ÿ‘† ๐Ÿ’ช ๐Ÿ” ๐Ÿ’ฒ `"lenet"` โฎ๏ธ `ModelName.lenet.value`.
#### ๐Ÿ“จ *๐Ÿ”ข ๐Ÿ‘จโ€๐ŸŽ“*
๐Ÿ‘† ๐Ÿ’ช ๐Ÿ“จ *๐Ÿ”ข ๐Ÿ‘จโ€๐ŸŽ“* โšช๏ธโžก๏ธ ๐Ÿ‘† *โžก ๐Ÿ› ๏ธ*, ๐Ÿฆ ๐ŸŽป ๐Ÿ’ช (โœ… `dict`).
๐Ÿ‘ซ ๐Ÿ”œ ๐Ÿ—œ ๐Ÿ‘ซ ๐Ÿ”— ๐Ÿ’ฒ (๐ŸŽป ๐Ÿ‘‰ ๐Ÿ’ผ) โญ ๐Ÿ›ฌ ๐Ÿ‘ซ ๐Ÿ‘ฉโ€๐Ÿ’ป:
```Python hl_lines="18 21 23"
{!../../../docs_src/path_params/tutorial005.py!}
```
๐Ÿ‘† ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ‘† ๐Ÿ”œ ๐Ÿคš ๐ŸŽป ๐Ÿ“จ ๐Ÿ’–:
```JSON
{
"model_name": "alexnet",
"message": "Deep Learning FTW!"
}
```
## โžก ๐Ÿ”ข โš— โžก
โžก๏ธ ๐Ÿ’ฌ ๐Ÿ‘† โœ”๏ธ *โžก ๐Ÿ› ๏ธ* โฎ๏ธ โžก `/files/{file_path}`.
โœ‹๏ธ ๐Ÿ‘† ๐Ÿ’ช `file_path` โšซ๏ธ ๐Ÿ”Œ *โžก*, ๐Ÿ’– `home/johndoe/myfile.txt`.
, ๐Ÿ“› ๐Ÿ‘ˆ ๐Ÿ“ ๐Ÿ”œ ๐Ÿ•ณ ๐Ÿ’–: `/files/home/johndoe/myfile.txt`.
### ๐Ÿ—„ ๐Ÿ•โ€๐Ÿฆบ
๐Ÿ—„ ๐Ÿšซ ๐Ÿ•โ€๐Ÿฆบ ๐ŸŒŒ ๐Ÿ“ฃ *โžก ๐Ÿ”ข* ๐Ÿ”Œ *โžก* ๐Ÿ”˜, ๐Ÿ‘ˆ ๐Ÿ’ช โ†˜๏ธ ๐Ÿ˜ ๐Ÿ‘ˆ โš  ๐Ÿ’ฏ &amp; ๐Ÿ”ฌ.
๐Ÿ‘, ๐Ÿ‘† ๐Ÿ’ช โšซ๏ธ **FastAPI**, โš™๏ธ 1๏ธโƒฃ ๐Ÿ”— ๐Ÿงฐ โšช๏ธโžก๏ธ ๐Ÿ’ƒ.
&amp; ๐Ÿฉบ ๐Ÿ”œ ๐Ÿ‘ท, ๐Ÿ‘ ๐Ÿšซ โŽ ๐Ÿ™† ๐Ÿงพ ๐Ÿ’ฌ ๐Ÿ‘ˆ ๐Ÿ”ข ๐Ÿ”œ ๐Ÿ”Œ โžก.
### โžก ๐Ÿ”Œ
โš™๏ธ ๐ŸŽ› ๐Ÿ”— โšช๏ธโžก๏ธ ๐Ÿ’ƒ ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ“ฃ *โžก ๐Ÿ”ข* โš— *โžก* โš™๏ธ ๐Ÿ“› ๐Ÿ’–:
```
/files/{file_path:path}
```
๐Ÿ‘‰ ๐Ÿ’ผ, ๐Ÿ“› ๐Ÿ”ข `file_path`, &amp; ๐Ÿ ๐Ÿ•, `:path`, ๐Ÿ’ฌ โšซ๏ธ ๐Ÿ‘ˆ ๐Ÿ”ข ๐Ÿ”œ ๐Ÿ ๐Ÿ™† *โžก*.
, ๐Ÿ‘† ๐Ÿ’ช โš™๏ธ โšซ๏ธ โฎ๏ธ:
```Python hl_lines="6"
{!../../../docs_src/path_params/tutorial004.py!}
```
!!! tip
๐Ÿ‘† ๐Ÿ’ช ๐Ÿ’ช ๐Ÿ”ข ๐Ÿ”Œ `/home/johndoe/myfile.txt`, โฎ๏ธ ๐Ÿ ๐Ÿ”ช (`/`).
๐Ÿ‘ˆ ๐Ÿ’ผ, ๐Ÿ“› ๐Ÿ”œ: `/files//home/johndoe/myfile.txt`, โฎ๏ธ 2๏ธโƒฃโœ–๏ธ ๐Ÿ”ช (`//`) ๐Ÿ–– `files` &amp; `home`.
## ๐ŸŒƒ
โฎ๏ธ **FastAPI**, โš™๏ธ ๐Ÿ“, ๐Ÿ‹๏ธ &amp; ๐Ÿฉ ๐Ÿ ๐Ÿ†Ž ๐Ÿ“„, ๐Ÿ‘† ๐Ÿคš:
* ๐Ÿ‘จโ€๐ŸŽจ ๐Ÿ•โ€๐Ÿฆบ: โŒ โœ…, โœ, โ™’๏ธ.
* ๐Ÿ’ฝ "<abbr title="converting the string that comes from an HTTP request into Python data">โœ</abbr>"
* ๐Ÿ’ฝ ๐Ÿ”ฌ
* ๐Ÿ› ๏ธ โœ &amp; ๐Ÿง ๐Ÿงพ
&amp; ๐Ÿ‘† ๐Ÿ•ด โœ”๏ธ ๐Ÿ“ฃ ๐Ÿ‘ซ ๐Ÿ•.
๐Ÿ‘ˆ ๐ŸŽฒ ๐Ÿ‘‘ โญ ๐Ÿ“ˆ **FastAPI** ๐Ÿ”ฌ ๐ŸŽ› ๐Ÿ› ๏ธ (โ†–๏ธ โšช๏ธโžก๏ธ ๐Ÿฃ ๐ŸŽญ).

467
docs/em/docs/tutorial/query-params-str-validations.md

@ -0,0 +1,467 @@
# ๐Ÿ”ข ๐Ÿ”ข &amp; ๐ŸŽป ๐Ÿ”ฌ
**FastAPI** โœ” ๐Ÿ‘† ๐Ÿ“ฃ ๐ŸŒ– โ„น &amp; ๐Ÿ”ฌ ๐Ÿ‘† ๐Ÿ”ข.
โžก๏ธ โœŠ ๐Ÿ‘‰ ๐Ÿˆธ ๐Ÿ–ผ:
=== "๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="9"
{!> ../../../docs_src/query_params_str_validations/tutorial001.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.1๏ธโƒฃ0๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="7"
{!> ../../../docs_src/query_params_str_validations/tutorial001_py310.py!}
```
๐Ÿ”ข ๐Ÿ”ข `q` ๐Ÿ†Ž `Union[str, None]` (โš–๏ธ `str | None` ๐Ÿ 3๏ธโƒฃ.1๏ธโƒฃ0๏ธโƒฃ), ๐Ÿ‘ˆ โ›“ ๐Ÿ‘ˆ โšซ๏ธ ๐Ÿ†Ž `str` โœ‹๏ธ ๐Ÿ’ช `None`, &amp; ๐Ÿ‘, ๐Ÿ”ข ๐Ÿ’ฒ `None`, FastAPI ๐Ÿ”œ ๐Ÿ’ญ โšซ๏ธ ๐Ÿšซ โœ”.
!!! note
FastAPI ๐Ÿ”œ ๐Ÿ’ญ ๐Ÿ‘ˆ ๐Ÿ’ฒ `q` ๐Ÿšซ โœ” โ†ฉ๏ธ ๐Ÿ”ข ๐Ÿ’ฒ `= None`.
`Union` `Union[str, None]` ๐Ÿ”œ โœ” ๐Ÿ‘† ๐Ÿ‘จโ€๐ŸŽจ ๐Ÿค ๐Ÿ‘† ๐Ÿ‘ ๐Ÿ•โ€๐Ÿฆบ &amp; ๐Ÿ” โŒ.
## ๐ŸŒ– ๐Ÿ”ฌ
๐Ÿ‘ฅ ๐Ÿ”œ ๐Ÿ› ๏ธ ๐Ÿ‘ˆ โœ‹๏ธ `q` ๐Ÿ“ฆ, ๐Ÿ•โ” โšซ๏ธ ๐Ÿšš, **๐Ÿšฎ ๐Ÿ“ ๐Ÿšซ ๐Ÿ“‰ 5๏ธโƒฃ0๏ธโƒฃ ๐Ÿฆน**.
### ๐Ÿ—„ `Query`
๐Ÿ† ๐Ÿ‘ˆ, ๐Ÿฅ‡ ๐Ÿ—„ `Query` โšช๏ธโžก๏ธ `fastapi`:
=== "๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="3"
{!> ../../../docs_src/query_params_str_validations/tutorial002.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.1๏ธโƒฃ0๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="1"
{!> ../../../docs_src/query_params_str_validations/tutorial002_py310.py!}
```
## โš™๏ธ `Query` ๐Ÿ”ข ๐Ÿ’ฒ
&amp; ๐Ÿ”œ โš™๏ธ โšซ๏ธ ๐Ÿ”ข ๐Ÿ’ฒ ๐Ÿ‘† ๐Ÿ”ข, โš’ ๐Ÿ”ข `max_length` 5๏ธโƒฃ0๏ธโƒฃ:
=== "๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="9"
{!> ../../../docs_src/query_params_str_validations/tutorial002.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.1๏ธโƒฃ0๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="7"
{!> ../../../docs_src/query_params_str_validations/tutorial002_py310.py!}
```
๐Ÿ‘ฅ โœ”๏ธ โŽ ๐Ÿ”ข ๐Ÿ’ฒ `None` ๐Ÿ”ข โฎ๏ธ `Query()`, ๐Ÿ‘ฅ ๐Ÿ’ช ๐Ÿ”œ โš’ ๐Ÿ”ข ๐Ÿ’ฒ โฎ๏ธ ๐Ÿ”ข `Query(default=None)`, โšซ๏ธ ๐Ÿฆ ๐ŸŽ ๐ŸŽฏ โš– ๐Ÿ‘ˆ ๐Ÿ”ข ๐Ÿ’ฒ.
:
```Python
q: Union[str, None] = Query(default=None)
```
...โš’ ๐Ÿ”ข ๐Ÿ“ฆ, ๐ŸŽ:
```Python
q: Union[str, None] = None
```
&amp; ๐Ÿ 3๏ธโƒฃ.1๏ธโƒฃ0๏ธโƒฃ &amp; ๐Ÿ”›:
```Python
q: str | None = Query(default=None)
```
...โš’ ๐Ÿ”ข ๐Ÿ“ฆ, ๐ŸŽ:
```Python
q: str | None = None
```
โœ‹๏ธ โšซ๏ธ ๐Ÿ“ฃ โšซ๏ธ ๐ŸŽฏ ๐Ÿ’†โ€โ™‚ ๐Ÿ”ข ๐Ÿ”ข.
!!! info
โœ”๏ธ ๐Ÿคฏ ๐Ÿ‘ˆ ๐ŸŒ… โš  ๐Ÿ• โš’ ๐Ÿ”ข ๐Ÿ“ฆ ๐Ÿ•:
```Python
= None
```
โš–๏ธ:
```Python
= Query(default=None)
```
โšซ๏ธ ๐Ÿ”œ โš™๏ธ ๐Ÿ‘ˆ `None` ๐Ÿ”ข ๐Ÿ’ฒ, &amp; ๐Ÿ‘ˆ ๐ŸŒŒ โš’ ๐Ÿ”ข **๐Ÿšซ โœ”**.
`Union[str, None]` ๐Ÿ• โœ” ๐Ÿ‘† ๐Ÿ‘จโ€๐ŸŽจ ๐Ÿšš ๐Ÿ‘ป ๐Ÿ•โ€๐Ÿฆบ, โœ‹๏ธ โšซ๏ธ ๐Ÿšซ โšซ๏ธโ” ๐Ÿ’ฌ FastAPI ๐Ÿ‘ˆ ๐Ÿ‘‰ ๐Ÿ”ข ๐Ÿšซ โœ”.
โคด๏ธ, ๐Ÿ‘ฅ ๐Ÿ’ช ๐Ÿšถโ€โ™€๏ธ ๐ŸŒ… ๐Ÿ”ข `Query`. ๐Ÿ‘‰ ๐Ÿ’ผ, `max_length` ๐Ÿ”ข ๐Ÿ‘ˆ โœ” ๐ŸŽป:
```Python
q: Union[str, None] = Query(default=None, max_length=50)
```
๐Ÿ‘‰ ๐Ÿ”œ โœ” ๐Ÿ“Š, ๐ŸŽฆ ๐Ÿ†‘ โŒ ๐Ÿ•โ” ๐Ÿ“Š ๐Ÿšซ โ˜‘, &amp; ๐Ÿ“„ ๐Ÿ”ข ๐Ÿ—„ ๐Ÿ”— *โžก ๐Ÿ› ๏ธ*.
## ๐Ÿšฎ ๐ŸŒ… ๐Ÿ”ฌ
๐Ÿ‘† ๐Ÿ’ช ๐Ÿšฎ ๐Ÿ”ข `min_length`:
=== "๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="10"
{!> ../../../docs_src/query_params_str_validations/tutorial003.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.1๏ธโƒฃ0๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="7"
{!> ../../../docs_src/query_params_str_validations/tutorial003_py310.py!}
```
## ๐Ÿšฎ ๐Ÿฅ” ๐Ÿงฌ
๐Ÿ‘† ๐Ÿ’ช ๐Ÿ”ฌ <abbr title="A regular expression, regex or regexp is a sequence of characters that define a search pattern for strings.">๐Ÿฅ” ๐Ÿงฌ</abbr> ๐Ÿ‘ˆ ๐Ÿ”ข ๐Ÿ”œ ๐Ÿ:
=== "๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="11"
{!> ../../../docs_src/query_params_str_validations/tutorial004.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.1๏ธโƒฃ0๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="9"
{!> ../../../docs_src/query_params_str_validations/tutorial004_py310.py!}
```
๐Ÿ‘‰ ๐ŸŽฏ ๐Ÿฅ” ๐Ÿงฌ โœ… ๐Ÿ‘ˆ ๐Ÿ“จ ๐Ÿ”ข ๐Ÿ’ฒ:
* `^`: โ–ถ๏ธ โฎ๏ธ ๐Ÿ“„ ๐Ÿฆน, ๐Ÿšซ โœ”๏ธ ๐Ÿฆน โญ.
* `fixedquery`: โœ”๏ธ โ˜‘ ๐Ÿ’ฒ `fixedquery`.
* `$`: ๐Ÿ”š ๐Ÿ“ค, ๐Ÿšซ โœ”๏ธ ๐Ÿ™† ๐ŸŒ– ๐Ÿฆน โฎ๏ธ `fixedquery`.
๐Ÿšฅ ๐Ÿ‘† ๐Ÿ’ญ ๐Ÿ’ธ โฎ๏ธ ๐ŸŒ ๐Ÿ‘‰ **"๐Ÿฅ” ๐Ÿงฌ"** ๐Ÿ’ญ, ๐Ÿšซ ๐Ÿ˜Ÿ. ๐Ÿ‘ซ ๐Ÿ‹๏ธ โ” ๐Ÿ“š ๐Ÿ‘ซ๐Ÿ‘ซ. ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ“š ๐Ÿ’ฉ ๐Ÿต ๐Ÿ’†โ€โ™‚ ๐Ÿฅ” ๐Ÿงฌ.
โœ‹๏ธ ๐Ÿ•โ” ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ‘ซ &amp; ๐Ÿšถ &amp; ๐Ÿ’ก ๐Ÿ‘ซ, ๐Ÿ’ญ ๐Ÿ‘ˆ ๐Ÿ‘† ๐Ÿ’ช โช โš™๏ธ ๐Ÿ‘ซ ๐Ÿ”— **FastAPI**.
## ๐Ÿ”ข ๐Ÿ’ฒ
๐ŸŽ ๐ŸŒŒ ๐Ÿ‘ˆ ๐Ÿ‘† ๐Ÿ’ช ๐Ÿšถโ€โ™€๏ธ `None` ๐Ÿ’ฒ `default` ๐Ÿ”ข, ๐Ÿ‘† ๐Ÿ’ช ๐Ÿšถโ€โ™€๏ธ ๐ŸŽ ๐Ÿ’ฒ.
โžก๏ธ ๐Ÿ’ฌ ๐Ÿ‘ˆ ๐Ÿ‘† ๐Ÿ’š ๐Ÿ“ฃ `q` ๐Ÿ”ข ๐Ÿ”ข โœ”๏ธ `min_length` `3`, &amp; โœ”๏ธ ๐Ÿ”ข ๐Ÿ’ฒ `"fixedquery"`:
```Python hl_lines="7"
{!../../../docs_src/query_params_str_validations/tutorial005.py!}
```
!!! note
โœ”๏ธ ๐Ÿ”ข ๐Ÿ’ฒ โš’ ๐Ÿ”ข ๐Ÿ“ฆ.
## โš’ โšซ๏ธ โœ”
๐Ÿ•โ” ๐Ÿ‘ฅ ๐Ÿšซ ๐Ÿ’ช ๐Ÿ“ฃ ๐ŸŒ… ๐Ÿ”ฌ โš–๏ธ ๐Ÿ—ƒ, ๐Ÿ‘ฅ ๐Ÿ’ช โš’ `q` ๐Ÿ”ข ๐Ÿ”ข โœ” ๐Ÿšซ ๐Ÿ“ฃ ๐Ÿ”ข ๐Ÿ’ฒ, ๐Ÿ’–:
```Python
q: str
```
โ†ฉ๏ธ:
```Python
q: Union[str, None] = None
```
โœ‹๏ธ ๐Ÿ‘ฅ ๐Ÿ”œ ๐Ÿ“ฃ โšซ๏ธ โฎ๏ธ `Query`, ๐Ÿ–ผ ๐Ÿ’–:
```Python
q: Union[str, None] = Query(default=None, min_length=3)
```
, ๐Ÿ•โ” ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ“ฃ ๐Ÿ’ฒ โœ” โช โš™๏ธ `Query`, ๐Ÿ‘† ๐Ÿ’ช ๐ŸŽฏ ๐Ÿšซ ๐Ÿ“ฃ ๐Ÿ”ข ๐Ÿ’ฒ:
```Python hl_lines="7"
{!../../../docs_src/query_params_str_validations/tutorial006.py!}
```
### โœ” โฎ๏ธ โ• (`...`)
๐Ÿ“ค ๐ŸŽ› ๐ŸŒŒ ๐ŸŽฏ ๐Ÿ“ฃ ๐Ÿ‘ˆ ๐Ÿ’ฒ โœ”. ๐Ÿ‘† ๐Ÿ’ช โš’ `default` ๐Ÿ”ข ๐Ÿ”‘ ๐Ÿ’ฒ `...`:
```Python hl_lines="7"
{!../../../docs_src/query_params_str_validations/tutorial006b.py!}
```
!!! info
๐Ÿšฅ ๐Ÿ‘† ๐Ÿšซ ๐Ÿ‘€ ๐Ÿ‘ˆ `...` โญ: โšซ๏ธ ๐ŸŽ ๐Ÿ‘ ๐Ÿ’ฒ, โšซ๏ธ <a href="https://docs.python.org/3/library/constants.html#Ellipsis" class="external-link" target="_blank">๐Ÿ• ๐Ÿ &amp; ๐Ÿค™ "โ•"</a>.
โšซ๏ธ โš™๏ธ Pydantic &amp; FastAPI ๐ŸŽฏ ๐Ÿ“ฃ ๐Ÿ‘ˆ ๐Ÿ’ฒ โœ”.
๐Ÿ‘‰ ๐Ÿ”œ โžก๏ธ **FastAPI** ๐Ÿ’ญ ๐Ÿ‘ˆ ๐Ÿ‘‰ ๐Ÿ”ข โœ”.
### โœ” โฎ๏ธ `None`
๐Ÿ‘† ๐Ÿ’ช ๐Ÿ“ฃ ๐Ÿ‘ˆ ๐Ÿ”ข ๐Ÿ’ช ๐Ÿšซ `None`, โœ‹๏ธ ๐Ÿ‘ˆ โšซ๏ธ โœ”. ๐Ÿ‘‰ ๐Ÿ”œ โšก ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ“จ ๐Ÿ’ฒ, ๐Ÿšฅ ๐Ÿ’ฒ `None`.
๐Ÿ‘ˆ, ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ“ฃ ๐Ÿ‘ˆ `None` โ˜‘ ๐Ÿ†Ž โœ‹๏ธ โš™๏ธ `default=...`:
=== "๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="9"
{!> ../../../docs_src/query_params_str_validations/tutorial006c.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.1๏ธโƒฃ0๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="7"
{!> ../../../docs_src/query_params_str_validations/tutorial006c_py310.py!}
```
!!! tip
Pydantic, โ” โšซ๏ธโ” ๐Ÿ‹๏ธ ๐ŸŒ ๐Ÿ’ฝ ๐Ÿ”ฌ &amp; ๐Ÿ› ๏ธ FastAPI, โœ”๏ธ ๐ŸŽ ๐ŸŽญ ๐Ÿ•โ” ๐Ÿ‘† โš™๏ธ `Optional` โš–๏ธ `Union[Something, None]` ๐Ÿต ๐Ÿ”ข ๐Ÿ’ฒ, ๐Ÿ‘† ๐Ÿ’ช โœ ๐ŸŒ… ๐Ÿ”ƒ โšซ๏ธ Pydantic ๐Ÿฉบ ๐Ÿ”ƒ <a href="https://pydantic-docs.helpmanual.io/usage/models/#required-optional-fields" class="external-link" target="_blank">โœ” ๐Ÿ“ฆ ๐Ÿ‘</a>.
### โš™๏ธ Pydantic `Required` โ†ฉ๏ธ โ• (`...`)
๐Ÿšฅ ๐Ÿ‘† ๐Ÿ’ญ ๐Ÿ˜ฌ โš™๏ธ `...`, ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ—„ &amp; โš™๏ธ `Required` โšช๏ธโžก๏ธ Pydantic:
```Python hl_lines="2 8"
{!../../../docs_src/query_params_str_validations/tutorial006d.py!}
```
!!! tip
๐Ÿ’ญ ๐Ÿ‘ˆ ๐ŸŒ… ๐Ÿ’ผ, ๐Ÿ•โ” ๐Ÿ•ณ ๐Ÿšš, ๐Ÿ‘† ๐Ÿ’ช ๐ŸŽฏ ๐Ÿšซ `default` ๐Ÿ”ข, ๐Ÿ‘† ๐Ÿ›Ž ๐Ÿšซ โœ”๏ธ โš™๏ธ `...` ๐Ÿšซ `Required`.
## ๐Ÿ”ข ๐Ÿ”ข ๐Ÿ“‡ / ๐Ÿ’— ๐Ÿ’ฒ
๐Ÿ•โ” ๐Ÿ‘† ๐Ÿ”ฌ ๐Ÿ”ข ๐Ÿ”ข ๐ŸŽฏ โฎ๏ธ `Query` ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ“ฃ โšซ๏ธ ๐Ÿ“จ ๐Ÿ“‡ ๐Ÿ’ฒ, โš–๏ธ ๐Ÿ™†โ€โ™€ ๐ŸŽ ๐ŸŒŒ, ๐Ÿ“จ ๐Ÿ’— ๐Ÿ’ฒ.
๐Ÿ–ผ, ๐Ÿ“ฃ ๐Ÿ”ข ๐Ÿ”ข `q` ๐Ÿ‘ˆ ๐Ÿ’ช ๐Ÿ˜‘ ๐Ÿ’— ๐Ÿ•ฐ ๐Ÿ“›, ๐Ÿ‘† ๐Ÿ’ช โœ:
=== "๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="9"
{!> ../../../docs_src/query_params_str_validations/tutorial011.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.9๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="9"
{!> ../../../docs_src/query_params_str_validations/tutorial011_py39.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.1๏ธโƒฃ0๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="7"
{!> ../../../docs_src/query_params_str_validations/tutorial011_py310.py!}
```
โคด๏ธ, โฎ๏ธ ๐Ÿ“› ๐Ÿ’–:
```
http://localhost:8000/items/?q=foo&q=bar
```
๐Ÿ‘† ๐Ÿ”œ ๐Ÿ“จ ๐Ÿ’— `q` *๐Ÿ”ข ๐Ÿ”ข'* ๐Ÿ’ฒ (`foo` &amp; `bar`) ๐Ÿ `list` ๐Ÿ”˜ ๐Ÿ‘† *โžก ๐Ÿ› ๏ธ ๐Ÿ”ข*, *๐Ÿ”ข ๐Ÿ”ข* `q`.
, ๐Ÿ“จ ๐Ÿ‘ˆ ๐Ÿ“› ๐Ÿ”œ:
```JSON
{
"q": [
"foo",
"bar"
]
}
```
!!! tip
๐Ÿ“ฃ ๐Ÿ”ข ๐Ÿ”ข โฎ๏ธ ๐Ÿ†Ž `list`, ๐Ÿ’– ๐Ÿ–ผ ๐Ÿ”›, ๐Ÿ‘† ๐Ÿ’ช ๐ŸŽฏ โš™๏ธ `Query`, โช โšซ๏ธ ๐Ÿ”œ ๐Ÿ”ฌ ๐Ÿ“จ ๐Ÿ’ช.
๐ŸŽ“ ๐Ÿ› ๏ธ ๐Ÿฉบ ๐Ÿ”œ โ„น โžก๏ธ, โœ” ๐Ÿ’— ๐Ÿ’ฒ:
<img src="/img/tutorial/query-params-str-validations/image02.png">
### ๐Ÿ”ข ๐Ÿ”ข ๐Ÿ“‡ / ๐Ÿ’— ๐Ÿ’ฒ โฎ๏ธ ๐Ÿ”ข
&amp; ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ”ฌ ๐Ÿ”ข `list` ๐Ÿ’ฒ ๐Ÿšฅ ๐Ÿ‘Œ ๐Ÿšš:
=== "๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="9"
{!> ../../../docs_src/query_params_str_validations/tutorial012.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.9๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="7"
{!> ../../../docs_src/query_params_str_validations/tutorial012_py39.py!}
```
๐Ÿšฅ ๐Ÿ‘† ๐Ÿšถ:
```
http://localhost:8000/items/
```
๐Ÿ”ข `q` ๐Ÿ”œ: `["foo", "bar"]` &amp; ๐Ÿ‘† ๐Ÿ“จ ๐Ÿ”œ:
```JSON
{
"q": [
"foo",
"bar"
]
}
```
#### โš™๏ธ `list`
๐Ÿ‘† ๐Ÿ’ช โš™๏ธ `list` ๐Ÿ”— โ†ฉ๏ธ `List[str]` (โš–๏ธ `list[str]` ๐Ÿ 3๏ธโƒฃ.9๏ธโƒฃ โž•):
```Python hl_lines="7"
{!../../../docs_src/query_params_str_validations/tutorial013.py!}
```
!!! note
โœ”๏ธ ๐Ÿคฏ ๐Ÿ‘ˆ ๐Ÿ‘‰ ๐Ÿ’ผ, FastAPI ๐Ÿ† ๐Ÿšซ โœ… ๐ŸŽš ๐Ÿ“‡.
๐Ÿ–ผ, `List[int]` ๐Ÿ”œ โœ… (&amp; ๐Ÿ“„) ๐Ÿ‘ˆ ๐ŸŽš ๐Ÿ“‡ ๐Ÿ”ข. โœ‹๏ธ `list` ๐Ÿ˜ž ๐Ÿšซ๐Ÿ”œ.
## ๐Ÿ“ฃ ๐ŸŒ… ๐Ÿ—ƒ
๐Ÿ‘† ๐Ÿ’ช ๐Ÿšฎ ๐ŸŒ… โ„น ๐Ÿ”ƒ ๐Ÿ”ข.
๐Ÿ‘ˆ โ„น ๐Ÿ”œ ๐Ÿ”Œ ๐Ÿ— ๐Ÿ—„ &amp; โš™๏ธ ๐Ÿงพ ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ”ข &amp; ๐Ÿ”ข ๐Ÿงฐ.
!!! note
โœ”๏ธ ๐Ÿคฏ ๐Ÿ‘ˆ ๐ŸŽ ๐Ÿงฐ 5๏ธโƒฃ๐Ÿ“† โœ”๏ธ ๐ŸŽ ๐ŸŽš ๐Ÿ—„ ๐Ÿ•โ€๐Ÿฆบ.
๐Ÿ‘ซ ๐Ÿ’ช ๐Ÿšซ ๐ŸŽฆ ๐ŸŒ โž• โ„น ๐Ÿ“ฃ, ๐Ÿ‘ ๐ŸŒ… ๐Ÿ’ผ, โŒ โš’ โช ๐Ÿ“„ ๐Ÿ› ๏ธ.
๐Ÿ‘† ๐Ÿ’ช ๐Ÿšฎ `title`:
=== "๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="10"
{!> ../../../docs_src/query_params_str_validations/tutorial007.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.1๏ธโƒฃ0๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="8"
{!> ../../../docs_src/query_params_str_validations/tutorial007_py310.py!}
```
&amp; `description`:
=== "๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="13"
{!> ../../../docs_src/query_params_str_validations/tutorial008.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.1๏ธโƒฃ0๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="12"
{!> ../../../docs_src/query_params_str_validations/tutorial008_py310.py!}
```
## ๐Ÿ“› ๐Ÿ”ข
๐ŸŒˆ ๐Ÿ‘ˆ ๐Ÿ‘† ๐Ÿ’š ๐Ÿ”ข `item-query`.
๐Ÿ’–:
```
http://127.0.0.1:8000/items/?item-query=foobaritems
```
โœ‹๏ธ `item-query` ๐Ÿšซ โ˜‘ ๐Ÿ ๐Ÿ”ข ๐Ÿ“›.
๐Ÿ” ๐Ÿ”œ `item_query`.
โœ‹๏ธ ๐Ÿ‘† ๐Ÿ’ช โšซ๏ธ โšซ๏ธโ” `item-query`...
โคด๏ธ ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ“ฃ `alias`, &amp; ๐Ÿ‘ˆ ๐Ÿ“› โšซ๏ธโ” ๐Ÿ”œ โš™๏ธ ๐Ÿ”Ž ๐Ÿ”ข ๐Ÿ’ฒ:
=== "๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="9"
{!> ../../../docs_src/query_params_str_validations/tutorial009.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.1๏ธโƒฃ0๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="7"
{!> ../../../docs_src/query_params_str_validations/tutorial009_py310.py!}
```
## ๐Ÿ˜› ๐Ÿ”ข
๐Ÿ”œ โžก๏ธ ๐Ÿ’ฌ ๐Ÿ‘† ๐Ÿšซ ๐Ÿ’– ๐Ÿ‘‰ ๐Ÿ”ข ๐Ÿšซ๐Ÿ”œ.
๐Ÿ‘† โœ”๏ธ ๐Ÿ‘ˆ โšซ๏ธ ๐Ÿ“ค โช โ†ฉ๏ธ ๐Ÿ“ค ๐Ÿ‘ฉโ€๐Ÿ’ป โš™๏ธ โšซ๏ธ, โœ‹๏ธ ๐Ÿ‘† ๐Ÿ’š ๐Ÿฉบ ๐ŸŽฏ ๐ŸŽฆ โšซ๏ธ <abbr title="obsolete, recommended not to use it">๐Ÿ˜ข</abbr>.
โคด๏ธ ๐Ÿšถโ€โ™€๏ธ ๐Ÿ”ข `deprecated=True` `Query`:
=== "๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="18"
{!> ../../../docs_src/query_params_str_validations/tutorial010.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.1๏ธโƒฃ0๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="17"
{!> ../../../docs_src/query_params_str_validations/tutorial010_py310.py!}
```
๐Ÿฉบ ๐Ÿ”œ ๐ŸŽฆ โšซ๏ธ ๐Ÿ’– ๐Ÿ‘‰:
<img src="/img/tutorial/query-params-str-validations/image01.png">
## ๐Ÿšซ โšช๏ธโžก๏ธ ๐Ÿ—„
๐Ÿšซ ๐Ÿ”ข ๐Ÿ”ข โšช๏ธโžก๏ธ ๐Ÿ— ๐Ÿ—„ ๐Ÿ”— (&amp; โžก๏ธ, โšช๏ธโžก๏ธ ๐Ÿง ๐Ÿงพ โš™๏ธ), โš’ ๐Ÿ”ข `include_in_schema` `Query` `False`:
=== "๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="10"
{!> ../../../docs_src/query_params_str_validations/tutorial014.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.1๏ธโƒฃ0๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="8"
{!> ../../../docs_src/query_params_str_validations/tutorial014_py310.py!}
```
## ๐ŸŒƒ
๐Ÿ‘† ๐Ÿ’ช ๐Ÿ“ฃ ๐ŸŒ– ๐Ÿ”ฌ &amp; ๐Ÿ—ƒ ๐Ÿ‘† ๐Ÿ”ข.
๐Ÿ’Š ๐Ÿ”ฌ &amp; ๐Ÿ—ƒ:
* `alias`
* `title`
* `description`
* `deprecated`
๐Ÿ”ฌ ๐ŸŽฏ ๐ŸŽป:
* `min_length`
* `max_length`
* `regex`
๐Ÿ‘ซ ๐Ÿ–ผ ๐Ÿ‘† ๐Ÿ‘€ โ” ๐Ÿ“ฃ ๐Ÿ”ฌ `str` ๐Ÿ’ฒ.
๐Ÿ‘€ โญ ๐Ÿ“ƒ ๐Ÿ‘€ โ” ๐Ÿ“ฃ ๐Ÿ”ฌ ๐ŸŽ ๐Ÿ†Ž, ๐Ÿ’– ๐Ÿ”ข.

225
docs/em/docs/tutorial/query-params.md

@ -0,0 +1,225 @@
# ๐Ÿ”ข ๐Ÿ”ข
๐Ÿ•โ” ๐Ÿ‘† ๐Ÿ“ฃ ๐ŸŽ ๐Ÿ”ข ๐Ÿ”ข ๐Ÿ‘ˆ ๐Ÿšซ ๐Ÿ• โžก ๐Ÿ”ข, ๐Ÿ‘ซ ๐Ÿ” ๐Ÿ”ฌ "๐Ÿ”ข" ๐Ÿ”ข.
```Python hl_lines="9"
{!../../../docs_src/query_params/tutorial001.py!}
```
๐Ÿ”ข โš’ ๐Ÿ”‘-๐Ÿ’ฒ ๐Ÿ‘ซ ๐Ÿ‘ˆ ๐Ÿšถ โฎ๏ธ `?` ๐Ÿ“›, ๐ŸŽ `&` ๐Ÿฆน.
๐Ÿ–ผ, ๐Ÿ“›:
```
http://127.0.0.1:8000/items/?skip=0&limit=10
```
...๐Ÿ”ข ๐Ÿ”ข:
* `skip`: โฎ๏ธ ๐Ÿ’ฒ `0`
* `limit`: โฎ๏ธ ๐Ÿ’ฒ `10`
๐Ÿ‘ซ ๐Ÿ• ๐Ÿ“›, ๐Ÿ‘ซ "๐Ÿ›Ž" ๐ŸŽป.
โœ‹๏ธ ๐Ÿ•โ” ๐Ÿ‘† ๐Ÿ“ฃ ๐Ÿ‘ซ โฎ๏ธ ๐Ÿ ๐Ÿ†Ž (๐Ÿ–ผ ๐Ÿ”›, `int`), ๐Ÿ‘ซ ๐Ÿ—œ ๐Ÿ‘ˆ ๐Ÿ†Ž &amp; โœ” ๐Ÿ›ก โšซ๏ธ.
๐ŸŒ ๐ŸŽ ๐Ÿ› ๏ธ ๐Ÿ‘ˆ โš– โžก ๐Ÿ”ข โœ” ๐Ÿ”ข ๐Ÿ”ข:
* ๐Ÿ‘จโ€๐ŸŽจ ๐Ÿ•โ€๐Ÿฆบ (๐ŸŽฒ)
* ๐Ÿ’ฝ <abbr title="converting the string that comes from an HTTP request into Python data">"โœ"</abbr>
* ๐Ÿ’ฝ ๐Ÿ”ฌ
* ๐Ÿง ๐Ÿงพ
## ๐Ÿ”ข
๐Ÿ”ข ๐Ÿ”ข ๐Ÿšซ ๐Ÿ”ง ๐Ÿ• โžก, ๐Ÿ‘ซ ๐Ÿ’ช ๐Ÿ“ฆ &amp; ๐Ÿ’ช โœ”๏ธ ๐Ÿ”ข ๐Ÿ’ฒ.
๐Ÿ–ผ ๐Ÿ”› ๐Ÿ‘ซ โœ”๏ธ ๐Ÿ”ข ๐Ÿ’ฒ `skip=0` &amp; `limit=10`.
, ๐Ÿ”œ ๐Ÿ“›:
```
http://127.0.0.1:8000/items/
```
๐Ÿ”œ ๐ŸŽ ๐Ÿ”œ:
```
http://127.0.0.1:8000/items/?skip=0&limit=10
```
โœ‹๏ธ ๐Ÿšฅ ๐Ÿ‘† ๐Ÿšถ, ๐Ÿ–ผ:
```
http://127.0.0.1:8000/items/?skip=20
```
๐Ÿ”ข ๐Ÿ’ฒ ๐Ÿ‘† ๐Ÿ”ข ๐Ÿ”œ:
* `skip=20`: โ†ฉ๏ธ ๐Ÿ‘† โš’ โšซ๏ธ ๐Ÿ“›
* `limit=10`: โ†ฉ๏ธ ๐Ÿ‘ˆ ๐Ÿ”ข ๐Ÿ’ฒ
## ๐Ÿ“ฆ ๐Ÿ”ข
๐ŸŽ ๐ŸŒŒ, ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ“ฃ ๐Ÿ“ฆ ๐Ÿ”ข ๐Ÿ”ข, โš’ ๐Ÿ‘ซ ๐Ÿ”ข `None`:
=== "๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="9"
{!> ../../../docs_src/query_params/tutorial002.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.1๏ธโƒฃ0๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="7"
{!> ../../../docs_src/query_params/tutorial002_py310.py!}
```
๐Ÿ‘‰ ๐Ÿ’ผ, ๐Ÿ”ข ๐Ÿ”ข `q` ๐Ÿ”œ ๐Ÿ“ฆ, &amp; ๐Ÿ”œ `None` ๐Ÿ”ข.
!!! check
๐Ÿ‘€ ๐Ÿ‘ˆ **FastAPI** ๐Ÿ™ƒ ๐Ÿฅƒ ๐Ÿ‘€ ๐Ÿ‘ˆ โžก ๐Ÿ”ข `item_id` โžก ๐Ÿ”ข &amp; `q` ๐Ÿšซ,, โšซ๏ธ ๐Ÿ”ข ๐Ÿ”ข.
## ๐Ÿ”ข ๐Ÿ”ข ๐Ÿ†Ž ๐Ÿ› ๏ธ
๐Ÿ‘† ๐Ÿ’ช ๐Ÿ“ฃ `bool` ๐Ÿ†Ž, &amp; ๐Ÿ‘ซ ๐Ÿ”œ ๐Ÿ—œ:
=== "๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="9"
{!> ../../../docs_src/query_params/tutorial003.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.1๏ธโƒฃ0๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="7"
{!> ../../../docs_src/query_params/tutorial003_py310.py!}
```
๐Ÿ‘‰ ๐Ÿ’ผ, ๐Ÿšฅ ๐Ÿ‘† ๐Ÿšถ:
```
http://127.0.0.1:8000/items/foo?short=1
```
โš–๏ธ
```
http://127.0.0.1:8000/items/foo?short=True
```
โš–๏ธ
```
http://127.0.0.1:8000/items/foo?short=true
```
โš–๏ธ
```
http://127.0.0.1:8000/items/foo?short=on
```
โš–๏ธ
```
http://127.0.0.1:8000/items/foo?short=yes
```
โš–๏ธ ๐Ÿ™† ๐ŸŽ ๐Ÿ’ผ ๐Ÿ“ˆ (๐Ÿ” , ๐Ÿฅ‡ ๐Ÿ”ค ๐Ÿ” , โ™’๏ธ), ๐Ÿ‘† ๐Ÿ”ข ๐Ÿ”œ ๐Ÿ‘€ ๐Ÿ”ข `short` โฎ๏ธ `bool` ๐Ÿ’ฒ `True`. โช `False`.
## ๐Ÿ’— โžก &amp; ๐Ÿ”ข ๐Ÿ”ข
๐Ÿ‘† ๐Ÿ’ช ๐Ÿ“ฃ ๐Ÿ’— โžก ๐Ÿ”ข &amp; ๐Ÿ”ข ๐Ÿ”ข ๐ŸŽ ๐Ÿ•ฐ, **FastAPI** ๐Ÿ’ญ โ” โ”.
&amp; ๐Ÿ‘† ๐Ÿšซ โœ”๏ธ ๐Ÿ“ฃ ๐Ÿ‘ซ ๐Ÿ™† ๐ŸŽฏ โœ”.
๐Ÿ‘ซ ๐Ÿ”œ ๐Ÿ”ฌ ๐Ÿ“›:
=== "๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="8 10"
{!> ../../../docs_src/query_params/tutorial004.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.1๏ธโƒฃ0๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="6 8"
{!> ../../../docs_src/query_params/tutorial004_py310.py!}
```
## โœ” ๐Ÿ”ข ๐Ÿ”ข
๐Ÿ•โ” ๐Ÿ‘† ๐Ÿ“ฃ ๐Ÿ”ข ๐Ÿ’ฒ ๐Ÿšซ-โžก ๐Ÿ”ข (๐Ÿ”œ, ๐Ÿ‘ฅ โœ”๏ธ ๐Ÿ•ด ๐Ÿ‘€ ๐Ÿ”ข ๐Ÿ”ข), โคด๏ธ โšซ๏ธ ๐Ÿšซ โœ”.
๐Ÿšฅ ๐Ÿ‘† ๐Ÿšซ ๐Ÿ’š ๐Ÿšฎ ๐ŸŽฏ ๐Ÿ’ฒ โœ‹๏ธ โš’ โšซ๏ธ ๐Ÿ“ฆ, โš’ ๐Ÿ”ข `None`.
โœ‹๏ธ ๐Ÿ•โ” ๐Ÿ‘† ๐Ÿ’š โš’ ๐Ÿ”ข ๐Ÿ”ข โœ”, ๐Ÿ‘† ๐Ÿ’ช ๐Ÿšซ ๐Ÿ“ฃ ๐Ÿ™† ๐Ÿ”ข ๐Ÿ’ฒ:
```Python hl_lines="6-7"
{!../../../docs_src/query_params/tutorial005.py!}
```
๐Ÿ“ฅ ๐Ÿ”ข ๐Ÿ”ข `needy` โœ” ๐Ÿ”ข ๐Ÿ”ข ๐Ÿ†Ž `str`.
๐Ÿšฅ ๐Ÿ‘† ๐Ÿ“‚ ๐Ÿ‘† ๐Ÿ–ฅ ๐Ÿ“› ๐Ÿ’–:
```
http://127.0.0.1:8000/items/foo-item
```
...๐Ÿต โŽ โœ” ๐Ÿ”ข `needy`, ๐Ÿ‘† ๐Ÿ”œ ๐Ÿ‘€ โŒ ๐Ÿ’–:
```JSON
{
"detail": [
{
"loc": [
"query",
"needy"
],
"msg": "field required",
"type": "value_error.missing"
}
]
}
```
`needy` ๐Ÿšš ๐Ÿ”ข, ๐Ÿ‘† ๐Ÿ”œ ๐Ÿ’ช โš’ โšซ๏ธ ๐Ÿ“›:
```
http://127.0.0.1:8000/items/foo-item?needy=sooooneedy
```
...๐Ÿ‘‰ ๐Ÿ”œ ๐Ÿ‘ท:
```JSON
{
"item_id": "foo-item",
"needy": "sooooneedy"
}
```
&amp; โ†—๏ธ, ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ”ฌ ๐Ÿ”ข โœ”, โœ”๏ธ ๐Ÿ”ข ๐Ÿ’ฒ, &amp; ๐Ÿ• ๐Ÿ“ฆ:
=== "๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="10"
{!> ../../../docs_src/query_params/tutorial006.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.1๏ธโƒฃ0๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="8"
{!> ../../../docs_src/query_params/tutorial006_py310.py!}
```
๐Ÿ‘‰ ๐Ÿ’ผ, ๐Ÿ“ค 3๏ธโƒฃ ๐Ÿ”ข ๐Ÿ”ข:
* `needy`, โœ” `str`.
* `skip`, `int` โฎ๏ธ ๐Ÿ”ข ๐Ÿ’ฒ `0`.
* `limit`, ๐Ÿ“ฆ `int`.
!!! tip
๐Ÿ‘† ๐Ÿ’ช โš™๏ธ `Enum`โ“‚ ๐ŸŽ ๐ŸŒŒ โฎ๏ธ [โžก ๐Ÿ”ข](path-params.md#predefined-values){.internal-link target=_blank}.

186
docs/em/docs/tutorial/request-files.md

@ -0,0 +1,186 @@
# ๐Ÿ“จ ๐Ÿ“
๐Ÿ‘† ๐Ÿ’ช ๐Ÿ”ฌ ๐Ÿ“ ๐Ÿ“‚ ๐Ÿ‘ฉโ€๐Ÿ’ป โš™๏ธ `File`.
!!! info
๐Ÿ“จ ๐Ÿ“‚ ๐Ÿ“, ๐Ÿฅ‡ โŽ <a href="https://andrew-d.github.io/python-multipart/" class="external-link" target="_blank">`python-multipart`</a>.
๐Ÿคถ โ“‚. `pip install python-multipart`.
๐Ÿ‘‰ โ†ฉ๏ธ ๐Ÿ“‚ ๐Ÿ“ ๐Ÿ“จ "๐Ÿ“จ ๐Ÿ’ฝ".
## ๐Ÿ—„ `File`
๐Ÿ—„ `File` &amp; `UploadFile` โšช๏ธโžก๏ธ `fastapi`:
```Python hl_lines="1"
{!../../../docs_src/request_files/tutorial001.py!}
```
## ๐Ÿ”ฌ `File` ๐Ÿ”ข
โœ ๐Ÿ“ ๐Ÿ”ข ๐ŸŽ ๐ŸŒŒ ๐Ÿ‘† ๐Ÿ”œ `Body` โš–๏ธ `Form`:
```Python hl_lines="7"
{!../../../docs_src/request_files/tutorial001.py!}
```
!!! info
`File` ๐ŸŽ“ ๐Ÿ‘ˆ ๐Ÿ˜– ๐Ÿ”— โšช๏ธโžก๏ธ `Form`.
โœ‹๏ธ ๐Ÿ’ญ ๐Ÿ‘ˆ ๐Ÿ•โ” ๐Ÿ‘† ๐Ÿ—„ `Query`, `Path`, `File` &amp; ๐ŸŽ โšช๏ธโžก๏ธ `fastapi`, ๐Ÿ‘ˆ ๐Ÿค™ ๐Ÿ”ข ๐Ÿ‘ˆ ๐Ÿ“จ ๐ŸŽ ๐ŸŽ“.
!!! tip
๐Ÿ“ฃ ๐Ÿ“ ๐Ÿ’ช, ๐Ÿ‘† ๐Ÿ’ช โš™๏ธ `File`, โ†ฉ๏ธ โช ๐Ÿ”ข ๐Ÿ”œ ๐Ÿ”ฌ ๐Ÿ”ข ๐Ÿ”ข โš–๏ธ ๐Ÿ’ช (๐ŸŽป) ๐Ÿ”ข.
๐Ÿ“ ๐Ÿ”œ ๐Ÿ“‚ "๐Ÿ“จ ๐Ÿ’ฝ".
๐Ÿšฅ ๐Ÿ‘† ๐Ÿ“ฃ ๐Ÿ†Ž ๐Ÿ‘† *โžก ๐Ÿ› ๏ธ ๐Ÿ”ข* ๐Ÿ”ข `bytes`, **FastAPI** ๐Ÿ”œ โœ ๐Ÿ“ ๐Ÿ‘† &amp; ๐Ÿ‘† ๐Ÿ”œ ๐Ÿ“จ ๐ŸŽš `bytes`.
โœ”๏ธ ๐Ÿคฏ ๐Ÿ‘ˆ ๐Ÿ‘‰ โ›“ ๐Ÿ‘ˆ ๐ŸŽ‚ ๐ŸŽš ๐Ÿ”œ ๐Ÿช ๐Ÿ’พ. ๐Ÿ‘‰ ๐Ÿ”œ ๐Ÿ‘ท ๐Ÿ‘ ๐Ÿคช ๐Ÿ“.
โœ‹๏ธ ๐Ÿ“ค ๐Ÿ“š ๐Ÿ’ผ โ” ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ’ฐ โšช๏ธโžก๏ธ โš™๏ธ `UploadFile`.
## ๐Ÿ“ ๐Ÿ”ข โฎ๏ธ `UploadFile`
๐Ÿ”ฌ ๐Ÿ“ ๐Ÿ”ข โฎ๏ธ ๐Ÿ†Ž `UploadFile`:
```Python hl_lines="12"
{!../../../docs_src/request_files/tutorial001.py!}
```
โš™๏ธ `UploadFile` โœ”๏ธ ๐Ÿ“š ๐Ÿ“ˆ ๐Ÿคญ `bytes`:
* ๐Ÿ‘† ๐Ÿšซ โœ”๏ธ โš™๏ธ `File()` ๐Ÿ”ข ๐Ÿ’ฒ ๐Ÿ”ข.
* โšซ๏ธ โš™๏ธ "๐Ÿงต" ๐Ÿ“:
* ๐Ÿ“ ๐Ÿช ๐Ÿ’พ ๐Ÿ†™ ๐Ÿ”† ๐Ÿ“ ๐Ÿ“‰, &amp; โฎ๏ธ ๐Ÿšถโ€โ™€๏ธ ๐Ÿ‘‰ ๐Ÿ“‰ โšซ๏ธ ๐Ÿ”œ ๐Ÿช ๐Ÿ’พ.
* ๐Ÿ‘‰ โ›“ ๐Ÿ‘ˆ โšซ๏ธ ๐Ÿ”œ ๐Ÿ‘ท ๐Ÿ‘ โญ• ๐Ÿ“ ๐Ÿ’– ๐Ÿ–ผ, ๐Ÿ“น, โญ• ๐Ÿ’ฑ, โ™’๏ธ. ๐Ÿต ๐Ÿ˜ฉ ๐ŸŒ ๐Ÿ’พ.
* ๐Ÿ‘† ๐Ÿ’ช ๐Ÿคš ๐Ÿ—ƒ โšช๏ธโžก๏ธ ๐Ÿ“‚ ๐Ÿ“.
* โšซ๏ธ โœ”๏ธ <a href="https://docs.python.org/3/glossary.html#term-file-like-object" class="external-link" target="_blank">๐Ÿ“-๐Ÿ’–</a> `async` ๐Ÿ”ข.
* โšซ๏ธ ๐ŸŽฆ โ˜‘ ๐Ÿ <a href="https://docs.python.org/3/library/tempfile.html#tempfile.SpooledTemporaryFile" class="external-link" target="_blank">`SpooledTemporaryFile`</a> ๐ŸŽš ๐Ÿ‘ˆ ๐Ÿ‘† ๐Ÿ’ช ๐Ÿšถโ€โ™€๏ธ ๐Ÿ”— ๐ŸŽ ๐Ÿ—ƒ ๐Ÿ‘ˆ โŒ› ๐Ÿ“-๐Ÿ’– ๐ŸŽš.
### `UploadFile`
`UploadFile` โœ”๏ธ ๐Ÿ“„ ๐Ÿ”ข:
* `filename`: `str` โฎ๏ธ โฎ๏ธ ๐Ÿ“ ๐Ÿ“› ๐Ÿ‘ˆ ๐Ÿ“‚ (โœ… `myimage.jpg`).
* `content_type`: `str` โฎ๏ธ ๐ŸŽš ๐Ÿ†Ž (๐Ÿ“ ๐Ÿ†Ž / ๐Ÿ“ป ๐Ÿ†Ž) (โœ… `image/jpeg`).
* `file`: <a href="https://docs.python.org/3/library/tempfile.html#tempfile.SpooledTemporaryFile" class="external-link" target="_blank">`SpooledTemporaryFile`</a> ( <a href="https://docs.python.org/3/glossary.html#term-file-like-object" class="external-link" target="_blank">๐Ÿ“-๐Ÿ’–</a> ๐ŸŽš). ๐Ÿ‘‰ โ˜‘ ๐Ÿ ๐Ÿ“ ๐Ÿ‘ˆ ๐Ÿ‘† ๐Ÿ’ช ๐Ÿšถโ€โ™€๏ธ ๐Ÿ”— ๐ŸŽ ๐Ÿ”ข โš–๏ธ ๐Ÿ—ƒ ๐Ÿ‘ˆ โŒ› "๐Ÿ“-๐Ÿ’–" ๐ŸŽš.
`UploadFile` โœ”๏ธ ๐Ÿ“„ `async` ๐Ÿ‘ฉโ€๐Ÿ”ฌ. ๐Ÿ‘ซ ๐ŸŒ ๐Ÿค™ ๐Ÿ”— ๐Ÿ“ ๐Ÿ‘ฉโ€๐Ÿ”ฌ ๐Ÿ”˜ (โš™๏ธ ๐Ÿ”— `SpooledTemporaryFile`).
* `write(data)`: โœ `data` (`str` โš–๏ธ `bytes`) ๐Ÿ“.
* `read(size)`: โœ `size` (`int`) ๐Ÿ”ข/๐Ÿฆน ๐Ÿ“.
* `seek(offset)`: ๐Ÿšถ ๐Ÿ”ข ๐Ÿง˜ `offset` (`int`) ๐Ÿ“.
* ๐Ÿคถ โ“‚., `await myfile.seek(0)` ๐Ÿ”œ ๐Ÿšถ โ–ถ๏ธ ๐Ÿ“.
* ๐Ÿ‘‰ โœด๏ธ โš  ๐Ÿšฅ ๐Ÿ‘† ๐Ÿƒ `await myfile.read()` ๐Ÿ• &amp; โคด๏ธ ๐Ÿ’ช โœ ๐ŸŽš ๐Ÿ”„.
* `close()`: ๐Ÿ” ๐Ÿ“.
๐ŸŒ ๐Ÿ‘ซ ๐Ÿ‘ฉโ€๐Ÿ”ฌ `async` ๐Ÿ‘ฉโ€๐Ÿ”ฌ, ๐Ÿ‘† ๐Ÿ’ช "โŒ›" ๐Ÿ‘ซ.
๐Ÿ–ผ, ๐Ÿ”˜ `async` *โžก ๐Ÿ› ๏ธ ๐Ÿ”ข* ๐Ÿ‘† ๐Ÿ’ช ๐Ÿคš ๐ŸŽš โฎ๏ธ:
```Python
contents = await myfile.read()
```
๐Ÿšฅ ๐Ÿ‘† ๐Ÿ”˜ ๐Ÿ˜ `def` *โžก ๐Ÿ› ๏ธ ๐Ÿ”ข*, ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ” `UploadFile.file` ๐Ÿ”—, ๐Ÿ–ผ:
```Python
contents = myfile.file.read()
```
!!! note "`async` ๐Ÿ“ก โ„น"
๐Ÿ•โ” ๐Ÿ‘† โš™๏ธ `async` ๐Ÿ‘ฉโ€๐Ÿ”ฌ, **FastAPI** ๐Ÿƒ ๐Ÿ“ ๐Ÿ‘ฉโ€๐Ÿ”ฌ ๐Ÿงต &amp; โŒ› ๐Ÿ‘ซ.
!!! note "๐Ÿ’ƒ ๐Ÿ“ก โ„น"
**FastAPI**'โ“‚ `UploadFile` ๐Ÿ˜– ๐Ÿ”— โšช๏ธโžก๏ธ **๐Ÿ’ƒ**'โ“‚ `UploadFile`, โœ‹๏ธ ๐Ÿšฎ ๐Ÿ’ช ๐Ÿ• โš’ โšซ๏ธ ๐Ÿ”— โฎ๏ธ **Pydantic** &amp; ๐ŸŽ ๐Ÿ• FastAPI.
## โšซ๏ธโ” "๐Ÿ“จ ๐Ÿ’ฝ"
๐ŸŒŒ ๐Ÿ•ธ ๐Ÿ“จ (`<form></form>`) ๐Ÿ“จ ๐Ÿ’ฝ ๐Ÿ’ฝ ๐Ÿ›Ž โš™๏ธ "๐ŸŽ" ๐Ÿ”ข ๐Ÿ‘ˆ ๐Ÿ“Š, โšซ๏ธ ๐ŸŽ โšช๏ธโžก๏ธ ๐ŸŽป.
**FastAPI** ๐Ÿ”œ โš’ ๐Ÿ’ญ โœ ๐Ÿ‘ˆ ๐Ÿ“Š โšช๏ธโžก๏ธ โ–ถ๏ธ๏ธ ๐Ÿฅ‰ โ†ฉ๏ธ ๐ŸŽป.
!!! note "๐Ÿ“ก โ„น"
๐Ÿ“Š โšช๏ธโžก๏ธ ๐Ÿ“จ ๐Ÿ›Ž ๐Ÿ—œ โš™๏ธ "๐Ÿ“ป ๐Ÿ†Ž" `application/x-www-form-urlencoded` ๐Ÿ•โ” โšซ๏ธ ๐Ÿšซ ๐Ÿ”Œ ๐Ÿ“.
โœ‹๏ธ ๐Ÿ•โ” ๐Ÿ“จ ๐Ÿ”Œ ๐Ÿ“, โšซ๏ธ ๐Ÿ—œ `multipart/form-data`. ๐Ÿšฅ ๐Ÿ‘† โš™๏ธ `File`, **FastAPI** ๐Ÿ”œ ๐Ÿ’ญ โšซ๏ธ โœ”๏ธ ๐Ÿคš ๐Ÿ“ โšช๏ธโžก๏ธ โ˜‘ ๐Ÿ• ๐Ÿ’ช.
๐Ÿšฅ ๐Ÿ‘† ๐Ÿ’š โœ ๐ŸŒ– ๐Ÿ”ƒ ๐Ÿ‘‰ ๐Ÿ”ข &amp; ๐Ÿ“จ ๐Ÿ‘, ๐Ÿ‘ณ <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/POST" class="external-link" target="_blank"><abbr title="Mozilla Developer Network">๐Ÿ‡</abbr> ๐Ÿ•ธ ๐Ÿฉบ <code>POST</code></a>.
!!! warning
๐Ÿ‘† ๐Ÿ’ช ๐Ÿ“ฃ ๐Ÿ’— `File` &amp; `Form` ๐Ÿ”ข *โžก ๐Ÿ› ๏ธ*, โœ‹๏ธ ๐Ÿ‘† ๐Ÿ’ช ๐Ÿšซ ๐Ÿ“ฃ `Body` ๐Ÿ‘ ๐Ÿ‘ˆ ๐Ÿ‘† โŒ› ๐Ÿ“จ ๐ŸŽป, ๐Ÿ“จ ๐Ÿ”œ โœ”๏ธ ๐Ÿ’ช ๐Ÿ—œ โš™๏ธ `multipart/form-data` โ†ฉ๏ธ `application/json`.
๐Ÿ‘‰ ๐Ÿšซ ๐Ÿšซ **FastAPI**, โšซ๏ธ ๐Ÿ• ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ” ๐Ÿ› ๏ธ.
## ๐Ÿ“ฆ ๐Ÿ“ ๐Ÿ“‚
๐Ÿ‘† ๐Ÿ’ช โš’ ๐Ÿ“ ๐Ÿ“ฆ โš™๏ธ ๐Ÿฉ ๐Ÿ†Ž โœ &amp; โš’ ๐Ÿ”ข ๐Ÿ’ฒ `None`:
=== "๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="9 17"
{!> ../../../docs_src/request_files/tutorial001_02.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.1๏ธโƒฃ0๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="7 14"
{!> ../../../docs_src/request_files/tutorial001_02_py310.py!}
```
## `UploadFile` โฎ๏ธ ๐ŸŒ– ๐Ÿ—ƒ
๐Ÿ‘† ๐Ÿ’ช โš™๏ธ `File()` โฎ๏ธ `UploadFile`, ๐Ÿ–ผ, โš’ ๐ŸŒ– ๐Ÿ—ƒ:
```Python hl_lines="13"
{!../../../docs_src/request_files/tutorial001_03.py!}
```
## ๐Ÿ’— ๐Ÿ“ ๐Ÿ“‚
โšซ๏ธ ๐Ÿ’ช ๐Ÿ“‚ ๐Ÿ“š ๐Ÿ“ ๐ŸŽ ๐Ÿ•ฐ.
๐Ÿ‘ซ ๐Ÿ”œ ๐Ÿ‘จโ€๐Ÿ’ผ ๐ŸŽ "๐Ÿ“จ ๐Ÿ‘" ๐Ÿ“จ โš™๏ธ "๐Ÿ“จ ๐Ÿ’ฝ".
โš™๏ธ ๐Ÿ‘ˆ, ๐Ÿ“ฃ ๐Ÿ“‡ `bytes` โš–๏ธ `UploadFile`:
=== "๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="10 15"
{!> ../../../docs_src/request_files/tutorial002.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.9๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="8 13"
{!> ../../../docs_src/request_files/tutorial002_py39.py!}
```
๐Ÿ‘† ๐Ÿ”œ ๐Ÿ“จ, ๐Ÿ“ฃ, `list` `bytes` โš–๏ธ `UploadFile`โ“‚.
!!! note "๐Ÿ“ก โ„น"
๐Ÿ‘† ๐Ÿ’ช โš™๏ธ `from starlette.responses import HTMLResponse`.
**FastAPI** ๐Ÿšš ๐ŸŽ `starlette.responses` `fastapi.responses` ๐Ÿช ๐Ÿ‘†, ๐Ÿ‘ฉโ€๐Ÿ’ป. โœ‹๏ธ ๐ŸŒ… ๐Ÿ’ช ๐Ÿ“จ ๐Ÿ‘Ÿ ๐Ÿ”— โšช๏ธโžก๏ธ ๐Ÿ’ƒ.
### ๐Ÿ’— ๐Ÿ“ ๐Ÿ“‚ โฎ๏ธ ๐ŸŒ– ๐Ÿ—ƒ
&amp; ๐ŸŽ ๐ŸŒŒ โญ, ๐Ÿ‘† ๐Ÿ’ช โš™๏ธ `File()` โš’ ๐ŸŒ– ๐Ÿ”ข, `UploadFile`:
=== "๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="18"
{!> ../../../docs_src/request_files/tutorial003.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.9๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="16"
{!> ../../../docs_src/request_files/tutorial003_py39.py!}
```
## ๐ŸŒƒ
โš™๏ธ `File`, `bytes`, &amp; `UploadFile` ๐Ÿ“ฃ ๐Ÿ“ ๐Ÿ“‚ ๐Ÿ“จ, ๐Ÿ“จ ๐Ÿ“จ ๐Ÿ’ฝ.

35
docs/em/docs/tutorial/request-forms-and-files.md

@ -0,0 +1,35 @@
# ๐Ÿ“จ ๐Ÿ“จ &amp; ๐Ÿ“
๐Ÿ‘† ๐Ÿ’ช ๐Ÿ”ฌ ๐Ÿ“ &amp; ๐Ÿ“จ ๐Ÿ‘ ๐ŸŽ ๐Ÿ•ฐ โš™๏ธ `File` &amp; `Form`.
!!! info
๐Ÿ“จ ๐Ÿ“‚ ๐Ÿ“ &amp; /โš–๏ธ ๐Ÿ“จ ๐Ÿ“Š, ๐Ÿฅ‡ โŽ <a href="https://andrew-d.github.io/python-multipart/" class="external-link" target="_blank">`python-multipart`</a>.
๐Ÿคถ โ“‚. `pip install python-multipart`.
## ๐Ÿ—„ `File` &amp; `Form`
```Python hl_lines="1"
{!../../../docs_src/request_forms_and_files/tutorial001.py!}
```
## ๐Ÿ”ฌ `File` &amp; `Form` ๐Ÿ”ข
โœ ๐Ÿ“ &amp; ๐Ÿ“จ ๐Ÿ”ข ๐ŸŽ ๐ŸŒŒ ๐Ÿ‘† ๐Ÿ”œ `Body` โš–๏ธ `Query`:
```Python hl_lines="8"
{!../../../docs_src/request_forms_and_files/tutorial001.py!}
```
๐Ÿ“ &amp; ๐Ÿ“จ ๐Ÿ‘ ๐Ÿ”œ ๐Ÿ“‚ ๐Ÿ“จ ๐Ÿ“Š &amp; ๐Ÿ‘† ๐Ÿ”œ ๐Ÿ“จ ๐Ÿ“ &amp; ๐Ÿ“จ ๐Ÿ‘.
&amp; ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ“ฃ ๐Ÿ“ `bytes` &amp; `UploadFile`.
!!! warning
๐Ÿ‘† ๐Ÿ’ช ๐Ÿ“ฃ ๐Ÿ’— `File` &amp; `Form` ๐Ÿ”ข *โžก ๐Ÿ› ๏ธ*, โœ‹๏ธ ๐Ÿ‘† ๐Ÿ’ช ๐Ÿšซ ๐Ÿ“ฃ `Body` ๐Ÿ‘ ๐Ÿ‘ˆ ๐Ÿ‘† โŒ› ๐Ÿ“จ ๐ŸŽป, ๐Ÿ“จ ๐Ÿ”œ โœ”๏ธ ๐Ÿ’ช ๐Ÿ—œ โš™๏ธ `multipart/form-data` โ†ฉ๏ธ `application/json`.
๐Ÿ‘‰ ๐Ÿšซ ๐Ÿšซ **FastAPI**, โšซ๏ธ ๐Ÿ• ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ” ๐Ÿ› ๏ธ.
## ๐ŸŒƒ
โš™๏ธ `File` &amp; `Form` ๐Ÿ‘ฏโ€โ™‚๏ธ ๐Ÿ•โ” ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ“จ ๐Ÿ’ฝ &amp; ๐Ÿ“ ๐ŸŽ ๐Ÿ“จ.

58
docs/em/docs/tutorial/request-forms.md

@ -0,0 +1,58 @@
# ๐Ÿ“จ ๐Ÿ’ฝ
๐Ÿ•โ” ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ“จ ๐Ÿ“จ ๐Ÿ‘ โ†ฉ๏ธ ๐ŸŽป, ๐Ÿ‘† ๐Ÿ’ช โš™๏ธ `Form`.
!!! info
โš™๏ธ ๐Ÿ“จ, ๐Ÿฅ‡ โŽ <a href="https://andrew-d.github.io/python-multipart/" class="external-link" target="_blank">`python-multipart`</a>.
๐Ÿคถ โ“‚. `pip install python-multipart`.
## ๐Ÿ—„ `Form`
๐Ÿ—„ `Form` โšช๏ธโžก๏ธ `fastapi`:
```Python hl_lines="1"
{!../../../docs_src/request_forms/tutorial001.py!}
```
## ๐Ÿ”ฌ `Form` ๐Ÿ”ข
โœ ๐Ÿ“จ ๐Ÿ”ข ๐ŸŽ ๐ŸŒŒ ๐Ÿ‘† ๐Ÿ”œ `Body` โš–๏ธ `Query`:
```Python hl_lines="7"
{!../../../docs_src/request_forms/tutorial001.py!}
```
๐Ÿ–ผ, 1๏ธโƒฃ ๐ŸŒŒ Oauth2๏ธโƒฃ ๐Ÿ”ง ๐Ÿ’ช โš™๏ธ (๐Ÿค™ "๐Ÿ” ๐Ÿ’ง") โšซ๏ธ โœ” ๐Ÿ“จ `username` &amp; `password` ๐Ÿ“จ ๐Ÿ‘.
<abbr title="specification">๐Ÿ”Œ</abbr> ๐Ÿšš ๐Ÿ‘ โšซ๏ธโ” ๐Ÿ“› `username` &amp; `password`, &amp; ๐Ÿ“จ ๐Ÿ“จ ๐Ÿ‘, ๐Ÿšซ ๐ŸŽป.
โฎ๏ธ `Form` ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ“ฃ ๐ŸŽ ๐Ÿ“ณ โฎ๏ธ `Body` (&amp; `Query`, `Path`, `Cookie`), ๐Ÿ”Œ ๐Ÿ”ฌ, ๐Ÿ–ผ, ๐Ÿ“› (โœ… `user-name` โ†ฉ๏ธ `username`), โ™’๏ธ.
!!! info
`Form` ๐ŸŽ“ ๐Ÿ‘ˆ ๐Ÿ˜– ๐Ÿ”— โšช๏ธโžก๏ธ `Body`.
!!! tip
๐Ÿ“ฃ ๐Ÿ“จ ๐Ÿ’ช, ๐Ÿ‘† ๐Ÿ’ช โš™๏ธ `Form` ๐ŸŽฏ, โ†ฉ๏ธ ๐Ÿต โšซ๏ธ ๐Ÿ”ข ๐Ÿ”œ ๐Ÿ”ฌ ๐Ÿ”ข ๐Ÿ”ข โš–๏ธ ๐Ÿ’ช (๐ŸŽป) ๐Ÿ”ข.
## ๐Ÿ”ƒ "๐Ÿ“จ ๐Ÿ‘"
๐ŸŒŒ ๐Ÿ•ธ ๐Ÿ“จ (`<form></form>`) ๐Ÿ“จ ๐Ÿ’ฝ ๐Ÿ’ฝ ๐Ÿ›Ž โš™๏ธ "๐ŸŽ" ๐Ÿ”ข ๐Ÿ‘ˆ ๐Ÿ“Š, โšซ๏ธ ๐ŸŽ โšช๏ธโžก๏ธ ๐ŸŽป.
**FastAPI** ๐Ÿ”œ โš’ ๐Ÿ’ญ โœ ๐Ÿ‘ˆ ๐Ÿ“Š โšช๏ธโžก๏ธ โ–ถ๏ธ๏ธ ๐Ÿฅ‰ โ†ฉ๏ธ ๐ŸŽป.
!!! note "๐Ÿ“ก โ„น"
๐Ÿ“Š โšช๏ธโžก๏ธ ๐Ÿ“จ ๐Ÿ›Ž ๐Ÿ—œ โš™๏ธ "๐Ÿ“ป ๐Ÿ†Ž" `application/x-www-form-urlencoded`.
โœ‹๏ธ ๐Ÿ•โ” ๐Ÿ“จ ๐Ÿ”Œ ๐Ÿ“, โšซ๏ธ ๐Ÿ—œ `multipart/form-data`. ๐Ÿ‘† ๐Ÿ”œ โœ ๐Ÿ”ƒ ๐Ÿšš ๐Ÿ“ โญ ๐Ÿ“ƒ.
๐Ÿšฅ ๐Ÿ‘† ๐Ÿ’š โœ ๐ŸŒ– ๐Ÿ”ƒ ๐Ÿ‘‰ ๐Ÿ”ข &amp; ๐Ÿ“จ ๐Ÿ‘, ๐Ÿ‘ณ <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/POST" class="external-link" target="_blank"><abbr title="Mozilla Developer Network">๐Ÿ‡</abbr> ๐Ÿ•ธ ๐Ÿฉบ <code>POST</code></a>.
!!! warning
๐Ÿ‘† ๐Ÿ’ช ๐Ÿ“ฃ ๐Ÿ’— `Form` ๐Ÿ”ข *โžก ๐Ÿ› ๏ธ*, โœ‹๏ธ ๐Ÿ‘† ๐Ÿ’ช ๐Ÿšซ ๐Ÿ“ฃ `Body` ๐Ÿ‘ ๐Ÿ‘ˆ ๐Ÿ‘† โŒ› ๐Ÿ“จ ๐ŸŽป, ๐Ÿ“จ ๐Ÿ”œ โœ”๏ธ ๐Ÿ’ช ๐Ÿ—œ โš™๏ธ `application/x-www-form-urlencoded` โ†ฉ๏ธ `application/json`.
๐Ÿ‘‰ ๐Ÿšซ ๐Ÿšซ **FastAPI**, โšซ๏ธ ๐Ÿ• ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ” ๐Ÿ› ๏ธ.
## ๐ŸŒƒ
โš™๏ธ `Form` ๐Ÿ“ฃ ๐Ÿ“จ ๐Ÿ’ฝ ๐Ÿ”ข ๐Ÿ”ข.

481
docs/em/docs/tutorial/response-model.md

@ -0,0 +1,481 @@
# ๐Ÿ“จ ๐Ÿท - ๐Ÿ“จ ๐Ÿ†Ž
๐Ÿ‘† ๐Ÿ’ช ๐Ÿ“ฃ ๐Ÿ†Ž โš™๏ธ ๐Ÿ“จ โœ *โžก ๐Ÿ› ๏ธ ๐Ÿ”ข* **๐Ÿ“จ ๐Ÿ†Ž**.
๐Ÿ‘† ๐Ÿ’ช โš™๏ธ **๐Ÿ†Ž โœ** ๐ŸŽ ๐ŸŒŒ ๐Ÿ‘† ๐Ÿ”œ ๐Ÿ”ข ๐Ÿ’ฝ ๐Ÿ”ข **๐Ÿ”ข**, ๐Ÿ‘† ๐Ÿ’ช โš™๏ธ Pydantic ๐Ÿท, ๐Ÿ“‡, ๐Ÿ“–, ๐Ÿ“Š ๐Ÿ’ฒ ๐Ÿ’– ๐Ÿ”ข, ๐ŸŽป, โ™’๏ธ.
=== "๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="18 23"
{!> ../../../docs_src/response_model/tutorial001_01.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.9๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="18 23"
{!> ../../../docs_src/response_model/tutorial001_01_py39.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.1๏ธโƒฃ0๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="16 21"
{!> ../../../docs_src/response_model/tutorial001_01_py310.py!}
```
FastAPI ๐Ÿ”œ โš™๏ธ ๐Ÿ‘‰ ๐Ÿ“จ ๐Ÿ†Ž:
* **โœ”** ๐Ÿ“จ ๐Ÿ’ฝ.
* ๐Ÿšฅ ๐Ÿ’ฝ โŒ (โœ… ๐Ÿ‘† โŒ ๐Ÿ‘), โšซ๏ธ โ›“ ๐Ÿ‘ˆ *๐Ÿ‘†* ๐Ÿ“ฑ ๐Ÿ“Ÿ ๐Ÿ’”, ๐Ÿšซ ๐Ÿ›ฌ โšซ๏ธโ” โšซ๏ธ ๐Ÿ”œ, &amp; โšซ๏ธ ๐Ÿ”œ ๐Ÿ“จ ๐Ÿ’ฝ โŒ โ†ฉ๏ธ ๐Ÿ›ฌ โŒ ๐Ÿ’ฝ. ๐Ÿ‘‰ ๐ŸŒŒ ๐Ÿ‘† &amp; ๐Ÿ‘† ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ’ช ๐ŸŽฏ ๐Ÿ‘ˆ ๐Ÿ‘ซ ๐Ÿ”œ ๐Ÿ“จ ๐Ÿ’ฝ &amp; ๐Ÿ’ฝ ๐Ÿ’  ๐Ÿ“ˆ.
* ๐Ÿšฎ **๐ŸŽป ๐Ÿ”—** ๐Ÿ“จ, ๐Ÿ—„ *โžก ๐Ÿ› ๏ธ*.
* ๐Ÿ‘‰ ๐Ÿ”œ โš™๏ธ **๐Ÿง ๐Ÿฉบ**.
* โšซ๏ธ ๐Ÿ”œ โš™๏ธ ๐Ÿง ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ“Ÿ โšก ๐Ÿงฐ.
โœ‹๏ธ ๐Ÿ† ๐Ÿฅˆ:
* โšซ๏ธ ๐Ÿ”œ **๐Ÿ“‰ &amp; โ›ฝ** ๐Ÿ”ข ๐Ÿ“Š โšซ๏ธโ” ๐Ÿ”ฌ ๐Ÿ“จ ๐Ÿ†Ž.
* ๐Ÿ‘‰ โœด๏ธ โš  **๐Ÿ’‚โ€โ™‚**, ๐Ÿ‘ฅ ๐Ÿ”œ ๐Ÿ‘€ ๐ŸŒ… ๐Ÿ‘ˆ ๐Ÿ”›.
## `response_model` ๐Ÿ”ข
๐Ÿ“ค ๐Ÿ’ผ ๐ŸŒโ” ๐Ÿ‘† ๐Ÿ’ช โš–๏ธ ๐Ÿ’š ๐Ÿ“จ ๐Ÿ’ฝ ๐Ÿ‘ˆ ๐Ÿšซ โšซ๏ธโ” โšซ๏ธโ” ๐Ÿ†Ž ๐Ÿ“ฃ.
๐Ÿ–ผ, ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ’š **๐Ÿ“จ ๐Ÿ“–** โš–๏ธ ๐Ÿ’ฝ ๐ŸŽš, โœ‹๏ธ **๐Ÿ“ฃ โšซ๏ธ Pydantic ๐Ÿท**. ๐Ÿ‘‰ ๐ŸŒŒ Pydantic ๐Ÿท ๐Ÿ”œ ๐ŸŒ ๐Ÿ’ฝ ๐Ÿงพ, ๐Ÿ”ฌ, โ™’๏ธ. ๐ŸŽš ๐Ÿ‘ˆ ๐Ÿ‘† ๐Ÿ“จ (โœ… ๐Ÿ“– โš–๏ธ ๐Ÿ’ฝ ๐ŸŽš).
๐Ÿšฅ ๐Ÿ‘† ๐Ÿšฎ ๐Ÿ“จ ๐Ÿ†Ž โœ, ๐Ÿงฐ &amp; ๐Ÿ‘จโ€๐ŸŽจ ๐Ÿ”œ ๐Ÿ˜ญ โฎ๏ธ (โ˜‘) โŒ ๐Ÿ’ฌ ๐Ÿ‘† ๐Ÿ‘ˆ ๐Ÿ‘† ๐Ÿ”ข ๐Ÿ›ฌ ๐Ÿ†Ž (โœ…#๏ธโƒฃ) ๐Ÿ‘ˆ ๐ŸŽ โšช๏ธโžก๏ธ โšซ๏ธโ” ๐Ÿ‘† ๐Ÿ“ฃ (โœ… Pydantic ๐Ÿท).
๐Ÿ“š ๐Ÿ’ผ, ๐Ÿ‘† ๐Ÿ’ช โš™๏ธ *โžก ๐Ÿ› ๏ธ ๐Ÿ‘จโ€๐ŸŽจ* ๐Ÿ”ข `response_model` โ†ฉ๏ธ ๐Ÿ“จ ๐Ÿ†Ž.
๐Ÿ‘† ๐Ÿ’ช โš™๏ธ `response_model` ๐Ÿ”ข ๐Ÿ™† *โžก ๐Ÿ› ๏ธ*:
* `@app.get()`
* `@app.post()`
* `@app.put()`
* `@app.delete()`
* โ™’๏ธ.
=== "๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="17 22 24-27"
{!> ../../../docs_src/response_model/tutorial001.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.9๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="17 22 24-27"
{!> ../../../docs_src/response_model/tutorial001_py39.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.1๏ธโƒฃ0๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="17 22 24-27"
{!> ../../../docs_src/response_model/tutorial001_py310.py!}
```
!!! note
๐Ÿ‘€ ๐Ÿ‘ˆ `response_model` ๐Ÿ”ข "๐Ÿ‘จโ€๐ŸŽจ" ๐Ÿ‘ฉโ€๐Ÿ”ฌ (`get`, `post`, โ™’๏ธ). ๐Ÿšซ ๐Ÿ‘† *โžก ๐Ÿ› ๏ธ ๐Ÿ”ข*, ๐Ÿ’– ๐ŸŒ ๐Ÿ”ข &amp; ๐Ÿ’ช.
`response_model` ๐Ÿ“จ ๐ŸŽ ๐Ÿ†Ž ๐Ÿ‘† ๐Ÿ”œ ๐Ÿ“ฃ Pydantic ๐Ÿท ๐Ÿ‘,, โšซ๏ธ ๐Ÿ’ช Pydantic ๐Ÿท, โœ‹๏ธ โšซ๏ธ ๐Ÿ’ช, โœ… `list` Pydantic ๐Ÿท, ๐Ÿ’– `List[Item]`.
FastAPI ๐Ÿ”œ โš™๏ธ ๐Ÿ‘‰ `response_model` ๐ŸŒ ๐Ÿ’ฝ ๐Ÿงพ, ๐Ÿ”ฌ, โ™’๏ธ. &amp; **๐Ÿ—œ &amp; โ›ฝ ๐Ÿ”ข ๐Ÿ“Š** ๐Ÿšฎ ๐Ÿ†Ž ๐Ÿ“„.
!!! tip
๐Ÿšฅ ๐Ÿ‘† โœ”๏ธ โš  ๐Ÿ†Ž โœ… ๐Ÿ‘† ๐Ÿ‘จโ€๐ŸŽจ, โœ, โ™’๏ธ, ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ“ฃ ๐Ÿ”ข ๐Ÿ“จ ๐Ÿ†Ž `Any`.
๐Ÿ‘ˆ ๐ŸŒŒ ๐Ÿ‘† ๐Ÿ’ฌ ๐Ÿ‘จโ€๐ŸŽจ ๐Ÿ‘ˆ ๐Ÿ‘† ๐Ÿ˜ซ ๐Ÿ›ฌ ๐Ÿ•ณ. โœ‹๏ธ FastAPI ๐Ÿ”œ ๐Ÿ’ฝ ๐Ÿงพ, ๐Ÿ”ฌ, ๐Ÿ–ฅ, โ™’๏ธ. โฎ๏ธ `response_model`.
### `response_model` ๐Ÿ“ซ
๐Ÿšฅ ๐Ÿ‘† ๐Ÿ“ฃ ๐Ÿ‘ฏโ€โ™‚๏ธ ๐Ÿ“จ ๐Ÿ†Ž &amp; `response_model`, `response_model` ๐Ÿ”œ โœŠ ๐Ÿ“ซ &amp; โš™๏ธ FastAPI.
๐Ÿ‘‰ ๐ŸŒŒ ๐Ÿ‘† ๐Ÿ’ช ๐Ÿšฎ โ˜‘ ๐Ÿ†Ž โœ ๐Ÿ‘† ๐Ÿ”ข ๐Ÿ•โ” ๐Ÿ‘† ๐Ÿ›ฌ ๐Ÿ†Ž ๐ŸŽ ๐ŸŒ˜ ๐Ÿ“จ ๐Ÿท, โš™๏ธ ๐Ÿ‘จโ€๐ŸŽจ &amp; ๐Ÿงฐ ๐Ÿ’– โœ. &amp; ๐Ÿ‘† ๐Ÿ’ช โœ”๏ธ FastAPI ๐Ÿ’ฝ ๐Ÿ”ฌ, ๐Ÿงพ, โ™’๏ธ. โš™๏ธ `response_model`.
๐Ÿ‘† ๐Ÿ’ช โš™๏ธ `response_model=None` โŽ ๐Ÿ— ๐Ÿ“จ ๐Ÿท ๐Ÿ‘ˆ *โžก ๐Ÿ› ๏ธ*, ๐Ÿ‘† 5๏ธโƒฃ๐Ÿ“† ๐Ÿ’ช โšซ๏ธ ๐Ÿšฅ ๐Ÿ‘† โŽ ๐Ÿ†Ž โœ ๐Ÿ‘œ ๐Ÿ‘ˆ ๐Ÿšซ โ˜‘ Pydantic ๐Ÿ‘, ๐Ÿ‘† ๐Ÿ”œ ๐Ÿ‘€ ๐Ÿ–ผ ๐Ÿ‘ˆ 1๏ธโƒฃ ๐Ÿ“„ ๐Ÿ”›.
## ๐Ÿ“จ ๐ŸŽ ๐Ÿ”ข ๐Ÿ’ฝ
๐Ÿ“ฅ ๐Ÿ‘ฅ ๐Ÿ“ฃ `UserIn` ๐Ÿท, โšซ๏ธ ๐Ÿ”œ ๐Ÿ”Œ ๐Ÿ”ข ๐Ÿ”:
=== "๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="9 11"
{!> ../../../docs_src/response_model/tutorial002.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.1๏ธโƒฃ0๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="7 9"
{!> ../../../docs_src/response_model/tutorial002_py310.py!}
```
!!! info
โš™๏ธ `EmailStr`, ๐Ÿฅ‡ โŽ <a href="https://github.com/JoshData/python-email-validator" class="external-link" target="_blank">`email_validator`</a>.
๐Ÿคถ โ“‚. `pip install email-validator`
โš–๏ธ `pip install pydantic[email]`.
&amp; ๐Ÿ‘ฅ โš™๏ธ ๐Ÿ‘‰ ๐Ÿท ๐Ÿ“ฃ ๐Ÿ‘† ๐Ÿ”ข &amp; ๐ŸŽ ๐Ÿท ๐Ÿ“ฃ ๐Ÿ‘† ๐Ÿ”ข:
=== "๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="18"
{!> ../../../docs_src/response_model/tutorial002.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.1๏ธโƒฃ0๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="16"
{!> ../../../docs_src/response_model/tutorial002_py310.py!}
```
๐Ÿ”œ, ๐Ÿ•โ” ๐Ÿ–ฅ ๐Ÿ— ๐Ÿ‘ฉโ€๐Ÿ’ป โฎ๏ธ ๐Ÿ”, ๐Ÿ› ๏ธ ๐Ÿ”œ ๐Ÿ“จ ๐ŸŽ ๐Ÿ” ๐Ÿ“จ.
๐Ÿ‘‰ ๐Ÿ’ผ, โšซ๏ธ ๐Ÿ’ช ๐Ÿšซ โš , โ†ฉ๏ธ โšซ๏ธ ๐ŸŽ ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ“จ ๐Ÿ”.
โœ‹๏ธ ๐Ÿšฅ ๐Ÿ‘ฅ โš™๏ธ ๐ŸŽ ๐Ÿท โž•1๏ธโƒฃ *โžก ๐Ÿ› ๏ธ*, ๐Ÿ‘ฅ ๐Ÿ’ช ๐Ÿ“จ ๐Ÿ‘† ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ” ๐Ÿ”  ๐Ÿ‘ฉโ€๐Ÿ’ป.
!!! danger
๐Ÿ™… ๐Ÿช โœ… ๐Ÿ” ๐Ÿ‘ฉโ€๐Ÿ’ป โš–๏ธ ๐Ÿ“จ โšซ๏ธ ๐Ÿ“จ ๐Ÿ’– ๐Ÿ‘‰, ๐Ÿšฅ ๐Ÿ‘† ๐Ÿ’ญ ๐ŸŒ โš  &amp; ๐Ÿ‘† ๐Ÿ’ญ โšซ๏ธโ” ๐Ÿ‘† ๐Ÿ”จ.
## ๐Ÿšฎ ๐Ÿ”ข ๐Ÿท
๐Ÿ‘ฅ ๐Ÿ’ช โ†ฉ๏ธ โœ ๐Ÿ”ข ๐Ÿท โฎ๏ธ ๐Ÿ”ข ๐Ÿ” &amp; ๐Ÿ”ข ๐Ÿท ๐Ÿต โšซ๏ธ:
=== "๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="9 11 16"
{!> ../../../docs_src/response_model/tutorial003.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.1๏ธโƒฃ0๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="9 11 16"
{!> ../../../docs_src/response_model/tutorial003_py310.py!}
```
๐Ÿ“ฅ, โœ‹๏ธ ๐Ÿ‘† *โžก ๐Ÿ› ๏ธ ๐Ÿ”ข* ๐Ÿ›ฌ ๐ŸŽ ๐Ÿ”ข ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ‘ˆ ๐Ÿ”Œ ๐Ÿ”:
=== "๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="24"
{!> ../../../docs_src/response_model/tutorial003.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.1๏ธโƒฃ0๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="24"
{!> ../../../docs_src/response_model/tutorial003_py310.py!}
```
...๐Ÿ‘ฅ ๐Ÿ“ฃ `response_model` ๐Ÿ‘† ๐Ÿท `UserOut`, ๐Ÿ‘ˆ ๐Ÿšซ ๐Ÿ”Œ ๐Ÿ”:
=== "๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="22"
{!> ../../../docs_src/response_model/tutorial003.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.1๏ธโƒฃ0๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="22"
{!> ../../../docs_src/response_model/tutorial003_py310.py!}
```
, **FastAPI** ๐Ÿ”œ โœŠ ๐Ÿ’… ๐Ÿ–ฅ ๐Ÿ‘… ๐ŸŒ ๐Ÿ’ฝ ๐Ÿ‘ˆ ๐Ÿšซ ๐Ÿ“ฃ ๐Ÿ”ข ๐Ÿท (โš™๏ธ Pydantic).
### `response_model` โš–๏ธ ๐Ÿ“จ ๐Ÿ†Ž
๐Ÿ‘‰ ๐Ÿ’ผ, โ†ฉ๏ธ 2๏ธโƒฃ ๐Ÿท ๐ŸŽ, ๐Ÿšฅ ๐Ÿ‘ฅ โœ ๐Ÿ”ข ๐Ÿ“จ ๐Ÿ†Ž `UserOut`, ๐Ÿ‘จโ€๐ŸŽจ &amp; ๐Ÿงฐ ๐Ÿ”œ ๐Ÿ˜ญ ๐Ÿ‘ˆ ๐Ÿ‘ฅ ๐Ÿ›ฌ โŒ ๐Ÿ†Ž, ๐Ÿ“š ๐ŸŽ ๐ŸŽ“.
๐Ÿ‘ˆ โšซ๏ธโ” ๐Ÿ‘‰ ๐Ÿ–ผ ๐Ÿ‘ฅ โœ”๏ธ ๐Ÿ“ฃ โšซ๏ธ `response_model` ๐Ÿ”ข.
...โœ‹๏ธ ๐Ÿ˜ฃ ๐Ÿ‘‚ ๐Ÿ”› ๐Ÿ‘€ โ” โŽ ๐Ÿ‘ˆ.
## ๐Ÿ“จ ๐Ÿ†Ž &amp; ๐Ÿ’ฝ ๐Ÿ–ฅ
โžก๏ธ ๐Ÿ˜ฃ โšช๏ธโžก๏ธ โฎ๏ธ ๐Ÿ–ผ. ๐Ÿ‘ฅ ๐Ÿ’š **โœ ๐Ÿ”ข โฎ๏ธ 1๏ธโƒฃ ๐Ÿ†Ž** โœ‹๏ธ ๐Ÿ“จ ๐Ÿ•ณ ๐Ÿ‘ˆ ๐Ÿ”Œ **๐ŸŒ… ๐Ÿ’ฝ**.
๐Ÿ‘ฅ ๐Ÿ’š FastAPI ๐Ÿšง **๐Ÿ–ฅ** ๐Ÿ“Š โš™๏ธ ๐Ÿ“จ ๐Ÿท.
โฎ๏ธ ๐Ÿ–ผ, โ†ฉ๏ธ ๐ŸŽ“ ๐ŸŽ, ๐Ÿ‘ฅ โœ”๏ธ โš™๏ธ `response_model` ๐Ÿ”ข. โœ‹๏ธ ๐Ÿ‘ˆ โ›“ ๐Ÿ‘ˆ ๐Ÿ‘ฅ ๐Ÿšซ ๐Ÿคš ๐Ÿ•โ€๐Ÿฆบ โšช๏ธโžก๏ธ ๐Ÿ‘จโ€๐ŸŽจ &amp; ๐Ÿงฐ โœ… ๐Ÿ”ข ๐Ÿ“จ ๐Ÿ†Ž.
โœ‹๏ธ ๐ŸŒ… ๐Ÿ’ผ ๐ŸŒโ” ๐Ÿ‘ฅ ๐Ÿ’ช ๐Ÿ•ณ ๐Ÿ’– ๐Ÿ‘‰, ๐Ÿ‘ฅ ๐Ÿ’š ๐Ÿท **โ›ฝ/โŽ** ๐Ÿ“Š ๐Ÿ‘‰ ๐Ÿ–ผ.
&amp; ๐Ÿ‘ˆ ๐Ÿ’ผ, ๐Ÿ‘ฅ ๐Ÿ’ช โš™๏ธ ๐ŸŽ“ &amp; ๐Ÿงฌ โœŠ ๐Ÿ“ˆ ๐Ÿ”ข **๐Ÿ†Ž โœ** ๐Ÿคš ๐Ÿ‘ ๐Ÿ•โ€๐Ÿฆบ ๐Ÿ‘จโ€๐ŸŽจ &amp; ๐Ÿงฐ, &amp; ๐Ÿคš FastAPI **๐Ÿ’ฝ ๐Ÿ–ฅ**.
=== "๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="9-13 15-16 20"
{!> ../../../docs_src/response_model/tutorial003_01.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.1๏ธโƒฃ0๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="7-10 13-14 18"
{!> ../../../docs_src/response_model/tutorial003_01_py310.py!}
```
โฎ๏ธ ๐Ÿ‘‰, ๐Ÿ‘ฅ ๐Ÿคš ๐Ÿญ ๐Ÿ•โ€๐Ÿฆบ, โšช๏ธโžก๏ธ ๐Ÿ‘จโ€๐ŸŽจ &amp; โœ ๐Ÿ‘‰ ๐Ÿ“Ÿ โ˜‘ โš– ๐Ÿ†Ž, โœ‹๏ธ ๐Ÿ‘ฅ ๐Ÿคš ๐Ÿ’ฝ ๐Ÿ–ฅ โšช๏ธโžก๏ธ FastAPI.
โ” ๐Ÿ”จ ๐Ÿ‘‰ ๐Ÿ‘ท โ“ โžก๏ธ โœ… ๐Ÿ‘ˆ ๐Ÿ‘…. ๐Ÿ‘ถ
### ๐Ÿ†Ž โœ &amp; ๐Ÿญ
๐Ÿฅ‡ โžก๏ธ ๐Ÿ‘€ โ” ๐Ÿ‘จโ€๐ŸŽจ, โœ &amp; ๐ŸŽ ๐Ÿงฐ ๐Ÿ”œ ๐Ÿ‘€ ๐Ÿ‘‰.
`BaseUser` โœ”๏ธ ๐Ÿงข ๐Ÿ‘. โคด๏ธ `UserIn` ๐Ÿ˜– โšช๏ธโžก๏ธ `BaseUser` &amp; ๐Ÿšฎ `password` ๐Ÿ‘,, โšซ๏ธ ๐Ÿ”œ ๐Ÿ”Œ ๐ŸŒ ๐Ÿ‘ โšช๏ธโžก๏ธ ๐Ÿ‘ฏโ€โ™‚๏ธ ๐Ÿท.
๐Ÿ‘ฅ โœ ๐Ÿ”ข ๐Ÿ“จ ๐Ÿ†Ž `BaseUser`, โœ‹๏ธ ๐Ÿ‘ฅ ๐Ÿค™ ๐Ÿ›ฌ `UserIn` ๐Ÿ‘.
๐Ÿ‘จโ€๐ŸŽจ, โœ, &amp; ๐ŸŽ ๐Ÿงฐ ๐Ÿ† ๐Ÿšซ ๐Ÿ˜ญ ๐Ÿ”ƒ ๐Ÿ‘‰ โ†ฉ๏ธ, โŒจ โš–, `UserIn` ๐Ÿฟ `BaseUser`, โ” โ›“ โšซ๏ธ *โ˜‘* ๐Ÿ†Ž ๐Ÿ•โ” โšซ๏ธโ” โŒ› ๐Ÿ•ณ ๐Ÿ‘ˆ `BaseUser`.
### FastAPI ๐Ÿ’ฝ ๐Ÿ–ฅ
๐Ÿ”œ, FastAPI, โšซ๏ธ ๐Ÿ”œ ๐Ÿ‘€ ๐Ÿ“จ ๐Ÿ†Ž &amp; โš’ ๐Ÿ’ญ ๐Ÿ‘ˆ โšซ๏ธโ” ๐Ÿ‘† ๐Ÿ“จ ๐Ÿ”Œ **๐Ÿ•ด** ๐Ÿ‘ ๐Ÿ‘ˆ ๐Ÿ“ฃ ๐Ÿ†Ž.
FastAPI ๐Ÿ”จ ๐Ÿ“š ๐Ÿ‘œ ๐Ÿ”˜ โฎ๏ธ Pydantic โš’ ๐Ÿ’ญ ๐Ÿ‘ˆ ๐Ÿ“š ๐ŸŽ ๐Ÿšซ ๐ŸŽ“ ๐Ÿงฌ ๐Ÿšซ โš™๏ธ ๐Ÿ“จ ๐Ÿ’ฝ ๐Ÿ–ฅ, โช ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ”š ๐Ÿ†™ ๐Ÿ›ฌ ๐ŸŒ… ๐ŸŒ… ๐Ÿ’ฝ ๐ŸŒ˜ โšซ๏ธโ” ๐Ÿ‘† ๐Ÿ“ˆ.
๐Ÿ‘‰ ๐ŸŒŒ, ๐Ÿ‘† ๐Ÿ’ช ๐Ÿคš ๐Ÿ† ๐Ÿ‘ฏโ€โ™‚๏ธ ๐ŸŒ: ๐Ÿ†Ž โœ โฎ๏ธ **๐Ÿญ ๐Ÿ•โ€๐Ÿฆบ** &amp; **๐Ÿ’ฝ ๐Ÿ–ฅ**.
## ๐Ÿ‘€ โšซ๏ธ ๐Ÿฉบ
๐Ÿ•โ” ๐Ÿ‘† ๐Ÿ‘€ ๐Ÿง ๐Ÿฉบ, ๐Ÿ‘† ๐Ÿ’ช โœ… ๐Ÿ‘ˆ ๐Ÿ”ข ๐Ÿท &amp; ๐Ÿ”ข ๐Ÿท ๐Ÿ”œ ๐Ÿ‘ฏโ€โ™‚๏ธ โœ”๏ธ ๐Ÿ‘ซ ๐Ÿ‘ ๐ŸŽป ๐Ÿ”—:
<img src="/img/tutorial/response-model/image01.png">
&amp; ๐Ÿ‘ฏโ€โ™‚๏ธ ๐Ÿท ๐Ÿ”œ โš™๏ธ ๐ŸŽ“ ๐Ÿ› ๏ธ ๐Ÿงพ:
<img src="/img/tutorial/response-model/image02.png">
## ๐ŸŽ ๐Ÿ“จ ๐Ÿ†Ž โœ
๐Ÿ“ค 5๏ธโƒฃ๐Ÿ“† ๐Ÿ’ผ ๐ŸŒโ” ๐Ÿ‘† ๐Ÿ“จ ๐Ÿ•ณ ๐Ÿ‘ˆ ๐Ÿšซ โ˜‘ Pydantic ๐Ÿ‘ &amp; ๐Ÿ‘† โœ โšซ๏ธ ๐Ÿ”ข, ๐Ÿ•ด ๐Ÿคš ๐Ÿ•โ€๐Ÿฆบ ๐Ÿšš ๐Ÿญ (๐Ÿ‘จโ€๐ŸŽจ, โœ, โ™’๏ธ).
### ๐Ÿ“จ ๐Ÿ“จ ๐Ÿ”—
๐Ÿ† โš  ๐Ÿ’ผ ๐Ÿ”œ [๐Ÿ›ฌ ๐Ÿ“จ ๐Ÿ”— ๐Ÿ”ฌ โช ๐Ÿง ๐Ÿฉบ](../advanced/response-directly.md){.internal-link target=_blank}.
```Python hl_lines="8 10-11"
{!> ../../../docs_src/response_model/tutorial003_02.py!}
```
๐Ÿ‘‰ ๐Ÿ™… ๐Ÿ’ผ ๐Ÿต ๐Ÿ” FastAPI โ†ฉ๏ธ ๐Ÿ“จ ๐Ÿ†Ž โœ ๐ŸŽ“ (โš–๏ธ ๐Ÿฟ) `Response`.
&amp; ๐Ÿงฐ ๐Ÿ”œ ๐Ÿ˜„ โ†ฉ๏ธ ๐Ÿ‘ฏโ€โ™‚๏ธ `RedirectResponse` &amp; `JSONResponse` ๐Ÿฟ `Response`, ๐Ÿ†Ž โœ โ˜‘.
### โœ ๐Ÿ“จ ๐Ÿฟ
๐Ÿ‘† ๐Ÿ’ช โš™๏ธ ๐Ÿฟ `Response` ๐Ÿ†Ž โœ:
```Python hl_lines="8-9"
{!> ../../../docs_src/response_model/tutorial003_03.py!}
```
๐Ÿ‘‰ ๐Ÿ”œ ๐Ÿ‘ท โ†ฉ๏ธ `RedirectResponse` ๐Ÿฟ `Response`, &amp; FastAPI ๐Ÿ”œ ๐Ÿ” ๐Ÿต ๐Ÿ‘‰ ๐Ÿ™… ๐Ÿ’ผ.
### โŒ ๐Ÿ“จ ๐Ÿ†Ž โœ
โœ‹๏ธ ๐Ÿ•โ” ๐Ÿ‘† ๐Ÿ“จ ๐ŸŽ โŒ ๐ŸŽš ๐Ÿ‘ˆ ๐Ÿšซ โ˜‘ Pydantic ๐Ÿ†Ž (โœ… ๐Ÿ’ฝ ๐ŸŽš) &amp; ๐Ÿ‘† โœ โšซ๏ธ ๐Ÿ’– ๐Ÿ‘ˆ ๐Ÿ”ข, FastAPI ๐Ÿ”œ ๐Ÿ”„ โœ Pydantic ๐Ÿ“จ ๐Ÿท โšช๏ธโžก๏ธ ๐Ÿ‘ˆ ๐Ÿ†Ž โœ, &amp; ๐Ÿ”œ โŒ.
๐ŸŽ ๐Ÿ”œ ๐Ÿ”จ ๐Ÿšฅ ๐Ÿ‘† โœ”๏ธ ๐Ÿ•ณ ๐Ÿ’– <abbr title='A union between multiple types means "any of these types".'>๐Ÿ‡ช๐Ÿ‡บ</abbr> ๐Ÿ–– ๐ŸŽ ๐Ÿ†Ž ๐ŸŒโ” 1๏ธโƒฃ โš–๏ธ ๐ŸŒ… ๐Ÿ‘ซ ๐Ÿšซ โ˜‘ Pydantic ๐Ÿ†Ž, ๐Ÿ–ผ ๐Ÿ‘‰ ๐Ÿ”œ โŒ ๐Ÿ‘ถ:
=== "๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="10"
{!> ../../../docs_src/response_model/tutorial003_04.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.1๏ธโƒฃ0๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="8"
{!> ../../../docs_src/response_model/tutorial003_04_py310.py!}
```
...๐Ÿ‘‰ โŒ โ†ฉ๏ธ ๐Ÿ†Ž โœ ๐Ÿšซ Pydantic ๐Ÿ†Ž &amp; ๐Ÿšซ ๐Ÿ‘ `Response` ๐ŸŽ“ โš–๏ธ ๐Ÿฟ, โšซ๏ธ ๐Ÿ‡ช๐Ÿ‡บ (๐Ÿ™† 2๏ธโƒฃ) ๐Ÿ–– `Response` &amp; `dict`.
### โŽ ๐Ÿ“จ ๐Ÿท
โ–ถ๏ธ โšช๏ธโžก๏ธ ๐Ÿ–ผ ๐Ÿ”›, ๐Ÿ‘† 5๏ธโƒฃ๐Ÿ“† ๐Ÿšซ ๐Ÿ’š โœ”๏ธ ๐Ÿ”ข ๐Ÿ’ฝ ๐Ÿ”ฌ, ๐Ÿงพ, ๐Ÿ–ฅ, โ™’๏ธ. ๐Ÿ‘ˆ ๐ŸŽญ FastAPI.
โœ‹๏ธ ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ’š ๐Ÿšง ๐Ÿ“จ ๐Ÿ†Ž โœ ๐Ÿ”ข ๐Ÿคš ๐Ÿ•โ€๐Ÿฆบ โšช๏ธโžก๏ธ ๐Ÿงฐ ๐Ÿ’– ๐Ÿ‘จโ€๐ŸŽจ &amp; ๐Ÿ†Ž โ˜‘ (โœ… โœ).
๐Ÿ‘‰ ๐Ÿ’ผ, ๐Ÿ‘† ๐Ÿ’ช โŽ ๐Ÿ“จ ๐Ÿท โšก โš’ `response_model=None`:
=== "๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="9"
{!> ../../../docs_src/response_model/tutorial003_05.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.1๏ธโƒฃ0๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="7"
{!> ../../../docs_src/response_model/tutorial003_05_py310.py!}
```
๐Ÿ‘‰ ๐Ÿ”œ โš’ FastAPI ๐Ÿšถ ๐Ÿ“จ ๐Ÿท โšก &amp; ๐Ÿ‘ˆ ๐ŸŒŒ ๐Ÿ‘† ๐Ÿ’ช โœ”๏ธ ๐Ÿ™† ๐Ÿ“จ ๐Ÿ†Ž โœ ๐Ÿ‘† ๐Ÿ’ช ๐Ÿต โšซ๏ธ ๐Ÿค• ๐Ÿ‘† FastAPI ๐Ÿˆธ. ๐Ÿ‘ถ
## ๐Ÿ“จ ๐Ÿท ๐Ÿ”ข ๐Ÿ”ข
๐Ÿ‘† ๐Ÿ“จ ๐Ÿท ๐Ÿ’ช โœ”๏ธ ๐Ÿ”ข ๐Ÿ’ฒ, ๐Ÿ’–:
=== "๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="11 13-14"
{!> ../../../docs_src/response_model/tutorial004.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.9๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="11 13-14"
{!> ../../../docs_src/response_model/tutorial004_py39.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.1๏ธโƒฃ0๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="9 11-12"
{!> ../../../docs_src/response_model/tutorial004_py310.py!}
```
* `description: Union[str, None] = None` (โš–๏ธ `str | None = None` ๐Ÿ 3๏ธโƒฃ.1๏ธโƒฃ0๏ธโƒฃ) โœ”๏ธ ๐Ÿ”ข `None`.
* `tax: float = 10.5` โœ”๏ธ ๐Ÿ”ข `10.5`.
* `tags: List[str] = []` ๐Ÿ”ข ๐Ÿ› ๐Ÿ“‡: `[]`.
โœ‹๏ธ ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ’š ๐Ÿšซ ๐Ÿ‘ซ โšช๏ธโžก๏ธ ๐Ÿ ๐Ÿšฅ ๐Ÿ‘ซ ๐Ÿšซ ๐Ÿค™ ๐Ÿช.
๐Ÿ–ผ, ๐Ÿšฅ ๐Ÿ‘† โœ”๏ธ ๐Ÿท โฎ๏ธ ๐Ÿ“š ๐Ÿ“ฆ ๐Ÿ”ข โ˜ ๐Ÿ’ฝ, โœ‹๏ธ ๐Ÿ‘† ๐Ÿšซ ๐Ÿ’š ๐Ÿ“จ ๐Ÿ“ถ ๐Ÿ“ ๐ŸŽป ๐Ÿ“จ ๐ŸŒ• ๐Ÿ”ข ๐Ÿ’ฒ.
### โš™๏ธ `response_model_exclude_unset` ๐Ÿ”ข
๐Ÿ‘† ๐Ÿ’ช โš’ *โžก ๐Ÿ› ๏ธ ๐Ÿ‘จโ€๐ŸŽจ* ๐Ÿ”ข `response_model_exclude_unset=True`:
=== "๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="24"
{!> ../../../docs_src/response_model/tutorial004.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.9๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="24"
{!> ../../../docs_src/response_model/tutorial004_py39.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.1๏ธโƒฃ0๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="22"
{!> ../../../docs_src/response_model/tutorial004_py310.py!}
```
&amp; ๐Ÿ‘ˆ ๐Ÿ”ข ๐Ÿ’ฒ ๐Ÿ† ๐Ÿšซ ๐Ÿ”Œ ๐Ÿ“จ, ๐Ÿ•ด ๐Ÿ’ฒ ๐Ÿค™ โš’.
, ๐Ÿšฅ ๐Ÿ‘† ๐Ÿ“จ ๐Ÿ“จ ๐Ÿ‘ˆ *โžก ๐Ÿ› ๏ธ* ๐Ÿฌ โฎ๏ธ ๐Ÿ†” `foo`, ๐Ÿ“จ (๐Ÿšซ โœ… ๐Ÿ”ข ๐Ÿ’ฒ) ๐Ÿ”œ:
```JSON
{
"name": "Foo",
"price": 50.2
}
```
!!! info
FastAPI โš™๏ธ Pydantic ๐Ÿท `.dict()` โฎ๏ธ <a href="https://pydantic-docs.helpmanual.io/usage/exporting_models/#modeldict" class="external-link" target="_blank">๐Ÿšฎ `exclude_unset` ๐Ÿ”ข</a> ๐Ÿ† ๐Ÿ‘‰.
!!! info
๐Ÿ‘† ๐Ÿ’ช โš™๏ธ:
* `response_model_exclude_defaults=True`
* `response_model_exclude_none=True`
๐Ÿ”ฌ <a href="https://pydantic-docs.helpmanual.io/usage/exporting_models/#modeldict" class="external-link" target="_blank">Pydantic ๐Ÿฉบ</a> `exclude_defaults` &amp; `exclude_none`.
#### ๐Ÿ“Š โฎ๏ธ ๐Ÿ’ฒ ๐Ÿ‘ โฎ๏ธ ๐Ÿ”ข
โœ‹๏ธ ๐Ÿšฅ ๐Ÿ‘† ๐Ÿ“Š โœ”๏ธ ๐Ÿ’ฒ ๐Ÿท ๐Ÿ‘ โฎ๏ธ ๐Ÿ”ข ๐Ÿ’ฒ, ๐Ÿ’– ๐Ÿฌ โฎ๏ธ ๐Ÿ†” `bar`:
```Python hl_lines="3 5"
{
"name": "Bar",
"description": "The bartenders",
"price": 62,
"tax": 20.2
}
```
๐Ÿ‘ซ ๐Ÿ”œ ๐Ÿ”Œ ๐Ÿ“จ.
#### ๐Ÿ“Š โฎ๏ธ ๐ŸŽ ๐Ÿ’ฒ ๐Ÿ”ข
๐Ÿšฅ ๐Ÿ“Š โœ”๏ธ ๐ŸŽ ๐Ÿ’ฒ ๐Ÿ”ข ๐Ÿ•, ๐Ÿ’– ๐Ÿฌ โฎ๏ธ ๐Ÿ†” `baz`:
```Python hl_lines="3 5-6"
{
"name": "Baz",
"description": None,
"price": 50.2,
"tax": 10.5,
"tags": []
}
```
FastAPI ๐Ÿ™ƒ ๐Ÿฅƒ (๐Ÿค™, Pydantic ๐Ÿ™ƒ ๐Ÿฅƒ) ๐Ÿค” ๐Ÿ‘ˆ, โœ‹๏ธ `description`, `tax`, &amp; `tags` โœ”๏ธ ๐ŸŽ ๐Ÿ’ฒ ๐Ÿ”ข, ๐Ÿ‘ซ โš’ ๐ŸŽฏ (โ†ฉ๏ธ โœŠ โšช๏ธโžก๏ธ ๐Ÿ”ข).
, ๐Ÿ‘ซ ๐Ÿ”œ ๐Ÿ”Œ ๐ŸŽป ๐Ÿ“จ.
!!! tip
๐Ÿ‘€ ๐Ÿ‘ˆ ๐Ÿ”ข ๐Ÿ’ฒ ๐Ÿ’ช ๐Ÿ•ณ, ๐Ÿšซ ๐Ÿ•ด `None`.
๐Ÿ‘ซ ๐Ÿ’ช ๐Ÿ“‡ (`[]`), `float` `10.5`, โ™’๏ธ.
### `response_model_include` &amp; `response_model_exclude`
๐Ÿ‘† ๐Ÿ’ช โš™๏ธ *โžก ๐Ÿ› ๏ธ ๐Ÿ‘จโ€๐ŸŽจ* ๐Ÿ”ข `response_model_include` &amp; `response_model_exclude`.
๐Ÿ‘ซ โœŠ `set` `str` โฎ๏ธ ๐Ÿ“› ๐Ÿ”ข ๐Ÿ”Œ (โŽ ๐ŸŽ‚) โš–๏ธ ๐Ÿšซ (โœ… ๐ŸŽ‚).
๐Ÿ‘‰ ๐Ÿ’ช โš™๏ธ โฉ โŒจ ๐Ÿšฅ ๐Ÿ‘† โœ”๏ธ ๐Ÿ•ด 1๏ธโƒฃ Pydantic ๐Ÿท &amp; ๐Ÿ’š โŽ ๐Ÿ’ฝ โšช๏ธโžก๏ธ ๐Ÿ”ข.
!!! tip
โœ‹๏ธ โšซ๏ธ ๐Ÿ‘ โš™๏ธ ๐Ÿ’ญ ๐Ÿ”›, โš™๏ธ ๐Ÿ’— ๐ŸŽ“, โ†ฉ๏ธ ๐Ÿ‘ซ ๐Ÿ”ข.
๐Ÿ‘‰ โ†ฉ๏ธ ๐ŸŽป ๐Ÿ”— ๐Ÿ— ๐Ÿ‘† ๐Ÿ“ฑ ๐Ÿ—„ (&amp; ๐Ÿฉบ) ๐Ÿ”œ 1๏ธโƒฃ ๐Ÿ ๐Ÿท, ๐Ÿšฅ ๐Ÿ‘† โš™๏ธ `response_model_include` โš–๏ธ `response_model_exclude` ๐Ÿšซ ๐Ÿ”ข.
๐Ÿ‘‰ โœ” `response_model_by_alias` ๐Ÿ‘ˆ ๐Ÿ‘ท โžก.
=== "๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="31 37"
{!> ../../../docs_src/response_model/tutorial005.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.1๏ธโƒฃ0๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="29 35"
{!> ../../../docs_src/response_model/tutorial005_py310.py!}
```
!!! tip
โ• `{"name", "description"}` โœ `set` โฎ๏ธ ๐Ÿ“š 2๏ธโƒฃ ๐Ÿ’ฒ.
โšซ๏ธ ๐ŸŒ“ `set(["name", "description"])`.
#### โš™๏ธ `list`โ“‚ โ†ฉ๏ธ `set`โ“‚
๐Ÿšฅ ๐Ÿ‘† ๐Ÿ’ญ โš™๏ธ `set` &amp; โš™๏ธ `list` โš–๏ธ `tuple` โ†ฉ๏ธ, FastAPI ๐Ÿ”œ ๐Ÿ—œ โšซ๏ธ `set` &amp; โšซ๏ธ ๐Ÿ”œ ๐Ÿ‘ท โ˜‘:
=== "๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="31 37"
{!> ../../../docs_src/response_model/tutorial006.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.1๏ธโƒฃ0๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="29 35"
{!> ../../../docs_src/response_model/tutorial006_py310.py!}
```
## ๐ŸŒƒ
โš™๏ธ *โžก ๐Ÿ› ๏ธ ๐Ÿ‘จโ€๐ŸŽจ* ๐Ÿ”ข `response_model` ๐Ÿ”ฌ ๐Ÿ“จ ๐Ÿท &amp; โœด๏ธ ๐Ÿšš ๐Ÿ“ข ๐Ÿ’ฝ โ›ฝ ๐Ÿ‘….
โš™๏ธ `response_model_exclude_unset` ๐Ÿ“จ ๐Ÿ•ด ๐Ÿ’ฒ ๐ŸŽฏ โš’.

89
docs/em/docs/tutorial/response-status-code.md

@ -0,0 +1,89 @@
# ๐Ÿ“จ ๐Ÿ‘” ๐Ÿ“Ÿ
๐ŸŽ ๐ŸŒŒ ๐Ÿ‘† ๐Ÿ’ช โœ” ๐Ÿ“จ ๐Ÿท, ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ“ฃ ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ” ๐Ÿ‘” ๐Ÿ“Ÿ โš™๏ธ ๐Ÿ“จ โฎ๏ธ ๐Ÿ”ข `status_code` ๐Ÿ™† *โžก ๐Ÿ› ๏ธ*:
* `@app.get()`
* `@app.post()`
* `@app.put()`
* `@app.delete()`
* โ™’๏ธ.
```Python hl_lines="6"
{!../../../docs_src/response_status_code/tutorial001.py!}
```
!!! note
๐Ÿ‘€ ๐Ÿ‘ˆ `status_code` ๐Ÿ”ข "๐Ÿ‘จโ€๐ŸŽจ" ๐Ÿ‘ฉโ€๐Ÿ”ฌ (`get`, `post`, โ™’๏ธ). ๐Ÿšซ ๐Ÿ‘† *โžก ๐Ÿ› ๏ธ ๐Ÿ”ข*, ๐Ÿ’– ๐ŸŒ ๐Ÿ”ข &amp; ๐Ÿ’ช.
`status_code` ๐Ÿ”ข ๐Ÿ“จ ๐Ÿ”ข โฎ๏ธ ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ” ๐Ÿ‘” ๐Ÿ“Ÿ.
!!! info
`status_code` ๐Ÿ’ช ๐Ÿ‘ ๐Ÿ“จ `IntEnum`, โœ… ๐Ÿ <a href="https://docs.python.org/3/library/http.html#http.HTTPStatus" class="external-link" target="_blank">`http.HTTPStatus`</a>.
โšซ๏ธ ๐Ÿ”œ:
* ๐Ÿ“จ ๐Ÿ‘ˆ ๐Ÿ‘” ๐Ÿ“Ÿ ๐Ÿ“จ.
* ๐Ÿ“„ โšซ๏ธ โœ… ๐Ÿ—„ ๐Ÿ”— ( &amp; , ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ”ข):
<img src="/img/tutorial/response-status-code/image01.png">
!!! note
๐Ÿ“จ ๐Ÿ“Ÿ (๐Ÿ‘€ โญ ๐Ÿ“„) ๐ŸŽฆ ๐Ÿ‘ˆ ๐Ÿ“จ ๐Ÿ”จ ๐Ÿšซ โœ”๏ธ ๐Ÿ’ช.
FastAPI ๐Ÿ’ญ ๐Ÿ‘‰, &amp; ๐Ÿ”œ ๐Ÿญ ๐Ÿ—„ ๐Ÿฉบ ๐Ÿ‘ˆ ๐Ÿ‡ต๐Ÿ‡ธ ๐Ÿ“ค ๐Ÿ™…โ€โ™‚ ๐Ÿ“จ ๐Ÿ’ช.
## ๐Ÿ”ƒ ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ” ๐Ÿ‘” ๐Ÿ“Ÿ
!!! note
๐Ÿšฅ ๐Ÿ‘† โช ๐Ÿ’ญ โšซ๏ธโ” ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ” ๐Ÿ‘” ๐Ÿ“Ÿ, ๐Ÿšถ โญ ๐Ÿ“„.
๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ”, ๐Ÿ‘† ๐Ÿ“จ ๐Ÿ”ข ๐Ÿ‘” ๐Ÿ“Ÿ 3๏ธโƒฃ 9๏ธโƒฃ ๐Ÿ• ๐Ÿ“จ.
๐Ÿ‘ซ ๐Ÿ‘” ๐Ÿ“Ÿ โœ”๏ธ ๐Ÿ“› ๐Ÿ”— ๐Ÿค” ๐Ÿ‘ซ, โœ‹๏ธ โš  ๐Ÿ• ๐Ÿ”ข.
๐Ÿ“:
* `100` &amp; ๐Ÿ”› "โ„น". ๐Ÿ‘† ๐Ÿ›Ž โš™๏ธ ๐Ÿ‘ซ ๐Ÿ”—. ๐Ÿ“จ โฎ๏ธ ๐Ÿ‘ซ ๐Ÿ‘” ๐Ÿ“Ÿ ๐Ÿšซ๐Ÿ”œ โœ”๏ธ ๐Ÿ’ช.
* **`200`** &amp; ๐Ÿ”› "๐Ÿ†" ๐Ÿ“จ. ๐Ÿ‘ซ ๐Ÿ• ๐Ÿ‘† ๐Ÿ”œ โš™๏ธ ๐Ÿ†.
* `200` ๐Ÿ”ข ๐Ÿ‘” ๐Ÿ“Ÿ, โ” โ›“ ๐ŸŒ "๐Ÿ‘Œ".
* โž•1๏ธโƒฃ ๐Ÿ–ผ ๐Ÿ”œ `201`, "โœ". โšซ๏ธ ๐Ÿ›Ž โš™๏ธ โฎ๏ธ ๐Ÿ— ๐Ÿ†• โบ ๐Ÿ’ฝ.
* ๐ŸŽ ๐Ÿ’ผ `204`, "๐Ÿ™…โ€โ™‚ ๐ŸŽš". ๐Ÿ‘‰ ๐Ÿ“จ โš™๏ธ ๐Ÿ•โ” ๐Ÿ“ค ๐Ÿ™…โ€โ™‚ ๐ŸŽš ๐Ÿ“จ ๐Ÿ‘ฉโ€๐Ÿ’ป, &amp; ๐Ÿ“จ ๐Ÿ”œ ๐Ÿšซ โœ”๏ธ ๐Ÿ’ช.
* **`300`** &amp; ๐Ÿ”› "โŽ". ๐Ÿ“จ โฎ๏ธ ๐Ÿ‘ซ ๐Ÿ‘” ๐Ÿ“Ÿ 5๏ธโƒฃ๐Ÿ“† โš–๏ธ 5๏ธโƒฃ๐Ÿ“† ๐Ÿšซ โœ”๏ธ ๐Ÿ’ช, ๐ŸŒ– `304`, "๐Ÿšซ ๐Ÿ”€", โ” ๐Ÿ”œ ๐Ÿšซ โœ”๏ธ 1๏ธโƒฃ.
* **`400`** &amp; ๐Ÿ”› "๐Ÿ‘ฉโ€๐Ÿ’ป โŒ" ๐Ÿ“จ. ๐Ÿ‘ซ ๐Ÿฅˆ ๐Ÿ†Ž ๐Ÿ‘† ๐Ÿ”œ ๐ŸŽฒ โš™๏ธ ๐Ÿ†.
* ๐Ÿ–ผ `404`, "๐Ÿšซ ๐Ÿ”Ž" ๐Ÿ“จ.
* ๐Ÿ’Š โŒ โšช๏ธโžก๏ธ ๐Ÿ‘ฉโ€๐Ÿ’ป, ๐Ÿ‘† ๐Ÿ’ช โš™๏ธ `400`.
* `500` &amp; ๐Ÿ”› ๐Ÿ’ฝ โŒ. ๐Ÿ‘† ๐ŸŒ– ๐Ÿ™… โš™๏ธ ๐Ÿ‘ซ ๐Ÿ”—. ๐Ÿ•โ” ๐Ÿ•ณ ๐Ÿšถ โŒ ๐Ÿ• ๐Ÿ‘† ๐Ÿˆธ ๐Ÿ“Ÿ, โš–๏ธ ๐Ÿ’ฝ, โšซ๏ธ ๐Ÿ”œ ๐Ÿ” ๐Ÿ“จ 1๏ธโƒฃ ๐Ÿ‘ซ ๐Ÿ‘” ๐Ÿ“Ÿ.
!!! tip
๐Ÿ’ญ ๐ŸŒ… ๐Ÿ”ƒ ๐Ÿ”  ๐Ÿ‘” ๐Ÿ“Ÿ &amp; โ” ๐Ÿ“Ÿ โšซ๏ธโ”, โœ… <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Status" class="external-link" target="_blank"><abbr title="Mozilla Developer Network">๐Ÿ‡</abbr> ๐Ÿงพ ๐Ÿ”ƒ ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ” ๐Ÿ‘” ๐Ÿ“Ÿ</a>.
## โŒจ ๐Ÿ’ญ ๐Ÿ“›
โžก๏ธ ๐Ÿ‘€ โฎ๏ธ ๐Ÿ–ผ ๐Ÿ”„:
```Python hl_lines="6"
{!../../../docs_src/response_status_code/tutorial001.py!}
```
`201` ๐Ÿ‘” ๐Ÿ“Ÿ "โœ".
โœ‹๏ธ ๐Ÿ‘† ๐Ÿšซ โœ”๏ธ โœ โšซ๏ธโ” ๐Ÿ”  ๐Ÿ‘‰ ๐Ÿ“Ÿ โ›“.
๐Ÿ‘† ๐Ÿ’ช โš™๏ธ ๐Ÿช ๐Ÿ”ข โšช๏ธโžก๏ธ `fastapi.status`.
```Python hl_lines="1 6"
{!../../../docs_src/response_status_code/tutorial002.py!}
```
๐Ÿ‘ซ ๐Ÿช, ๐Ÿ‘ซ ๐Ÿง‘โ€๐Ÿคโ€๐Ÿง‘ ๐ŸŽ ๐Ÿ”ข, โœ‹๏ธ ๐Ÿ‘ˆ ๐ŸŒŒ ๐Ÿ‘† ๐Ÿ’ช โš™๏ธ ๐Ÿ‘จโ€๐ŸŽจ ๐Ÿ“‹ ๐Ÿ”Ž ๐Ÿ‘ซ:
<img src="/img/tutorial/response-status-code/image02.png">
!!! note "๐Ÿ“ก โ„น"
๐Ÿ‘† ๐Ÿ’ช โš™๏ธ `from starlette import status`.
**FastAPI** ๐Ÿšš ๐ŸŽ `starlette.status` `fastapi.status` ๐Ÿช ๐Ÿ‘†, ๐Ÿ‘ฉโ€๐Ÿ’ป. โœ‹๏ธ โšซ๏ธ ๐Ÿ‘Ÿ ๐Ÿ”— โšช๏ธโžก๏ธ ๐Ÿ’ƒ.
## ๐Ÿ”€ ๐Ÿ”ข
โช, [๐Ÿง ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿฆฎ](../advanced/response-change-status-code.md){.internal-link target=_blank}, ๐Ÿ‘† ๐Ÿ”œ ๐Ÿ‘€ โ” ๐Ÿ“จ ๐ŸŽ ๐Ÿ‘” ๐Ÿ“Ÿ ๐ŸŒ˜ ๐Ÿ”ข ๐Ÿ‘† ๐Ÿ“ฃ ๐Ÿ“ฅ.

141
docs/em/docs/tutorial/schema-extra-example.md

@ -0,0 +1,141 @@
# ๐Ÿ“ฃ ๐Ÿ“จ ๐Ÿ–ผ ๐Ÿ’ฝ
๐Ÿ‘† ๐Ÿ’ช ๐Ÿ“ฃ ๐Ÿ–ผ ๐Ÿ’ฝ ๐Ÿ‘† ๐Ÿ“ฑ ๐Ÿ’ช ๐Ÿ“จ.
๐Ÿ“ฅ ๐Ÿ“š ๐ŸŒŒ โšซ๏ธ.
## Pydantic `schema_extra`
๐Ÿ‘† ๐Ÿ’ช ๐Ÿ“ฃ `example` Pydantic ๐Ÿท โš™๏ธ `Config` &amp; `schema_extra`, ๐Ÿ”ฌ <a href="https://pydantic-docs.helpmanual.io/usage/schema/#schema-customization" class="external-link" target="_blank">Pydantic ๐Ÿฉบ: ๐Ÿ”— ๐Ÿ›ƒ</a>:
=== "๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="15-23"
{!> ../../../docs_src/schema_extra_example/tutorial001.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.1๏ธโƒฃ0๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="13-21"
{!> ../../../docs_src/schema_extra_example/tutorial001_py310.py!}
```
๐Ÿ‘ˆ โž• โ„น ๐Ÿ”œ ๐Ÿšฎ-๐Ÿ”ข **๐ŸŽป ๐Ÿ”—** ๐Ÿ‘ˆ ๐Ÿท, &amp; โšซ๏ธ ๐Ÿ”œ โš™๏ธ ๐Ÿ› ๏ธ ๐Ÿฉบ.
!!! tip
๐Ÿ‘† ๐Ÿ’ช โš™๏ธ ๐ŸŽ โš’ โ†” ๐ŸŽป ๐Ÿ”— &amp; ๐Ÿšฎ ๐Ÿ‘† ๐Ÿ‘ ๐Ÿ›ƒ โž• โ„น.
๐Ÿ–ผ ๐Ÿ‘† ๐Ÿ’ช โš™๏ธ โšซ๏ธ ๐Ÿšฎ ๐Ÿ—ƒ ๐Ÿ•ธ ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ”ข, โ™’๏ธ.
## `Field` ๐ŸŒ– โŒ
๐Ÿ•โ” โš™๏ธ `Field()` โฎ๏ธ Pydantic ๐Ÿท, ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ“ฃ โž• โ„น **๐ŸŽป ๐Ÿ”—** ๐Ÿšถโ€โ™€๏ธ ๐Ÿ™† ๐ŸŽ โŒ โŒ ๐Ÿ”ข.
๐Ÿ‘† ๐Ÿ’ช โš™๏ธ ๐Ÿ‘‰ ๐Ÿšฎ `example` ๐Ÿ”  ๐Ÿ‘:
=== "๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="4 10-13"
{!> ../../../docs_src/schema_extra_example/tutorial002.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.1๏ธโƒฃ0๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="2 8-11"
{!> ../../../docs_src/schema_extra_example/tutorial002_py310.py!}
```
!!! warning
๐Ÿšง ๐Ÿคฏ ๐Ÿ‘ˆ ๐Ÿ“š โž• โŒ ๐Ÿšถโ€โ™€๏ธ ๐Ÿ† ๐Ÿšซ ๐Ÿšฎ ๐Ÿ™† ๐Ÿ”ฌ, ๐Ÿ•ด โž• โ„น, ๐Ÿงพ ๐ŸŽฏ.
## `example` &amp; `examples` ๐Ÿ—„
๐Ÿ•โ” โš™๏ธ ๐Ÿ™†:
* `Path()`
* `Query()`
* `Header()`
* `Cookie()`
* `Body()`
* `Form()`
* `File()`
๐Ÿ‘† ๐Ÿ’ช ๐Ÿ“ฃ ๐Ÿ’ฝ `example` โš–๏ธ ๐Ÿ‘ช `examples` โฎ๏ธ ๐ŸŒ– โ„น ๐Ÿ‘ˆ ๐Ÿ”œ ๐Ÿšฎ **๐Ÿ—„**.
### `Body` โฎ๏ธ `example`
๐Ÿ“ฅ ๐Ÿ‘ฅ ๐Ÿšถโ€โ™€๏ธ `example` ๐Ÿ“Š โŒ› `Body()`:
=== "๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="20-25"
{!> ../../../docs_src/schema_extra_example/tutorial003.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.1๏ธโƒฃ0๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="18-23"
{!> ../../../docs_src/schema_extra_example/tutorial003_py310.py!}
```
### ๐Ÿ–ผ ๐Ÿฉบ ๐ŸŽš
โฎ๏ธ ๐Ÿ™† ๐Ÿ‘ฉโ€๐Ÿ”ฌ ๐Ÿ”› โšซ๏ธ ๐Ÿ”œ ๐Ÿ‘€ ๐Ÿ’– ๐Ÿ‘‰ `/docs`:
<img src="/img/tutorial/body-fields/image01.png">
### `Body` โฎ๏ธ ๐Ÿ’— `examples`
๐Ÿ‘ ๐Ÿ‘ `example`, ๐Ÿ‘† ๐Ÿ’ช ๐Ÿšถโ€โ™€๏ธ `examples` โš™๏ธ `dict` โฎ๏ธ **๐Ÿ’— ๐Ÿ–ผ**, ๐Ÿ”  โฎ๏ธ โž• โ„น ๐Ÿ‘ˆ ๐Ÿ”œ ๐Ÿšฎ **๐Ÿ—„** ๐Ÿ’โ€โ™‚๏ธ.
๐Ÿ”‘ `dict` ๐Ÿ”ฌ ๐Ÿ”  ๐Ÿ–ผ, &amp; ๐Ÿ”  ๐Ÿ’ฒ โž•1๏ธโƒฃ `dict`.
๐Ÿ”  ๐ŸŽฏ ๐Ÿ–ผ `dict` `examples` ๐Ÿ’ช ๐Ÿ”Œ:
* `summary`: ๐Ÿ“ ๐Ÿ“› ๐Ÿ–ผ.
* `description`: ๐Ÿ“ ๐Ÿ“› ๐Ÿ‘ˆ ๐Ÿ’ช ๐Ÿ”Œ โœ โœ.
* `value`: ๐Ÿ‘‰ โ˜‘ ๐Ÿ–ผ ๐ŸŽฆ, โœ… `dict`.
* `externalValue`: ๐ŸŽ› `value`, ๐Ÿ“› โ˜ ๐Ÿ–ผ. ๐Ÿ‘ ๐Ÿ‘‰ 5๏ธโƒฃ๐Ÿ“† ๐Ÿšซ ๐Ÿ•โ€๐Ÿฆบ ๐Ÿ“š ๐Ÿงฐ `value`.
=== "๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="21-47"
{!> ../../../docs_src/schema_extra_example/tutorial004.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.1๏ธโƒฃ0๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="19-45"
{!> ../../../docs_src/schema_extra_example/tutorial004_py310.py!}
```
### ๐Ÿ–ผ ๐Ÿฉบ ๐ŸŽš
โฎ๏ธ `examples` ๐Ÿšฎ `Body()` `/docs` ๐Ÿ”œ ๐Ÿ‘€ ๐Ÿ’–:
<img src="/img/tutorial/body-fields/image02.png">
## ๐Ÿ“ก โ„น
!!! warning
๐Ÿ‘‰ ๐Ÿ“ถ ๐Ÿ“ก โ„น ๐Ÿ”ƒ ๐Ÿฉ **๐ŸŽป ๐Ÿ”—** &amp; **๐Ÿ—„**.
๐Ÿšฅ ๐Ÿ’ญ ๐Ÿ”› โช ๐Ÿ‘ท ๐Ÿ‘†, ๐Ÿ‘ˆ ๐Ÿ’ช ๐Ÿฅƒ, &amp; ๐Ÿ‘† ๐ŸŽฒ ๐Ÿšซ ๐Ÿ’ช ๐Ÿ‘‰ โ„น, ๐Ÿ’ญ ๐Ÿ†“ ๐Ÿšถ ๐Ÿ‘ซ.
๐Ÿ•โ” ๐Ÿ‘† ๐Ÿšฎ ๐Ÿ–ผ ๐Ÿ”˜ Pydantic ๐Ÿท, โš™๏ธ `schema_extra` โš–๏ธ `Field(example="something")` ๐Ÿ‘ˆ ๐Ÿ–ผ ๐Ÿšฎ **๐ŸŽป ๐Ÿ”—** ๐Ÿ‘ˆ Pydantic ๐Ÿท.
&amp; ๐Ÿ‘ˆ **๐ŸŽป ๐Ÿ”—** Pydantic ๐Ÿท ๐Ÿ”Œ **๐Ÿ—„** ๐Ÿ‘† ๐Ÿ› ๏ธ, &amp; โคด๏ธ โšซ๏ธ โš™๏ธ ๐Ÿฉบ ๐ŸŽš.
**๐ŸŽป ๐Ÿ”—** ๐Ÿšซ ๐Ÿค™ โœ”๏ธ ๐Ÿ‘ `example` ๐Ÿฉ. โฎ๏ธ โฌ ๐ŸŽป ๐Ÿ”— ๐Ÿ”ฌ ๐Ÿ‘ <a href="https://json-schema.org/draft/2019-09/json-schema-validation.html#rfc.section.9.5" class="external-link" target="_blank">`examples`</a>, โœ‹๏ธ ๐Ÿ—„ 3๏ธโƒฃ.0๏ธโƒฃ.3๏ธโƒฃ โš“๏ธ ๐Ÿ”› ๐Ÿ— โฌ ๐ŸŽป ๐Ÿ”— ๐Ÿ‘ˆ ๐Ÿšซ โœ”๏ธ `examples`.
, ๐Ÿ—„ 3๏ธโƒฃ.0๏ธโƒฃ.3๏ธโƒฃ ๐Ÿ”ฌ ๐Ÿšฎ ๐Ÿ‘ <a href="https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.3.md#fixed-fields-20" class="external-link" target="_blank">`example`</a> ๐Ÿ”€ โฌ **๐ŸŽป ๐Ÿ”—** โšซ๏ธ โš™๏ธ, ๐ŸŽ ๐ŸŽฏ (โœ‹๏ธ โšซ๏ธ ๐Ÿ‘ `example`, ๐Ÿšซ `examples`), &amp; ๐Ÿ‘ˆ โšซ๏ธโ” โš™๏ธ ๐Ÿ› ๏ธ ๐Ÿฉบ ๐ŸŽš (โš™๏ธ ๐Ÿฆ ๐ŸŽš).
, ๐Ÿ‘ `example` ๐Ÿšซ ๐Ÿ• ๐ŸŽป ๐Ÿ”—, โšซ๏ธ ๐Ÿ• ๐Ÿ—„ ๐Ÿ›ƒ โฌ ๐ŸŽป ๐Ÿ”—, &amp; ๐Ÿ‘ˆ โšซ๏ธโ” ๐Ÿ”œ โš™๏ธ ๐Ÿฉบ ๐ŸŽš.
โœ‹๏ธ ๐Ÿ•โ” ๐Ÿ‘† โš™๏ธ `example` โš–๏ธ `examples` โฎ๏ธ ๐Ÿ™† ๐ŸŽ ๐Ÿš™ (`Query()`, `Body()`, โ™’๏ธ.) ๐Ÿ“š ๐Ÿ–ผ ๐Ÿšซ ๐Ÿšฎ ๐ŸŽป ๐Ÿ”— ๐Ÿ‘ˆ ๐Ÿ”ฌ ๐Ÿ‘ˆ ๐Ÿ’ฝ (๐Ÿšซ ๐Ÿ—„ ๐Ÿ‘ โฌ ๐ŸŽป ๐Ÿ”—), ๐Ÿ‘ซ ๐Ÿšฎ ๐Ÿ”— *โžก ๐Ÿ› ๏ธ* ๐Ÿ“„ ๐Ÿ—„ (๐Ÿž ๐Ÿ• ๐Ÿ—„ ๐Ÿ‘ˆ โš™๏ธ ๐ŸŽป ๐Ÿ”—).
`Path()`, `Query()`, `Header()`, &amp; `Cookie()`, `example` โš–๏ธ `examples` ๐Ÿšฎ <a href="https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#parameter-object" class="external-link" target="_blank">๐Ÿ—„ ๐Ÿ”‘, `Parameter Object` (๐Ÿ”ง)</a>.
&amp; `Body()`, `File()`, &amp; `Form()`, `example` โš–๏ธ `examples` ๐Ÿ“Š ๐Ÿšฎ <a href="https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#mediaTypeObject" class="external-link" target="_blank">๐Ÿ—„ ๐Ÿ”‘, `Request Body Object`, ๐Ÿ‘ `content`, ๐Ÿ”› `Media Type Object` (๐Ÿ”ง)</a>.
๐Ÿ”› ๐ŸŽ โœ‹, ๐Ÿ“ค ๐Ÿ†• โฌ ๐Ÿ—„: **3๏ธโƒฃ.1๏ธโƒฃ.0๏ธโƒฃ**, โณ ๐Ÿš€. โšซ๏ธ โš“๏ธ ๐Ÿ”› โช ๐ŸŽป ๐Ÿ”— &amp; ๐Ÿ† ๐Ÿ› ๏ธ โšช๏ธโžก๏ธ ๐Ÿ—„ ๐Ÿ›ƒ โฌ ๐ŸŽป ๐Ÿ”— โŽ, ๐Ÿ’ฑ โš’ โšช๏ธโžก๏ธ โฎ๏ธ โฌ ๐ŸŽป ๐Ÿ”—, ๐ŸŒ ๐Ÿ‘ซ ๐Ÿคช ๐Ÿ”บ ๐Ÿ“‰. ๐Ÿ‘, ๐Ÿฆ ๐ŸŽš โณ ๐Ÿšซ ๐Ÿ•โ€๐Ÿฆบ ๐Ÿ—„ 3๏ธโƒฃ.1๏ธโƒฃ.0๏ธโƒฃ,, ๐Ÿ”œ, โšซ๏ธ ๐Ÿ‘ ๐Ÿ˜ฃ โš™๏ธ ๐Ÿ’ญ ๐Ÿ”›.

182
docs/em/docs/tutorial/security/first-steps.md

@ -0,0 +1,182 @@
# ๐Ÿ’‚โ€โ™‚ - ๐Ÿฅ‡ ๐Ÿ”
โžก๏ธ ๐ŸŒˆ ๐Ÿ‘ˆ ๐Ÿ‘† โœ”๏ธ ๐Ÿ‘† **๐Ÿ‘ฉโ€๐Ÿ’ป** ๐Ÿ› ๏ธ ๐Ÿ†”.
&amp; ๐Ÿ‘† โœ”๏ธ **๐Ÿ•ธ** โž•1๏ธโƒฃ ๐Ÿ†” โš–๏ธ ๐ŸŽ โžก ๐ŸŽ ๐Ÿ†” (โš–๏ธ ๐Ÿ“ฑ ๐Ÿˆธ).
&amp; ๐Ÿ‘† ๐Ÿ’š โœ”๏ธ ๐ŸŒŒ ๐Ÿ•ธ ๐Ÿ”“ โฎ๏ธ ๐Ÿ‘ฉโ€๐Ÿ’ป, โš™๏ธ **๐Ÿ†”** &amp; **๐Ÿ”**.
๐Ÿ‘ฅ ๐Ÿ’ช โš™๏ธ **Oauth2๏ธโƒฃ** ๐Ÿ— ๐Ÿ‘ˆ โฎ๏ธ **FastAPI**.
โœ‹๏ธ โžก๏ธ ๐Ÿ–Š ๐Ÿ‘† ๐Ÿ•ฐ ๐Ÿ‘‚ ๐ŸŒ• ๐Ÿ“ ๐Ÿ”ง ๐Ÿ”Ž ๐Ÿ‘ˆ ๐Ÿฅ ๐Ÿ– โ„น ๐Ÿ‘† ๐Ÿ’ช.
โžก๏ธ โš™๏ธ ๐Ÿงฐ ๐Ÿšš **FastAPI** ๐Ÿต ๐Ÿ’‚โ€โ™‚.
## โ” โšซ๏ธ ๐Ÿ‘€
โžก๏ธ ๐Ÿฅ‡ โš™๏ธ ๐Ÿ“Ÿ &amp; ๐Ÿ‘€ โ” โšซ๏ธ ๐Ÿ‘ท, &amp; โคด๏ธ ๐Ÿ‘ฅ ๐Ÿ”œ ๐Ÿ‘Ÿ ๐Ÿ”™ ๐Ÿค” โšซ๏ธโ” ๐Ÿ˜ฅ.
## โœ `main.py`
๐Ÿ“ ๐Ÿ–ผ ๐Ÿ“ `main.py`:
```Python
{!../../../docs_src/security/tutorial001.py!}
```
## ๐Ÿƒ โšซ๏ธ
!!! info
๐Ÿฅ‡ โŽ <a href="https://andrew-d.github.io/python-multipart/" class="external-link" target="_blank">`python-multipart`</a>.
๐Ÿคถ โ“‚. `pip install python-multipart`.
๐Ÿ‘‰ โ†ฉ๏ธ **Oauth2๏ธโƒฃ** โš™๏ธ "๐Ÿ“จ ๐Ÿ“Š" ๐Ÿ“จ `username` &amp; `password`.
๐Ÿƒ ๐Ÿ–ผ โฎ๏ธ:
<div class="termy">
```console
$ uvicorn main:app --reload
<span style="color: green;">INFO</span>: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
```
</div>
## โœ… โšซ๏ธ
๐Ÿšถ ๐ŸŽ“ ๐Ÿฉบ: <a href="http://127.0.0.1:8000/docs" class="external-link" target="_blank">http://127.0.0.1:8000/docs</a>.
๐Ÿ‘† ๐Ÿ”œ ๐Ÿ‘€ ๐Ÿ•ณ ๐Ÿ’– ๐Ÿ‘‰:
<img src="/img/tutorial/security/image01.png">
!!! check "โœ” ๐Ÿ”ผ โ—"
๐Ÿ‘† โช โœ”๏ธ โœจ ๐Ÿ†• "โœ”" ๐Ÿ”ผ.
&amp; ๐Ÿ‘† *โžก ๐Ÿ› ๏ธ* โœ”๏ธ ๐Ÿฅ ๐Ÿ”’ ๐Ÿ”-โ–ถ๏ธ๏ธ โ†ฉ ๐Ÿ‘ˆ ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ–Š.
&amp; ๐Ÿšฅ ๐Ÿ‘† ๐Ÿ–Š โšซ๏ธ, ๐Ÿ‘† โœ”๏ธ ๐Ÿฅ โœ” ๐Ÿ“จ ๐Ÿ†Ž `username` &amp; `password` (&amp; ๐ŸŽ ๐Ÿ“ฆ ๐Ÿ‘):
<img src="/img/tutorial/security/image02.png">
!!! note
โšซ๏ธ ๐Ÿšซ ๐Ÿค” โšซ๏ธโ” ๐Ÿ‘† ๐Ÿ†Ž ๐Ÿ“จ, โšซ๏ธ ๐Ÿ† ๐Ÿšซ ๐Ÿ‘ท. โœ‹๏ธ ๐Ÿ‘ฅ ๐Ÿ”œ ๐Ÿคš ๐Ÿ“ค.
๐Ÿ‘‰ โ†—๏ธ ๐Ÿšซ ๐Ÿ•ธ ๐Ÿ ๐Ÿ‘ฉโ€๐Ÿ’ป, โœ‹๏ธ โšซ๏ธ ๐Ÿ‘‘ ๐Ÿง ๐Ÿงฐ ๐Ÿ“„ ๐Ÿ–ฅ ๐ŸŒ ๐Ÿ‘† ๐Ÿ› ๏ธ.
โšซ๏ธ ๐Ÿ’ช โš™๏ธ ๐Ÿ•ธ ๐Ÿ‰ (๐Ÿ‘ˆ ๐Ÿ’ช ๐Ÿ‘†).
โšซ๏ธ ๐Ÿ’ช โš™๏ธ ๐Ÿฅ‰ ๐Ÿฅณ ๐Ÿˆธ &amp; โš™๏ธ.
&amp; โšซ๏ธ ๐Ÿ’ช โš™๏ธ ๐Ÿ‘†, โ„น, โœ… &amp; ๐Ÿ’ฏ ๐ŸŽ ๐Ÿˆธ.
## `password` ๐Ÿ’ง
๐Ÿ”œ โžก๏ธ ๐Ÿšถ ๐Ÿ”™ ๐Ÿ‘„ &amp; ๐Ÿค” โšซ๏ธโ” ๐ŸŒ ๐Ÿ‘ˆ.
`password` "๐Ÿ’ง" 1๏ธโƒฃ ๐ŸŒŒ ("๐Ÿ’ง") ๐Ÿ”ฌ Oauth2๏ธโƒฃ, ๐Ÿต ๐Ÿ’‚โ€โ™‚ &amp; ๐Ÿค.
Oauth2๏ธโƒฃ ๐Ÿ”ง ๐Ÿ‘ˆ ๐Ÿ‘ฉโ€๐Ÿ’ป โš–๏ธ ๐Ÿ› ๏ธ ๐Ÿ’ช ๐Ÿ”ฌ ๐Ÿ’ฝ ๐Ÿ‘ˆ ๐Ÿ”“ ๐Ÿ‘ฉโ€๐Ÿ’ป.
โœ‹๏ธ ๐Ÿ‘‰ ๐Ÿ’ผ, ๐ŸŽ **FastAPI** ๐Ÿˆธ ๐Ÿ”œ ๐Ÿต ๐Ÿ› ๏ธ &amp; ๐Ÿค.
, โžก๏ธ ๐Ÿ“„ โšซ๏ธ โšช๏ธโžก๏ธ ๐Ÿ‘ˆ ๐Ÿ“‰ โ˜ ๐ŸŽ‘:
* ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ†Ž `username` &amp; `password` ๐Ÿ•ธ, &amp; ๐ŸŽฏ `Enter`.
* ๐Ÿ•ธ (๐Ÿƒโ€โ™‚ ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ–ฅ) ๐Ÿ“จ ๐Ÿ‘ˆ `username` &amp; `password` ๐ŸŽฏ ๐Ÿ“› ๐Ÿ‘† ๐Ÿ› ๏ธ (๐Ÿ“ฃ โฎ๏ธ `tokenUrl="token"`).
* ๐Ÿ› ๏ธ โœ… ๐Ÿ‘ˆ `username` &amp; `password`, &amp; ๐Ÿ“จ โฎ๏ธ "๐Ÿค" (๐Ÿ‘ฅ ๐Ÿšซ ๐Ÿ› ๏ธ ๐Ÿ™† ๐Ÿ‘‰).
* "๐Ÿค" ๐ŸŽป โฎ๏ธ ๐ŸŽš ๐Ÿ‘ˆ ๐Ÿ‘ฅ ๐Ÿ’ช โš™๏ธ โช โœ” ๐Ÿ‘‰ ๐Ÿ‘ฉโ€๐Ÿ’ป.
* ๐Ÿ›Ž, ๐Ÿค โš’ ๐Ÿ•› โฎ๏ธ ๐Ÿ•ฐ.
* , ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ”œ โœ”๏ธ ๐Ÿ•น ๐Ÿ”„ โ˜ โช.
* &amp; ๐Ÿšฅ ๐Ÿค ๐Ÿ“Ž, โš  ๐ŸŒ˜. โšซ๏ธ ๐Ÿšซ ๐Ÿ’– ๐Ÿงฒ ๐Ÿ”‘ ๐Ÿ‘ˆ ๐Ÿ”œ ๐Ÿ‘ท โ™พ (๐Ÿ† ๐Ÿ’ผ).
* ๐Ÿ•ธ ๐Ÿช ๐Ÿ‘ˆ ๐Ÿค ๐Ÿ• ๐Ÿ‘ฑ.
* ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ–Š ๐Ÿ•ธ ๐Ÿšถ โž•1๏ธโƒฃ ๐Ÿ“„ ๐Ÿ•ธ ๐Ÿ•ธ ๐Ÿ“ฑ.
* ๐Ÿ•ธ ๐Ÿ’ช โ˜• ๐ŸŒ… ๐Ÿ’ฝ โšช๏ธโžก๏ธ ๐Ÿ› ๏ธ.
* โœ‹๏ธ โšซ๏ธ ๐Ÿ’ช ๐Ÿค ๐Ÿ‘ˆ ๐ŸŽฏ ๐Ÿ”—.
* , ๐Ÿ”“ โฎ๏ธ ๐Ÿ‘† ๐Ÿ› ๏ธ, โšซ๏ธ ๐Ÿ“จ ๐ŸŽš `Authorization` โฎ๏ธ ๐Ÿ’ฒ `Bearer ` โž• ๐Ÿค.
* ๐Ÿšฅ ๐Ÿค ๐Ÿ”Œ `foobar`, ๐ŸŽš `Authorization` ๐ŸŽš ๐Ÿ”œ: `Bearer foobar`.
## **FastAPI**'โ“‚ `OAuth2PasswordBearer`
**FastAPI** ๐Ÿšš ๐Ÿ“š ๐Ÿงฐ, ๐ŸŽ ๐ŸŽš โš›, ๐Ÿ› ๏ธ ๐Ÿ‘ซ ๐Ÿ’‚โ€โ™‚ โš’.
๐Ÿ‘‰ ๐Ÿ–ผ ๐Ÿ‘ฅ ๐Ÿ”œ โš™๏ธ **Oauth2๏ธโƒฃ**, โฎ๏ธ **๐Ÿ”** ๐Ÿ’ง, โš™๏ธ **๐Ÿ“จ** ๐Ÿค. ๐Ÿ‘ฅ ๐Ÿ‘ˆ โš™๏ธ `OAuth2PasswordBearer` ๐ŸŽ“.
!!! info
"๐Ÿ“จ" ๐Ÿค ๐Ÿšซ ๐Ÿ•ด ๐ŸŽ›.
โœ‹๏ธ โšซ๏ธ ๐Ÿ† 1๏ธโƒฃ ๐Ÿ‘† โš™๏ธ ๐Ÿ’ผ.
&amp; โšซ๏ธ ๐Ÿ’ช ๐Ÿ† ๐Ÿ† โš™๏ธ ๐Ÿ’ผ, ๐Ÿšฅ ๐Ÿ‘† Oauth2๏ธโƒฃ ๐Ÿ•ด &amp; ๐Ÿ’ญ โšซ๏ธโ” โšซ๏ธโ” ๐Ÿ“ค โž•1๏ธโƒฃ ๐ŸŽ› ๐Ÿ‘ˆ โ™ฃ ๐Ÿ‘ป ๐Ÿ‘† ๐Ÿ’ช.
๐Ÿ‘ˆ ๐Ÿ’ผ, **FastAPI** ๐Ÿšš ๐Ÿ‘† โฎ๏ธ ๐Ÿงฐ ๐Ÿ— โšซ๏ธ.
๐Ÿ•โ” ๐Ÿ‘ฅ โœ ๐Ÿ‘ `OAuth2PasswordBearer` ๐ŸŽ“ ๐Ÿ‘ฅ ๐Ÿšถโ€โ™€๏ธ `tokenUrl` ๐Ÿ”ข. ๐Ÿ‘‰ ๐Ÿ”ข ๐Ÿ”Œ ๐Ÿ“› ๐Ÿ‘ˆ ๐Ÿ‘ฉโ€๐Ÿ’ป (๐Ÿ•ธ ๐Ÿƒ ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ–ฅ) ๐Ÿ”œ โš™๏ธ ๐Ÿ“จ `username` &amp; `password` โœ” ๐Ÿคš ๐Ÿค.
```Python hl_lines="6"
{!../../../docs_src/security/tutorial001.py!}
```
!!! tip
๐Ÿ“ฅ `tokenUrl="token"` ๐Ÿ”— โš– ๐Ÿ“› `token` ๐Ÿ‘ˆ ๐Ÿ‘ฅ ๐Ÿšซ โœ. โšซ๏ธ โš– ๐Ÿ“›, โšซ๏ธ ๐ŸŒ“ `./token`.
โ†ฉ๏ธ ๐Ÿ‘ฅ โš™๏ธ โš– ๐Ÿ“›, ๐Ÿšฅ ๐Ÿ‘† ๐Ÿ› ๏ธ ๐Ÿ”Ž `https://example.com/`, โคด๏ธ โšซ๏ธ ๐Ÿ”œ ๐Ÿ”— `https://example.com/token`. โœ‹๏ธ ๐Ÿšฅ ๐Ÿ‘† ๐Ÿ› ๏ธ ๐Ÿ”Ž `https://example.com/api/v1/`, โคด๏ธ โšซ๏ธ ๐Ÿ”œ ๐Ÿ”— `https://example.com/api/v1/token`.
โš™๏ธ โš– ๐Ÿ“› โš  โš’ ๐Ÿ’ญ ๐Ÿ‘† ๐Ÿˆธ ๐Ÿšง ๐Ÿ‘ท ๐Ÿง โš™๏ธ ๐Ÿ’ผ ๐Ÿ’– [โ›… ๐Ÿ—ณ](../../advanced/behind-a-proxy.md){.internal-link target=_blank}.
๐Ÿ‘‰ ๐Ÿ”ข ๐Ÿšซ โœ ๐Ÿ‘ˆ ๐Ÿ”— / *โžก ๐Ÿ› ๏ธ*, โœ‹๏ธ ๐Ÿ“ฃ ๐Ÿ‘ˆ ๐Ÿ“› `/token` ๐Ÿ”œ 1๏ธโƒฃ ๐Ÿ‘ˆ ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ”œ โš™๏ธ ๐Ÿคš ๐Ÿค. ๐Ÿ‘ˆ โ„น โš™๏ธ ๐Ÿ—„, &amp; โคด๏ธ ๐ŸŽ“ ๐Ÿ› ๏ธ ๐Ÿงพ โš™๏ธ.
๐Ÿ‘ฅ ๐Ÿ”œ ๐Ÿ”œ โœ โ˜‘ โžก ๐Ÿ› ๏ธ.
!!! info
๐Ÿšฅ ๐Ÿ‘† ๐Ÿ“ถ โš  "โœ" ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ‘Ž ๐Ÿ‘— ๐Ÿ”ข ๐Ÿ“› `tokenUrl` โ†ฉ๏ธ `token_url`.
๐Ÿ‘ˆ โ†ฉ๏ธ โšซ๏ธ โš™๏ธ ๐ŸŽ ๐Ÿ“› ๐Ÿ—„ ๐Ÿ”Œ. ๐Ÿ‘ˆ ๐Ÿšฅ ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ”ฌ ๐ŸŒ… ๐Ÿ”ƒ ๐Ÿ™† ๐Ÿ‘ซ ๐Ÿ’‚โ€โ™‚ โš– ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ“ &amp; ๐Ÿ“‹ โšซ๏ธ ๐Ÿ”Ž ๐ŸŒ– โ„น ๐Ÿ”ƒ โšซ๏ธ.
`oauth2_scheme` ๐Ÿ”ข ๐Ÿ‘ `OAuth2PasswordBearer`, โœ‹๏ธ โšซ๏ธ "๐Ÿ‡ง๐Ÿ‡ฒ".
โšซ๏ธ ๐Ÿ’ช ๐Ÿค™:
```Python
oauth2_scheme(some, parameters)
```
, โšซ๏ธ ๐Ÿ’ช โš™๏ธ โฎ๏ธ `Depends`.
### โš™๏ธ โšซ๏ธ
๐Ÿ”œ ๐Ÿ‘† ๐Ÿ’ช ๐Ÿšถโ€โ™€๏ธ ๐Ÿ‘ˆ `oauth2_scheme` ๐Ÿ”— โฎ๏ธ `Depends`.
```Python hl_lines="10"
{!../../../docs_src/security/tutorial001.py!}
```
๐Ÿ‘‰ ๐Ÿ”— ๐Ÿ”œ ๐Ÿšš `str` ๐Ÿ‘ˆ ๐Ÿ› ๏ธ ๐Ÿ”ข `token` *โžก ๐Ÿ› ๏ธ ๐Ÿ”ข*.
**FastAPI** ๐Ÿ”œ ๐Ÿ’ญ ๐Ÿ‘ˆ โšซ๏ธ ๐Ÿ’ช โš™๏ธ ๐Ÿ‘‰ ๐Ÿ”— ๐Ÿ”ฌ "๐Ÿ’‚โ€โ™‚ โš–" ๐Ÿ—„ ๐Ÿ”— (&amp; ๐Ÿง ๐Ÿ› ๏ธ ๐Ÿฉบ).
!!! info "๐Ÿ“ก โ„น"
**FastAPI** ๐Ÿ”œ ๐Ÿ’ญ ๐Ÿ‘ˆ โšซ๏ธ ๐Ÿ’ช โš™๏ธ ๐ŸŽ“ `OAuth2PasswordBearer` (๐Ÿ“ฃ ๐Ÿ”—) ๐Ÿ”ฌ ๐Ÿ’‚โ€โ™‚ โš– ๐Ÿ—„ โ†ฉ๏ธ โšซ๏ธ ๐Ÿ˜– โšช๏ธโžก๏ธ `fastapi.security.oauth2.OAuth2`, โ” ๐Ÿ”„ ๐Ÿ˜– โšช๏ธโžก๏ธ `fastapi.security.base.SecurityBase`.
๐ŸŒ ๐Ÿ’‚โ€โ™‚ ๐Ÿš™ ๐Ÿ‘ˆ ๐Ÿ› ๏ธ โฎ๏ธ ๐Ÿ—„ (&amp; ๐Ÿง ๐Ÿ› ๏ธ ๐Ÿฉบ) ๐Ÿ˜– โšช๏ธโžก๏ธ `SecurityBase`, ๐Ÿ‘ˆ โ” **FastAPI** ๐Ÿ’ช ๐Ÿ’ญ โ” ๐Ÿ› ๏ธ ๐Ÿ‘ซ ๐Ÿ—„.
## โšซ๏ธโ” โšซ๏ธ ๐Ÿ”จ
โšซ๏ธ ๐Ÿ”œ ๐Ÿšถ &amp; ๐Ÿ‘€ ๐Ÿ“จ ๐Ÿ‘ˆ `Authorization` ๐ŸŽš, โœ… ๐Ÿšฅ ๐Ÿ’ฒ `Bearer ` โž• ๐Ÿค, &amp; ๐Ÿ”œ ๐Ÿ“จ ๐Ÿค `str`.
๐Ÿšฅ โšซ๏ธ ๐Ÿšซ ๐Ÿ‘€ `Authorization` ๐ŸŽš, โš–๏ธ ๐Ÿ’ฒ ๐Ÿšซ โœ”๏ธ `Bearer ` ๐Ÿค, โšซ๏ธ ๐Ÿ”œ ๐Ÿ“จ โฎ๏ธ 4๏ธโƒฃ0๏ธโƒฃ1๏ธโƒฃ ๐Ÿ‘” ๐Ÿ“Ÿ โŒ (`UNAUTHORIZED`) ๐Ÿ”—.
๐Ÿ‘† ๐Ÿšซ โœ”๏ธ โœ… ๐Ÿšฅ ๐Ÿค ๐Ÿ”€ ๐Ÿ“จ โŒ. ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ’ญ ๐Ÿ‘ˆ ๐Ÿšฅ ๐Ÿ‘† ๐Ÿ”ข ๐Ÿ› ๏ธ, โšซ๏ธ ๐Ÿ”œ โœ”๏ธ `str` ๐Ÿ‘ˆ ๐Ÿค.
๐Ÿ‘† ๐Ÿ’ช ๐Ÿ”„ โšซ๏ธ โช ๐ŸŽ“ ๐Ÿฉบ:
<img src="/img/tutorial/security/image03.png">
๐Ÿ‘ฅ ๐Ÿšซ โœ” ๐Ÿ”ฌ ๐Ÿค, โœ‹๏ธ ๐Ÿ‘ˆ โ–ถ๏ธ โช.
## ๐ŸŒƒ
, 3๏ธโƒฃ โš–๏ธ 4๏ธโƒฃ โž• โธ, ๐Ÿ‘† โช โœ”๏ธ ๐Ÿ’ ๐Ÿ“จ ๐Ÿ’‚โ€โ™‚.

151
docs/em/docs/tutorial/security/get-current-user.md

@ -0,0 +1,151 @@
# ๐Ÿคš โฎ๏ธ ๐Ÿ‘ฉโ€๐Ÿ’ป
โฎ๏ธ ๐Ÿ“ƒ ๐Ÿ’‚โ€โ™‚ โš™๏ธ (โ” ๐Ÿงข ๐Ÿ”› ๐Ÿ”— ๐Ÿ’‰ โš™๏ธ) ๐Ÿค *โžก ๐Ÿ› ๏ธ ๐Ÿ”ข* `token` `str`:
```Python hl_lines="10"
{!../../../docs_src/security/tutorial001.py!}
```
โœ‹๏ธ ๐Ÿ‘ˆ ๐Ÿšซ ๐Ÿ‘ˆ โš .
โžก๏ธ โš’ โšซ๏ธ ๐Ÿค ๐Ÿ‘ฅ โฎ๏ธ ๐Ÿ‘ฉโ€๐Ÿ’ป.
## โœ ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿท
๐Ÿฅ‡, โžก๏ธ โœ Pydantic ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿท.
๐ŸŽ ๐ŸŒŒ ๐Ÿ‘ฅ โš™๏ธ Pydantic ๐Ÿ“ฃ ๐Ÿ’ช, ๐Ÿ‘ฅ ๐Ÿ’ช โš™๏ธ โšซ๏ธ ๐Ÿ™† ๐Ÿ™†:
=== "๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="5 12-16"
{!> ../../../docs_src/security/tutorial002.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.1๏ธโƒฃ0๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="3 10-14"
{!> ../../../docs_src/security/tutorial002_py310.py!}
```
## โœ `get_current_user` ๐Ÿ”—
โžก๏ธ โœ ๐Ÿ”— `get_current_user`.
๐Ÿ’ญ ๐Ÿ‘ˆ ๐Ÿ”— ๐Ÿ’ช โœ”๏ธ ๐ŸŽง-๐Ÿ”— โ“
`get_current_user` ๐Ÿ”œ โœ”๏ธ ๐Ÿ”— โฎ๏ธ ๐ŸŽ `oauth2_scheme` ๐Ÿ‘ฅ โœ โญ.
๐ŸŽ ๐Ÿ‘ฅ ๐Ÿ”จ โญ *โžก ๐Ÿ› ๏ธ* ๐Ÿ”—, ๐Ÿ‘† ๐Ÿ†• ๐Ÿ”— `get_current_user` ๐Ÿ”œ ๐Ÿ“จ `token` `str` โšช๏ธโžก๏ธ ๐ŸŽง-๐Ÿ”— `oauth2_scheme`:
=== "๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="25"
{!> ../../../docs_src/security/tutorial002.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.1๏ธโƒฃ0๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="23"
{!> ../../../docs_src/security/tutorial002_py310.py!}
```
## ๐Ÿคš ๐Ÿ‘ฉโ€๐Ÿ’ป
`get_current_user` ๐Ÿ”œ โš™๏ธ (โŒ) ๐Ÿš™ ๐Ÿ”ข ๐Ÿ‘ฅ โœ, ๐Ÿ‘ˆ โœŠ ๐Ÿค `str` &amp; ๐Ÿ“จ ๐Ÿ‘† Pydantic `User` ๐Ÿท:
=== "๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="19-22 26-27"
{!> ../../../docs_src/security/tutorial002.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.1๏ธโƒฃ0๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="17-20 24-25"
{!> ../../../docs_src/security/tutorial002_py310.py!}
```
## ๐Ÿ’‰ โฎ๏ธ ๐Ÿ‘ฉโ€๐Ÿ’ป
๐Ÿ”œ ๐Ÿ‘ฅ ๐Ÿ’ช โš™๏ธ ๐ŸŽ `Depends` โฎ๏ธ ๐Ÿ‘† `get_current_user` *โžก ๐Ÿ› ๏ธ*:
=== "๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="31"
{!> ../../../docs_src/security/tutorial002.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.1๏ธโƒฃ0๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="29"
{!> ../../../docs_src/security/tutorial002_py310.py!}
```
๐Ÿ‘€ ๐Ÿ‘ˆ ๐Ÿ‘ฅ ๐Ÿ“ฃ ๐Ÿ†Ž `current_user` Pydantic ๐Ÿท `User`.
๐Ÿ‘‰ ๐Ÿ”œ โ„น ๐Ÿ‡บ๐Ÿ‡ฒ ๐Ÿ”˜ ๐Ÿ”ข โฎ๏ธ ๐ŸŒ ๐Ÿ› ๏ธ &amp; ๐Ÿ†Ž โœ….
!!! tip
๐Ÿ‘† 5๏ธโƒฃ๐Ÿ“† ๐Ÿ’ญ ๐Ÿ‘ˆ ๐Ÿ“จ ๐Ÿ’ช ๐Ÿ“ฃ โฎ๏ธ Pydantic ๐Ÿท.
๐Ÿ“ฅ **FastAPI** ๐Ÿ† ๐Ÿšซ ๐Ÿคš ๐Ÿ˜จ โ†ฉ๏ธ ๐Ÿ‘† โš™๏ธ `Depends`.
!!! check
๐ŸŒŒ ๐Ÿ‘‰ ๐Ÿ”— โš™๏ธ ๐Ÿ— โœ” ๐Ÿ‘ฅ โœ”๏ธ ๐ŸŽ ๐Ÿ”— (๐ŸŽ "โ˜‘") ๐Ÿ‘ˆ ๐ŸŒ ๐Ÿ“จ `User` ๐Ÿท.
๐Ÿ‘ฅ ๐Ÿšซ ๐Ÿšซ โœ”๏ธ ๐Ÿ•ด 1๏ธโƒฃ ๐Ÿ”— ๐Ÿ‘ˆ ๐Ÿ’ช ๐Ÿ“จ ๐Ÿ‘ˆ ๐Ÿ†Ž ๐Ÿ’ฝ.
## ๐ŸŽ ๐Ÿท
๐Ÿ‘† ๐Ÿ’ช ๐Ÿ”œ ๐Ÿคš โฎ๏ธ ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ”— *โžก ๐Ÿ› ๏ธ ๐Ÿ”ข* &amp; ๐Ÿ™… โฎ๏ธ ๐Ÿ’‚โ€โ™‚ ๐Ÿ› ๏ธ **๐Ÿ”— ๐Ÿ’‰** ๐ŸŽš, โš™๏ธ `Depends`.
&amp; ๐Ÿ‘† ๐Ÿ’ช โš™๏ธ ๐Ÿ™† ๐Ÿท โš–๏ธ ๐Ÿ’ฝ ๐Ÿ’‚โ€โ™‚ ๐Ÿ“„ (๐Ÿ‘‰ ๐Ÿ’ผ, Pydantic ๐Ÿท `User`).
โœ‹๏ธ ๐Ÿ‘† ๐Ÿšซ ๐Ÿšซ โš™๏ธ ๐ŸŽฏ ๐Ÿ’ฝ ๐Ÿท, ๐ŸŽ“ โš–๏ธ ๐Ÿ†Ž.
๐Ÿ‘† ๐Ÿ’š โœ”๏ธ `id` &amp; `email` &amp; ๐Ÿšซ โœ”๏ธ ๐Ÿ™† `username` ๐Ÿ‘† ๐Ÿท โ“ ๐Ÿ’ญ. ๐Ÿ‘† ๐Ÿ’ช โš™๏ธ ๐Ÿ‘‰ ๐ŸŽ ๐Ÿงฐ.
๐Ÿ‘† ๐Ÿ’š โœ”๏ธ `str`โ“ โš–๏ธ `dict`โ“ โš–๏ธ ๐Ÿ’ฝ ๐ŸŽ“ ๐Ÿท ๐Ÿ‘ ๐Ÿ”— โ“ โšซ๏ธ ๐ŸŒ ๐Ÿ‘ท ๐ŸŽ ๐ŸŒŒ.
๐Ÿ‘† ๐Ÿค™ ๐Ÿšซ โœ”๏ธ ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ‘ˆ ๐Ÿ•น ๐Ÿ‘† ๐Ÿˆธ โœ‹๏ธ ๐Ÿค–, ๐Ÿค–, โš–๏ธ ๐ŸŽ โš™๏ธ, ๐Ÿ‘ˆ โœ”๏ธ ๐Ÿ” ๐Ÿค โ“ ๐Ÿ”„, โšซ๏ธ ๐ŸŒ ๐Ÿ‘ท ๐ŸŽ.
โš™๏ธ ๐Ÿ™† ๐Ÿ˜‡ ๐Ÿท, ๐Ÿ™† ๐Ÿ˜‡ ๐ŸŽ“, ๐Ÿ™† ๐Ÿ˜‡ ๐Ÿ’ฝ ๐Ÿ‘ˆ ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ‘† ๐Ÿˆธ. **FastAPI** โœ”๏ธ ๐Ÿ‘† ๐Ÿ“” โฎ๏ธ ๐Ÿ”— ๐Ÿ’‰ โš™๏ธ.
## ๐Ÿ“Ÿ ๐Ÿ“
๐Ÿ‘‰ ๐Ÿ–ผ 5๏ธโƒฃ๐Ÿ“† ๐Ÿ˜‘ ๐Ÿ”. โœ”๏ธ ๐Ÿคฏ ๐Ÿ‘ˆ ๐Ÿ‘ฅ ๐ŸŒ€ ๐Ÿ’‚โ€โ™‚, ๐Ÿ“Š ๐Ÿท, ๐Ÿš™ ๐Ÿ”ข &amp; *โžก ๐Ÿ› ๏ธ* ๐ŸŽ ๐Ÿ“.
โœ‹๏ธ ๐Ÿ“ฅ ๐Ÿ”‘ โ˜.
๐Ÿ’‚โ€โ™‚ &amp; ๐Ÿ”— ๐Ÿ’‰ ๐Ÿ’ฉ โœ ๐Ÿ•.
&amp; ๐Ÿ‘† ๐Ÿ’ช โš’ โšซ๏ธ ๐Ÿ— ๐Ÿ‘† ๐Ÿ’š. &amp; , โœ”๏ธ โšซ๏ธ โœ ๐Ÿ•ด ๐Ÿ•, ๐Ÿ‘ ๐Ÿฅ‰. โฎ๏ธ ๐ŸŒ ๐Ÿ’ช.
โœ‹๏ธ ๐Ÿ‘† ๐Ÿ’ช โœ”๏ธ ๐Ÿ’ฏ ๐Ÿ”— (*โžก ๐Ÿ› ๏ธ*) โš™๏ธ ๐ŸŽ ๐Ÿ’‚โ€โ™‚ โš™๏ธ.
&amp; ๐ŸŒ ๐Ÿ‘ซ (โš–๏ธ ๐Ÿ™† โ†” ๐Ÿ‘ซ ๐Ÿ‘ˆ ๐Ÿ‘† ๐Ÿ’š) ๐Ÿ’ช โœŠ ๐Ÿ“ˆ ๐Ÿค-โš™๏ธ ๐Ÿ‘ซ ๐Ÿ”— โš–๏ธ ๐Ÿ™† ๐ŸŽ ๐Ÿ”— ๐Ÿ‘† โœ.
&amp; ๐ŸŒ ๐Ÿ‘‰ ๐Ÿ’ฏ *โžก ๐Ÿ› ๏ธ* ๐Ÿ’ช ๐Ÿคช 3๏ธโƒฃ โธ:
=== "๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="30-32"
{!> ../../../docs_src/security/tutorial002.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.1๏ธโƒฃ0๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="28-30"
{!> ../../../docs_src/security/tutorial002_py310.py!}
```
## ๐ŸŒƒ
๐Ÿ‘† ๐Ÿ’ช ๐Ÿ”œ ๐Ÿคš โฎ๏ธ ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ”— ๐Ÿ‘† *โžก ๐Ÿ› ๏ธ ๐Ÿ”ข*.
๐Ÿ‘ฅ โช ๐Ÿ˜ฌ ๐Ÿ“ค.
๐Ÿ‘ฅ ๐Ÿ’ช ๐Ÿšฎ *โžก ๐Ÿ› ๏ธ* ๐Ÿ‘ฉโ€๐Ÿ’ป/๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿค™ ๐Ÿ“จ `username` &amp; `password`.
๐Ÿ‘ˆ ๐Ÿ‘Ÿ โญ.

101
docs/em/docs/tutorial/security/index.md

@ -0,0 +1,101 @@
# ๐Ÿ’‚โ€โ™‚ ๐ŸŽถ
๐Ÿ“ค ๐Ÿ“š ๐ŸŒŒ ๐Ÿต ๐Ÿ’‚โ€โ™‚, ๐Ÿค &amp; โœ”.
&amp; โšซ๏ธ ๐Ÿ›Ž ๐Ÿ— &amp; "โš " โ”.
๐Ÿ“š ๐Ÿ› ๏ธ &amp; โš™๏ธ ๐Ÿต ๐Ÿ’‚โ€โ™‚ &amp; ๐Ÿค โœŠ ๐Ÿฆ ๐Ÿ’ธ ๐ŸŽฏ &amp; ๐Ÿ“Ÿ (๐Ÿ“š ๐Ÿ’ผ โšซ๏ธ ๐Ÿ’ช 5๏ธโƒฃ0๏ธโƒฃ ๐Ÿ’ฏ โš–๏ธ ๐ŸŒ… ๐ŸŒ ๐Ÿ“Ÿ โœ).
**FastAPI** ๐Ÿšš ๐Ÿ“š ๐Ÿงฐ โ„น ๐Ÿ‘† ๐Ÿ™… โฎ๏ธ **๐Ÿ’‚โ€โ™‚** ๐Ÿ’ช, ๐Ÿ“‰, ๐Ÿฉ ๐ŸŒŒ, ๐Ÿต โœ”๏ธ ๐Ÿ”ฌ &amp; ๐Ÿ’ก ๐ŸŒ ๐Ÿ’‚โ€โ™‚ ๐Ÿ”ง.
โœ‹๏ธ ๐Ÿฅ‡, โžก๏ธ โœ… ๐Ÿคช ๐Ÿ”ง.
## ๐Ÿƒ โ“
๐Ÿšฅ ๐Ÿ‘† ๐Ÿšซ ๐Ÿ’… ๐Ÿ”ƒ ๐Ÿ™† ๐Ÿ‘‰ โš– &amp; ๐Ÿ‘† ๐Ÿ’ช ๐Ÿšฎ ๐Ÿ’‚โ€โ™‚ โฎ๏ธ ๐Ÿค โš“๏ธ ๐Ÿ”› ๐Ÿ†” &amp; ๐Ÿ” *โ–ถ๏ธ๏ธ ๐Ÿ”œ*, ๐Ÿšถ โญ ๐Ÿ“ƒ.
## Oauth2๏ธโƒฃ
Oauth2๏ธโƒฃ ๐Ÿ”ง ๐Ÿ‘ˆ ๐Ÿ”ฌ ๐Ÿ“š ๐ŸŒŒ ๐Ÿต ๐Ÿค &amp; โœ”.
โšซ๏ธ ๐Ÿ”ฌ ๐Ÿ”ง &amp; ๐Ÿ“” ๐Ÿ“š ๐Ÿ— โš™๏ธ ๐Ÿ’ผ.
โšซ๏ธ ๐Ÿ”Œ ๐ŸŒŒ ๐Ÿ”“ โš™๏ธ "๐Ÿฅ‰ ๐Ÿฅณ".
๐Ÿ‘ˆ โšซ๏ธโ” ๐ŸŒ โš™๏ธ โฎ๏ธ "๐Ÿ’ณ โฎ๏ธ ๐Ÿ‘ฑ๐Ÿ“”, ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ”, ๐Ÿ‘ฑ๐Ÿ“”, ๐Ÿ“‚" โš™๏ธ ๐Ÿ”˜.
### โœณ 1๏ธโƒฃ
๐Ÿ“ค โœณ 1๏ธโƒฃ, โ” ๐Ÿ“ถ ๐ŸŽ โšช๏ธโžก๏ธ Oauth2๏ธโƒฃ, &amp; ๐ŸŒ– ๐Ÿ—, โšซ๏ธ ๐Ÿ”Œ ๐Ÿ”— ๐Ÿ”ง ๐Ÿ”› โ” ๐Ÿ—œ ๐Ÿ“ป.
โšซ๏ธ ๐Ÿšซ ๐Ÿ“ถ ๐ŸŒŸ โš–๏ธ โš™๏ธ ๐Ÿ›Ž.
Oauth2๏ธโƒฃ ๐Ÿšซ โœ” โ” ๐Ÿ—œ ๐Ÿ“ป, โšซ๏ธ โŒ› ๐Ÿ‘† โœ”๏ธ ๐Ÿ‘† ๐Ÿˆธ ๐Ÿฆ โฎ๏ธ ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ”.
!!! tip
๐Ÿ“„ ๐Ÿ”ƒ **๐Ÿ› ๏ธ** ๐Ÿ‘† ๐Ÿ”œ ๐Ÿ‘€ โ” โš’ ๐Ÿ†™ ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ” ๐Ÿ†“, โš™๏ธ Traefik &amp; โžก๏ธ ๐Ÿ—œ.
## ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ”—
๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ”— โž•1๏ธโƒฃ ๐Ÿ”ง, ๐Ÿงข ๐Ÿ”› **Oauth2๏ธโƒฃ**.
โšซ๏ธ โ†” Oauth2๏ธโƒฃ โœ” ๐Ÿ‘œ ๐Ÿ‘ˆ ๐Ÿ“ถ ๐ŸŒŒ Oauth2๏ธโƒฃ, ๐Ÿ”„ โš’ โšซ๏ธ ๐ŸŒ… ๐Ÿ› ๏ธ.
๐Ÿ–ผ, ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ” ๐Ÿ’ณ โš™๏ธ ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ”— (โ” ๐Ÿ”˜ โš™๏ธ Oauth2๏ธโƒฃ).
โœ‹๏ธ ๐Ÿ‘ฑ๐Ÿ“” ๐Ÿ’ณ ๐Ÿšซ ๐Ÿ•โ€๐Ÿฆบ ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ”—. โšซ๏ธ โœ”๏ธ ๐Ÿšฎ ๐Ÿ‘ ๐Ÿ› Oauth2๏ธโƒฃ.
### ๐Ÿ‘ฉโ€๐Ÿ’ป (๐Ÿšซ "๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ”—")
๐Ÿ“ค "๐Ÿ‘ฉโ€๐Ÿ’ป" ๐Ÿ”ง. ๐Ÿ‘ˆ ๐Ÿ”„ โŽ ๐ŸŽ ๐Ÿ‘œ **๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ”—**, โœ‹๏ธ ๐Ÿšซ โš“๏ธ ๐Ÿ”› Oauth2๏ธโƒฃ.
, โšซ๏ธ ๐Ÿ ๐ŸŒ– โš™๏ธ.
โšซ๏ธ ๐Ÿšซ ๐Ÿ“ถ ๐ŸŒŸ โš–๏ธ โš™๏ธ ๐Ÿ›Ž.
## ๐Ÿ—„
๐Ÿ—„ (โช ๐Ÿ’ญ ๐Ÿฆ) ๐Ÿ“‚ ๐Ÿ”ง ๐Ÿ— ๐Ÿ”— (๐Ÿ”œ ๐Ÿ• ๐Ÿ’พ ๐Ÿ›).
**FastAPI** โš“๏ธ ๐Ÿ”› **๐Ÿ—„**.
๐Ÿ‘ˆ โšซ๏ธโ” โš’ โšซ๏ธ ๐Ÿ’ช โœ”๏ธ ๐Ÿ’— ๐Ÿง ๐ŸŽ“ ๐Ÿงพ ๐Ÿ”ข, ๐Ÿ“Ÿ โšก, โ™’๏ธ.
๐Ÿ—„ โœ”๏ธ ๐ŸŒŒ ๐Ÿ”ฌ ๐Ÿ’— ๐Ÿ’‚โ€โ™‚ "โš–".
โš™๏ธ ๐Ÿ‘ซ, ๐Ÿ‘† ๐Ÿ’ช โœŠ ๐Ÿ“ˆ ๐ŸŒ ๐Ÿ‘ซ ๐Ÿฉ-โš“๏ธ ๐Ÿงฐ, ๐Ÿ”Œ ๐Ÿ‘‰ ๐ŸŽ“ ๐Ÿงพ โš™๏ธ.
๐Ÿ—„ ๐Ÿ”ฌ ๐Ÿ“„ ๐Ÿ’‚โ€โ™‚ โš–:
* `apiKey`: ๐Ÿˆธ ๐ŸŽฏ ๐Ÿ”‘ ๐Ÿ‘ˆ ๐Ÿ’ช ๐Ÿ‘Ÿ โšช๏ธโžก๏ธ:
* ๐Ÿ”ข ๐Ÿ”ข.
* ๐ŸŽš.
* ๐Ÿช.
* `http`: ๐Ÿฉ ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ” ๐Ÿค โš™๏ธ, ๐Ÿ”Œ:
* `bearer`: ๐ŸŽš `Authorization` โฎ๏ธ ๐Ÿ’ฒ `Bearer ` โž• ๐Ÿค. ๐Ÿ‘‰ ๐Ÿ˜– โšช๏ธโžก๏ธ Oauth2๏ธโƒฃ.
* ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ” ๐Ÿ”ฐ ๐Ÿค.
* ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ” ๐Ÿ“ฐ, โ™’๏ธ.
* `oauth2`: ๐ŸŒ Oauth2๏ธโƒฃ ๐ŸŒŒ ๐Ÿต ๐Ÿ’‚โ€โ™‚ (๐Ÿค™ "๐Ÿ’ง").
* ๐Ÿ“š ๐Ÿ‘ซ ๐Ÿ’ง โ˜‘ ๐Ÿ— โœณ 2๏ธโƒฃ.0๏ธโƒฃ ๐Ÿค ๐Ÿ•โ€๐Ÿฆบ (๐Ÿ’– ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ”, ๐Ÿ‘ฑ๐Ÿ“”, ๐Ÿ‘ฑ๐Ÿ“”, ๐Ÿ“‚, โ™’๏ธ):
* `implicit`
* `clientCredentials`
* `authorizationCode`
* โœ‹๏ธ ๐Ÿ“ค 1๏ธโƒฃ ๐ŸŽฏ "๐Ÿ’ง" ๐Ÿ‘ˆ ๐Ÿ’ช ๐Ÿ‘Œ โš™๏ธ ๐Ÿšš ๐Ÿค ๐ŸŽ ๐Ÿˆธ ๐Ÿ”—:
* `password`: โญ ๐Ÿ“ƒ ๐Ÿ”œ ๐Ÿ“” ๐Ÿ–ผ ๐Ÿ‘‰.
* `openIdConnect`: โœ”๏ธ ๐ŸŒŒ ๐Ÿ”ฌ โ” ๐Ÿ”Ž Oauth2๏ธโƒฃ ๐Ÿค ๐Ÿ“Š ๐Ÿ”.
* ๐Ÿ‘‰ ๐Ÿง ๐Ÿ” โšซ๏ธโ” ๐Ÿ”ฌ ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ”— ๐Ÿ”ง.
!!! tip
๐Ÿ› ๏ธ ๐ŸŽ ๐Ÿค/โœ” ๐Ÿ•โ€๐Ÿฆบ ๐Ÿ’– ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ”, ๐Ÿ‘ฑ๐Ÿ“”, ๐Ÿ‘ฑ๐Ÿ“”, ๐Ÿ“‚, โ™’๏ธ. ๐Ÿ’ช &amp; ๐Ÿ“ถ โฉ.
๐ŸŒ… ๐Ÿ— โš  ๐Ÿ— ๐Ÿค/โœ” ๐Ÿ•โ€๐Ÿฆบ ๐Ÿ’– ๐Ÿ‘ˆ, โœ‹๏ธ **FastAPI** ๐Ÿค ๐Ÿ‘† ๐Ÿงฐ โšซ๏ธ ๐Ÿ’ช, โช ๐Ÿ”จ ๐Ÿ‹๏ธ ๐Ÿ‹โ€โ™‚ ๐Ÿ‘†.
## **FastAPI** ๐Ÿš™
FastAPI ๐Ÿšš ๐Ÿ“š ๐Ÿงฐ ๐Ÿ”  ๐Ÿ‘‰ ๐Ÿ’‚โ€โ™‚ โš– `fastapi.security` ๐Ÿ•น ๐Ÿ‘ˆ ๐Ÿ“‰ โš™๏ธ ๐Ÿ‘‰ ๐Ÿ’‚โ€โ™‚ ๐Ÿ› ๏ธ.
โญ ๐Ÿ“ƒ ๐Ÿ‘† ๐Ÿ”œ ๐Ÿ‘€ โ” ๐Ÿšฎ ๐Ÿ’‚โ€โ™‚ ๐Ÿ‘† ๐Ÿ› ๏ธ โš™๏ธ ๐Ÿ“š ๐Ÿงฐ ๐Ÿšš **FastAPI**.
&amp; ๐Ÿ‘† ๐Ÿ”œ ๐Ÿ‘€ โ” โšซ๏ธ ๐Ÿคš ๐Ÿ” ๐Ÿ› ๏ธ ๐Ÿ”˜ ๐ŸŽ“ ๐Ÿงพ โš™๏ธ.

297
docs/em/docs/tutorial/security/oauth2-jwt.md

@ -0,0 +1,297 @@
# Oauth2๏ธโƒฃ โฎ๏ธ ๐Ÿ” (&amp; ๐Ÿ”), ๐Ÿ“จ โฎ๏ธ ๐Ÿฅ™ ๐Ÿค
๐Ÿ”œ ๐Ÿ‘ˆ ๐Ÿ‘ฅ โœ”๏ธ ๐ŸŒ ๐Ÿ’‚โ€โ™‚ ๐Ÿ’ง, โžก๏ธ โš’ ๐Ÿˆธ ๐Ÿค™ ๐Ÿ”, โš™๏ธ <abbr title="JSON Web Tokens">๐Ÿฅ™</abbr> ๐Ÿค &amp; ๐Ÿ” ๐Ÿ” ๐Ÿ”.
๐Ÿ‘‰ ๐Ÿ“Ÿ ๐Ÿ•ณ ๐Ÿ‘† ๐Ÿ’ช ๐Ÿค™ โš™๏ธ ๐Ÿ‘† ๐Ÿˆธ, ๐Ÿ–Š ๐Ÿ” #๏ธโƒฃ ๐Ÿ‘† ๐Ÿ’ฝ, โ™’๏ธ.
๐Ÿ‘ฅ ๐Ÿ”œ โ–ถ๏ธ โšช๏ธโžก๏ธ ๐ŸŒโ” ๐Ÿ‘ฅ โ—€๏ธ โฎ๏ธ ๐Ÿ“ƒ &amp; ๐Ÿ“ˆ โšซ๏ธ.
## ๐Ÿ”ƒ ๐Ÿฅ™
๐Ÿฅ™ โ›“ "๐ŸŽป ๐Ÿ•ธ ๐Ÿค".
โšซ๏ธ ๐Ÿฉ ๐Ÿšซ ๐ŸŽป ๐ŸŽš ๐Ÿ“ ๐Ÿ’ง ๐ŸŽป ๐Ÿต ๐Ÿš€. โšซ๏ธ ๐Ÿ‘€ ๐Ÿ’– ๐Ÿ‘‰:
```
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c
```
โšซ๏ธ ๐Ÿšซ ๐Ÿ—œ,, ๐Ÿ™† ๐Ÿ’ช ๐Ÿ›ก โ„น โšช๏ธโžก๏ธ ๐ŸŽš.
โœ‹๏ธ โšซ๏ธ ๐Ÿ›‘. , ๐Ÿ•โ” ๐Ÿ‘† ๐Ÿ“จ ๐Ÿค ๐Ÿ‘ˆ ๐Ÿ‘† โ™จ, ๐Ÿ‘† ๐Ÿ’ช โœ” ๐Ÿ‘ˆ ๐Ÿ‘† ๐Ÿค™ โ™จ โšซ๏ธ.
๐Ÿ‘ˆ ๐ŸŒŒ, ๐Ÿ‘† ๐Ÿ’ช โœ ๐Ÿค โฎ๏ธ ๐Ÿ‘”, โžก๏ธ ๐Ÿ’ฌ, 1๏ธโƒฃ ๐Ÿ—“๏ธ. &amp; โคด๏ธ ๐Ÿ•โ” ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ‘Ÿ ๐Ÿ”™ โญ ๐Ÿ“† โฎ๏ธ ๐Ÿค, ๐Ÿ‘† ๐Ÿ’ญ ๐Ÿ‘ˆ ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ•น ๐Ÿ‘† โš™๏ธ.
โฎ๏ธ ๐Ÿ—“๏ธ, ๐Ÿค ๐Ÿ”œ ๐Ÿ•› &amp; ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ”œ ๐Ÿšซ โœ” &amp; ๐Ÿ”œ โœ”๏ธ ๐Ÿ›‘ ๐Ÿ”„ ๐Ÿคš ๐Ÿ†• ๐Ÿค. &amp; ๐Ÿšฅ ๐Ÿ‘ฉโ€๐Ÿ’ป (โš–๏ธ ๐Ÿฅ‰ ๐Ÿฅณ) ๐Ÿ”„ ๐Ÿ”€ ๐Ÿค ๐Ÿ”€ ๐Ÿ‘”, ๐Ÿ‘† ๐Ÿ”œ ๐Ÿ’ช ๐Ÿ”Ž โšซ๏ธ, โ†ฉ๏ธ ๐Ÿ’ณ ๐Ÿ”œ ๐Ÿšซ ๐Ÿ.
๐Ÿšฅ ๐Ÿ‘† ๐Ÿ’š ๐Ÿคพ โฎ๏ธ ๐Ÿฅ™ ๐Ÿค &amp; ๐Ÿ‘€ โ” ๐Ÿ‘ซ ๐Ÿ‘ท, โœ… <a href="https://jwt.io/" class="external-link" target="_blank">https://jwt.io</a>.
## โŽ `python-jose`
๐Ÿ‘ฅ ๐Ÿ’ช โŽ `python-jose` ๐Ÿ— &amp; โœ” ๐Ÿฅ™ ๐Ÿค ๐Ÿ:
<div class="termy">
```console
$ pip install "python-jose[cryptography]"
---> 100%
```
</div>
<a href="https://github.com/mpdavis/python-jose" class="external-link" target="_blank">๐Ÿ-๐Ÿ‡ฉ๐Ÿ‡ฌ</a> ๐Ÿšš ๐Ÿ” ๐Ÿ‘ฉโ€๐Ÿ’ป โž•.
๐Ÿ“ฅ ๐Ÿ‘ฅ โš™๏ธ ๐Ÿ‘ 1๏ธโƒฃ: <a href="https://cryptography.io/" class="external-link" target="_blank">)/โš›</a>.
!!! tip
๐Ÿ‘‰ ๐Ÿ”ฐ โช โš™๏ธ <a href="https://pyjwt.readthedocs.io/" class="external-link" target="_blank">PyJWT</a>.
โœ‹๏ธ โšซ๏ธ โ„น โš™๏ธ ๐Ÿ-๐Ÿ‡ฉ๐Ÿ‡ฌ โ†ฉ๏ธ โšซ๏ธ ๐Ÿšš ๐ŸŒ โš’ โšช๏ธโžก๏ธ PyJWT โž• โž• ๐Ÿ‘ˆ ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ’ช โช ๐Ÿ•โ” ๐Ÿ— ๐Ÿ› ๏ธ โฎ๏ธ ๐ŸŽ ๐Ÿงฐ.
## ๐Ÿ” ๐Ÿ”
"๐Ÿ”" โ›“ ๐Ÿญ ๐ŸŽš (๐Ÿ” ๐Ÿ‘‰ ๐Ÿ’ผ) ๐Ÿ”˜ ๐Ÿ” ๐Ÿ”ข (๐ŸŽป) ๐Ÿ‘ˆ ๐Ÿ‘€ ๐Ÿ’– ๐Ÿ™ƒ.
๐Ÿ•โ” ๐Ÿ‘† ๐Ÿšถโ€โ™€๏ธ โšซ๏ธโ” ๐ŸŽ ๐ŸŽš (โšซ๏ธโ” ๐ŸŽ ๐Ÿ”) ๐Ÿ‘† ๐Ÿคš โšซ๏ธโ” ๐ŸŽ ๐Ÿ™ƒ.
โœ‹๏ธ ๐Ÿ‘† ๐Ÿšซ๐Ÿ”œ ๐Ÿ—œ โšช๏ธโžก๏ธ ๐Ÿ™ƒ ๐Ÿ”™ ๐Ÿ”.
### โšซ๏ธโ” โš™๏ธ ๐Ÿ” ๐Ÿ”
๐Ÿšฅ ๐Ÿ‘† ๐Ÿ’ฝ ๐Ÿ“Ž, ๐Ÿง™โ€โ™€ ๐Ÿ† ๐Ÿšซ โœ”๏ธ ๐Ÿ‘† ๐Ÿ‘ฉโ€๐Ÿ’ป' ๐Ÿ”ข ๐Ÿ”, ๐Ÿ•ด#๏ธโƒฃ.
, ๐Ÿง™โ€โ™€ ๐Ÿ† ๐Ÿšซ ๐Ÿ’ช ๐Ÿ”„ โš™๏ธ ๐Ÿ‘ˆ ๐Ÿ” โž•1๏ธโƒฃ โš™๏ธ (๐Ÿ“š ๐Ÿ‘ฉโ€๐Ÿ’ป โš™๏ธ ๐ŸŽ ๐Ÿ” ๐ŸŒ, ๐Ÿ‘‰ ๐Ÿ”œ โš ).
## โŽ `passlib`
๐Ÿ‡ธ๐Ÿ‡ฒ ๐Ÿ‘‘ ๐Ÿ ๐Ÿ“ฆ ๐Ÿต ๐Ÿ”#๏ธโƒฃ.
โšซ๏ธ ๐Ÿ•โ€๐Ÿฆบ ๐Ÿ“š ๐Ÿ” ๐Ÿ” ๐Ÿ“Š &amp; ๐Ÿš™ ๐Ÿ‘ท โฎ๏ธ ๐Ÿ‘ซ.
๐Ÿ‘ ๐Ÿ“Š "๐Ÿก".
, โŽ ๐Ÿ‡ธ๐Ÿ‡ฒ โฎ๏ธ ๐Ÿก:
<div class="termy">
```console
$ pip install "passlib[bcrypt]"
---> 100%
```
</div>
!!! tip
โฎ๏ธ `passlib`, ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ”— โšซ๏ธ ๐Ÿ’ช โœ ๐Ÿ” โœ **โœณ**, **๐Ÿบ** ๐Ÿ’‚โ€โ™‚ ๐Ÿ”Œ-โš–๏ธ ๐Ÿ“š ๐ŸŽ.
, ๐Ÿ‘† ๐Ÿ”œ ๐Ÿ’ช, ๐Ÿ–ผ, ๐Ÿ’ฐ ๐ŸŽ ๐Ÿ“Š โšช๏ธโžก๏ธ โœณ ๐Ÿˆธ ๐Ÿ’ฝ โฎ๏ธ FastAPI ๐Ÿˆธ. โš–๏ธ ๐Ÿ“‰ โ†” โœณ ๐Ÿˆธ โš™๏ธ ๐ŸŽ ๐Ÿ’ฝ.
&amp; ๐Ÿ‘† ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ”œ ๐Ÿ’ช ๐Ÿ’ณ โšช๏ธโžก๏ธ ๐Ÿ‘† โœณ ๐Ÿ“ฑ โš–๏ธ โšช๏ธโžก๏ธ ๐Ÿ‘† **FastAPI** ๐Ÿ“ฑ, ๐ŸŽ ๐Ÿ•ฐ.
## #๏ธโƒฃ &amp; โœ” ๐Ÿ”
๐Ÿ—„ ๐Ÿงฐ ๐Ÿ‘ฅ ๐Ÿ’ช โšช๏ธโžก๏ธ `passlib`.
โœ ๐Ÿ‡ธ๐Ÿ‡ฒ "๐Ÿ”‘". ๐Ÿ‘‰ โšซ๏ธโ” ๐Ÿ”œ โš™๏ธ #๏ธโƒฃ &amp; โœ” ๐Ÿ”.
!!! tip
๐Ÿ‡ธ๐Ÿ‡ฒ ๐Ÿ”‘ โœ”๏ธ ๐Ÿ› ๏ธ โš™๏ธ ๐ŸŽ ๐Ÿ” ๐Ÿ“Š, ๐Ÿ”Œ ๐Ÿ˜ข ๐Ÿ— ๐Ÿ• ๐Ÿ•ด โœ” โœ” ๐Ÿ‘ซ, โ™’๏ธ.
๐Ÿ–ผ, ๐Ÿ‘† ๐Ÿ’ช โš™๏ธ โšซ๏ธ โœ &amp; โœ” ๐Ÿ” ๐Ÿ— โž•1๏ธโƒฃ โš™๏ธ (๐Ÿ’– โœณ) โœ‹๏ธ #๏ธโƒฃ ๐Ÿ™† ๐Ÿ†• ๐Ÿ” โฎ๏ธ ๐ŸŽ ๐Ÿ“Š ๐Ÿ’– ๐Ÿก.
&amp; ๐Ÿ”— โฎ๏ธ ๐ŸŒ ๐Ÿ‘ซ ๐ŸŽ ๐Ÿ•ฐ.
โœ ๐Ÿš™ ๐Ÿ”ข #๏ธโƒฃ ๐Ÿ” ๐Ÿ‘Ÿ โšช๏ธโžก๏ธ ๐Ÿ‘ฉโ€๐Ÿ’ป.
&amp; โž•1๏ธโƒฃ ๐Ÿš™ โœ” ๐Ÿšฅ ๐Ÿ“จ ๐Ÿ” ๐Ÿ #๏ธโƒฃ ๐Ÿช.
&amp; โž•1๏ธโƒฃ 1๏ธโƒฃ ๐Ÿ”“ &amp; ๐Ÿ“จ ๐Ÿ‘ฉโ€๐Ÿ’ป.
=== "๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="7 48 55-56 59-60 69-75"
{!> ../../../docs_src/security/tutorial004.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.1๏ธโƒฃ0๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="6 47 54-55 58-59 68-74"
{!> ../../../docs_src/security/tutorial004_py310.py!}
```
!!! note
๐Ÿšฅ ๐Ÿ‘† โœ… ๐Ÿ†• (โŒ) ๐Ÿ’ฝ `fake_users_db`, ๐Ÿ‘† ๐Ÿ”œ ๐Ÿ‘€ โ” #๏ธโƒฃ ๐Ÿ” ๐Ÿ‘€ ๐Ÿ’– ๐Ÿ”œ: `"$2b$12$EixZaYVK1fsbw1ZfbX3OXePaWxn96p36WQoeG6Lruj3vjPGga31lW"`.
## ๐Ÿต ๐Ÿฅ™ ๐Ÿค
๐Ÿ—„ ๐Ÿ•น โŽ.
โœ ๐ŸŽฒ ใŠ™ ๐Ÿ”‘ ๐Ÿ‘ˆ ๐Ÿ”œ โš™๏ธ ๐Ÿ›‘ ๐Ÿฅ™ ๐Ÿค.
๐Ÿ— ๐Ÿ” ๐ŸŽฒ ใŠ™ ๐Ÿ”‘ โš™๏ธ ๐Ÿ“‹:
<div class="termy">
```console
$ openssl rand -hex 32
09d25e094faa6ca2556c818166b7a9563b93f7099f6f0f4caa6cf63b88e8d3e7
```
</div>
&amp; ๐Ÿ“ ๐Ÿ”ข ๐Ÿ”ข `SECRET_KEY` (๐Ÿšซ โš™๏ธ 1๏ธโƒฃ ๐Ÿ–ผ).
โœ ๐Ÿ”ข `ALGORITHM` โฎ๏ธ ๐Ÿ“Š โš™๏ธ ๐Ÿ›‘ ๐Ÿฅ™ ๐Ÿค &amp; โš’ โšซ๏ธ `"HS256"`.
โœ ๐Ÿ”ข ๐Ÿ‘” ๐Ÿค.
๐Ÿ”ฌ Pydantic ๐Ÿท ๐Ÿ‘ˆ ๐Ÿ”œ โš™๏ธ ๐Ÿค ๐Ÿ”— ๐Ÿ“จ.
โœ ๐Ÿš™ ๐Ÿ”ข ๐Ÿ— ๐Ÿ†• ๐Ÿ” ๐Ÿค.
=== "๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="6 12-14 28-30 78-86"
{!> ../../../docs_src/security/tutorial004.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.1๏ธโƒฃ0๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="5 11-13 27-29 77-85"
{!> ../../../docs_src/security/tutorial004_py310.py!}
```
## โ„น ๐Ÿ”—
โ„น `get_current_user` ๐Ÿ“จ ๐ŸŽ ๐Ÿค โญ, โœ‹๏ธ ๐Ÿ‘‰ ๐Ÿ•ฐ, โš™๏ธ ๐Ÿฅ™ ๐Ÿค.
๐Ÿ”ฃ ๐Ÿ“จ ๐Ÿค, โœ” โšซ๏ธ, &amp; ๐Ÿ“จ โฎ๏ธ ๐Ÿ‘ฉโ€๐Ÿ’ป.
๐Ÿšฅ ๐Ÿค โŒ, ๐Ÿ“จ ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ” โŒ โ–ถ๏ธ๏ธ โ†–๏ธ.
=== "๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="89-106"
{!> ../../../docs_src/security/tutorial004.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.1๏ธโƒฃ0๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="88-105"
{!> ../../../docs_src/security/tutorial004_py310.py!}
```
## โ„น `/token` *โžก ๐Ÿ› ๏ธ*
โœ `timedelta` โฎ๏ธ ๐Ÿ‘” ๐Ÿ•ฐ ๐Ÿค.
โœ ๐ŸŽฐ ๐Ÿฅ™ ๐Ÿ” ๐Ÿค &amp; ๐Ÿ“จ โšซ๏ธ.
=== "๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="115-128"
{!> ../../../docs_src/security/tutorial004.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.1๏ธโƒฃ0๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="114-127"
{!> ../../../docs_src/security/tutorial004_py310.py!}
```
### ๐Ÿ“ก โ„น ๐Ÿ”ƒ ๐Ÿฅ™ "๐Ÿ“„" `sub`
๐Ÿฅ™ ๐Ÿ”ง ๐Ÿ’ฌ ๐Ÿ‘ˆ ๐Ÿ“ค ๐Ÿ”‘ `sub`, โฎ๏ธ ๐Ÿ“„ ๐Ÿค.
โšซ๏ธ ๐Ÿ“ฆ โš™๏ธ โšซ๏ธ, โœ‹๏ธ ๐Ÿ‘ˆ ๐ŸŒโ” ๐Ÿ‘† ๐Ÿ”œ ๐Ÿšฎ ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ†”, ๐Ÿ‘ฅ โš™๏ธ โšซ๏ธ ๐Ÿ“ฅ.
๐Ÿฅ™ 5๏ธโƒฃ๐Ÿ“† โš™๏ธ ๐ŸŽ ๐Ÿ‘œ โ†–๏ธ โšช๏ธโžก๏ธ โš– ๐Ÿ‘ฉโ€๐Ÿ’ป &amp; ๐Ÿค ๐Ÿ‘ซ ๐ŸŽญ ๐Ÿ› ๏ธ ๐Ÿ”— ๐Ÿ”› ๐Ÿ‘† ๐Ÿ› ๏ธ.
๐Ÿ–ผ, ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ”ฌ "๐Ÿš˜" โš–๏ธ "๐Ÿ“ฐ ๐Ÿค".
โคด๏ธ ๐Ÿ‘† ๐Ÿ’ช ๐Ÿšฎ โœ” ๐Ÿ”ƒ ๐Ÿ‘ˆ ๐Ÿ‘จโ€๐Ÿ’ผ, ๐Ÿ’– "๐Ÿ’พ" (๐Ÿš˜) โš–๏ธ "โœ" (๐Ÿ“ฐ).
&amp; โคด๏ธ, ๐Ÿ‘† ๐Ÿ’ช ๐Ÿค ๐Ÿ‘ˆ ๐Ÿฅ™ ๐Ÿค ๐Ÿ‘ฉโ€๐Ÿ’ป (โš–๏ธ ๐Ÿค–), &amp; ๐Ÿ‘ซ ๐Ÿ’ช โš™๏ธ โšซ๏ธ ๐ŸŽญ ๐Ÿ‘ˆ ๐ŸŽฏ (๐Ÿ’พ ๐Ÿš˜, โš–๏ธ โœ ๐Ÿ“ฐ ๐Ÿค) ๐Ÿต ๐Ÿ’†โ€โ™‚ โœ”๏ธ ๐Ÿง, โฎ๏ธ ๐Ÿฅ™ ๐Ÿค ๐Ÿ‘† ๐Ÿ› ๏ธ ๐Ÿ— ๐Ÿ‘ˆ.
โš™๏ธ ๐Ÿ‘ซ ๐Ÿ’ญ, ๐Ÿฅ™ ๐Ÿ’ช โš™๏ธ ๐ŸŒŒ ๐ŸŒ– ๐Ÿค“ ๐Ÿ˜.
๐Ÿ“š ๐Ÿ’ผ, ๐Ÿ“š ๐Ÿ‘ˆ ๐Ÿ‘จโ€๐Ÿ’ผ ๐Ÿ’ช โœ”๏ธ ๐ŸŽ ๐Ÿ†”, โžก๏ธ ๐Ÿ’ฌ `foo` (๐Ÿ‘ฉโ€๐Ÿ’ป `foo`, ๐Ÿš˜ `foo`, &amp; ๐Ÿ“ฐ ๐Ÿค `foo`).
, โŽ ๐Ÿ†” ๐Ÿ’ฅ, ๐Ÿ•โ” ๐Ÿ— ๐Ÿฅ™ ๐Ÿค ๐Ÿ‘ฉโ€๐Ÿ’ป, ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ”ก ๐Ÿ’ฒ `sub` ๐Ÿ”‘, โœ… โฎ๏ธ `username:`. , ๐Ÿ‘‰ ๐Ÿ–ผ, ๐Ÿ’ฒ `sub` ๐Ÿ’ช โœ”๏ธ: `username:johndoe`.
โš  ๐Ÿ‘œ โœ”๏ธ ๐Ÿคฏ ๐Ÿ‘ˆ `sub` ๐Ÿ”‘ ๐Ÿ”œ โœ”๏ธ ๐Ÿ˜ ๐Ÿ†” ๐Ÿคญ ๐ŸŽ‚ ๐Ÿˆธ, &amp; โšซ๏ธ ๐Ÿ”œ ๐ŸŽป.
## โœ… โšซ๏ธ
๐Ÿƒ ๐Ÿ’ฝ &amp; ๐Ÿšถ ๐Ÿฉบ: <a href="http://127.0.0.1:8000/docs" class="external-link" target="_blank">http://127.0.0.1:8000/docs</a>.
๐Ÿ‘† ๐Ÿ”œ ๐Ÿ‘€ ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ”ข ๐Ÿ’–:
<img src="/img/tutorial/security/image07.png">
โœ” ๐Ÿˆธ ๐ŸŽ ๐ŸŒŒ โญ.
โš™๏ธ ๐ŸŽ“:
๐Ÿ†”: `johndoe`
๐Ÿ”: `secret`
!!! check
๐Ÿ‘€ ๐Ÿ‘ˆ ๐Ÿ•ณ ๐Ÿ“Ÿ ๐Ÿ”ข ๐Ÿ” "`secret`", ๐Ÿ‘ฅ ๐Ÿ•ด โœ”๏ธ #๏ธโƒฃ โฌ.
<img src="/img/tutorial/security/image08.png">
๐Ÿค™ ๐Ÿ”— `/users/me/`, ๐Ÿ‘† ๐Ÿ”œ ๐Ÿคš ๐Ÿ“จ:
```JSON
{
"username": "johndoe",
"email": "[email protected]",
"full_name": "John Doe",
"disabled": false
}
```
<img src="/img/tutorial/security/image09.png">
๐Ÿšฅ ๐Ÿ‘† ๐Ÿ“‚ ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿงฐ, ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ‘€ โ” ๐Ÿ“Š ๐Ÿ“จ ๐Ÿ•ด ๐Ÿ”Œ ๐Ÿค, ๐Ÿ” ๐Ÿ•ด ๐Ÿ“จ ๐Ÿฅ‡ ๐Ÿ“จ ๐Ÿ”“ ๐Ÿ‘ฉโ€๐Ÿ’ป &amp; ๐Ÿคš ๐Ÿ‘ˆ ๐Ÿ” ๐Ÿค, โœ‹๏ธ ๐Ÿšซ โฎ๏ธ:
<img src="/img/tutorial/security/image10.png">
!!! note
๐Ÿ‘€ ๐ŸŽš `Authorization`, โฎ๏ธ ๐Ÿ’ฒ ๐Ÿ‘ˆ โ–ถ๏ธ โฎ๏ธ `Bearer `.
## ๐Ÿง โš™๏ธ โฎ๏ธ `scopes`
Oauth2๏ธโƒฃ โœ”๏ธ ๐Ÿ”‘ "โ†”".
๐Ÿ‘† ๐Ÿ’ช โš™๏ธ ๐Ÿ‘ซ ๐Ÿšฎ ๐ŸŽฏ โš’ โœ” ๐Ÿฅ™ ๐Ÿค.
โคด๏ธ ๐Ÿ‘† ๐Ÿ’ช ๐Ÿค ๐Ÿ‘‰ ๐Ÿค ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ”— โš–๏ธ ๐Ÿฅ‰ ๐Ÿฅณ, ๐Ÿ”— โฎ๏ธ ๐Ÿ‘† ๐Ÿ› ๏ธ โฎ๏ธ โš’ ๐Ÿšซ.
๐Ÿ‘† ๐Ÿ’ช ๐Ÿ’ก โ” โš™๏ธ ๐Ÿ‘ซ &amp; โ” ๐Ÿ‘ซ ๐Ÿ› ๏ธ ๐Ÿ”˜ **FastAPI** โช **๐Ÿง ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿฆฎ**.
## ๐ŸŒƒ
โฎ๏ธ โšซ๏ธโ” ๐Ÿ‘† โœ”๏ธ ๐Ÿ‘€ ๐Ÿ†™ ๐Ÿ”œ, ๐Ÿ‘† ๐Ÿ’ช โš’ ๐Ÿ†™ ๐Ÿ” **FastAPI** ๐Ÿˆธ โš™๏ธ ๐Ÿฉ ๐Ÿ’– Oauth2๏ธโƒฃ &amp; ๐Ÿฅ™.
๐ŸŒ– ๐Ÿ™† ๐Ÿ› ๏ธ ๐Ÿšš ๐Ÿ’‚โ€โ™‚ โ–ถ๏ธ๏ธ ๐Ÿ‘ ๐Ÿ— ๐Ÿ“„ ๐Ÿ”œ.
๐Ÿ“š ๐Ÿ“ฆ ๐Ÿ‘ˆ ๐Ÿ“‰ โšซ๏ธ ๐Ÿ“š โœ”๏ธ โš’ ๐Ÿ“š โš  โฎ๏ธ ๐Ÿ’ฝ ๐Ÿท, ๐Ÿ’ฝ, &amp; ๐Ÿ’ช โš’. &amp; ๐Ÿ‘‰ ๐Ÿ“ฆ ๐Ÿ‘ˆ ๐Ÿ“‰ ๐Ÿ‘œ ๐Ÿ’โ€โ™‚๏ธ ๐ŸŒ… ๐Ÿค™ โœ”๏ธ ๐Ÿ’‚โ€โ™‚ โš  ๐Ÿ”˜.
---
**FastAPI** ๐Ÿšซ โš’ ๐Ÿ™† โš  โฎ๏ธ ๐Ÿ™† ๐Ÿ’ฝ, ๐Ÿ’ฝ ๐Ÿท โš–๏ธ ๐Ÿงฐ.
โšซ๏ธ ๐Ÿค ๐Ÿ‘† ๐ŸŒ ๐Ÿ’ช โš’ ๐Ÿ• ๐Ÿ‘ˆ ๐Ÿ‘– ๐Ÿ‘† ๐Ÿ— ๐Ÿ†.
&amp; ๐Ÿ‘† ๐Ÿ’ช โš™๏ธ ๐Ÿ”— ๐Ÿ“š ๐Ÿ‘ ๐Ÿšง &amp; ๐Ÿ›Ž โš™๏ธ ๐Ÿ“ฆ ๐Ÿ’– `passlib` &amp; `python-jose`, โ†ฉ๏ธ **FastAPI** ๐Ÿšซ ๐Ÿšš ๐Ÿ™† ๐Ÿ— ๐Ÿ› ๏ธ ๐Ÿ› ๏ธ ๐Ÿ”ข ๐Ÿ“ฆ.
โœ‹๏ธ โšซ๏ธ ๐Ÿšš ๐Ÿ‘† ๐Ÿงฐ ๐Ÿ“‰ ๐Ÿ› ๏ธ ๐ŸŒ… ๐Ÿ’ช ๐Ÿต ๐ŸŽฏ ๐Ÿ’ช, โš–, โš–๏ธ ๐Ÿ’‚โ€โ™‚.
&amp; ๐Ÿ‘† ๐Ÿ’ช โš™๏ธ &amp; ๐Ÿ› ๏ธ ๐Ÿ”, ๐Ÿฉ ๐Ÿ› ๏ธ, ๐Ÿ’– Oauth2๏ธโƒฃ ๐Ÿ“ถ ๐Ÿ™… ๐ŸŒŒ.
๐Ÿ‘† ๐Ÿ’ช ๐Ÿ’ก ๐ŸŒ… **๐Ÿง ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿฆฎ** ๐Ÿ”ƒ โ” โš™๏ธ Oauth2๏ธโƒฃ "โ†”", ๐ŸŒ– ๐Ÿ‘Œ-๐Ÿงฝ โœ” โš™๏ธ, ๐Ÿ“„ ๐Ÿ‘ซ ๐ŸŽ ๐Ÿฉ. Oauth2๏ธโƒฃ โฎ๏ธ โ†” ๐Ÿ› ๏ธ โš™๏ธ ๐Ÿ“š ๐Ÿฆ ๐Ÿค ๐Ÿ•โ€๐Ÿฆบ, ๐Ÿ’– ๐Ÿ‘ฑ๐Ÿ“”, ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ”, ๐Ÿ“‚, ๐Ÿคธโ€โ™‚, ๐Ÿ‘ฑ๐Ÿ“”, โ™’๏ธ. โœ” ๐Ÿฅ‰ ๐Ÿฅณ ๐Ÿˆธ ๐Ÿ”— โฎ๏ธ ๐Ÿ‘ซ ๐Ÿ”— ๐Ÿ”› ๐Ÿ‘จโ€๐Ÿ’ผ ๐Ÿ‘ซ ๐Ÿ‘ฉโ€๐Ÿ’ป.

315
docs/em/docs/tutorial/security/simple-oauth2.md

@ -0,0 +1,315 @@
# ๐Ÿ™… Oauth2๏ธโƒฃ โฎ๏ธ ๐Ÿ” &amp; ๐Ÿ“จ
๐Ÿ”œ โžก๏ธ ๐Ÿ— โšช๏ธโžก๏ธ โฎ๏ธ ๐Ÿ“ƒ &amp; ๐Ÿšฎ โŒ ๐Ÿ• โœ”๏ธ ๐Ÿ ๐Ÿ’‚โ€โ™‚ ๐Ÿ’ง.
## ๐Ÿคš `username` &amp; `password`
๐Ÿ‘ฅ ๐Ÿ”œ โš™๏ธ **FastAPI** ๐Ÿ’‚โ€โ™‚ ๐Ÿš™ ๐Ÿคš `username` &amp; `password`.
Oauth2๏ธโƒฃ โœ” ๐Ÿ‘ˆ ๐Ÿ•โ” โš™๏ธ "๐Ÿ” ๐Ÿ’ง" (๐Ÿ‘ˆ ๐Ÿ‘ฅ โš™๏ธ) ๐Ÿ‘ฉโ€๐Ÿ’ป/๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ”œ ๐Ÿ“จ `username` &amp; `password` ๐Ÿ‘ ๐Ÿ“จ ๐Ÿ’ฝ.
&amp; ๐Ÿ”Œ ๐Ÿ’ฌ ๐Ÿ‘ˆ ๐Ÿ‘ โœ”๏ธ ๐ŸŒŸ ๐Ÿ’– ๐Ÿ‘ˆ. `user-name` โš–๏ธ `email` ๐Ÿšซ๐Ÿ”œ ๐Ÿ‘ท.
โœ‹๏ธ ๐Ÿšซ ๐Ÿ˜Ÿ, ๐Ÿ‘† ๐Ÿ’ช ๐ŸŽฆ โšซ๏ธ ๐Ÿ‘† ๐ŸŽ‹ ๐Ÿ‘† ๐Ÿ ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ•ธ.
&amp; ๐Ÿ‘† ๐Ÿ’ฝ ๐Ÿท ๐Ÿ’ช โš™๏ธ ๐Ÿ™† ๐ŸŽ ๐Ÿ“› ๐Ÿ‘† ๐Ÿ’š.
โœ‹๏ธ ๐Ÿ’ณ *โžก ๐Ÿ› ๏ธ*, ๐Ÿ‘ฅ ๐Ÿ’ช โš™๏ธ ๐Ÿ‘‰ ๐Ÿ“› ๐Ÿ”— โฎ๏ธ ๐Ÿ”Œ (&amp; ๐Ÿ’ช, ๐Ÿ–ผ, โš™๏ธ ๐Ÿ› ๏ธ ๐Ÿ› ๏ธ ๐Ÿงพ โš™๏ธ).
๐Ÿ”Œ ๐Ÿ‡ต๐Ÿ‡ธ ๐Ÿ‘ˆ `username` &amp; `password` ๐Ÿ”œ ๐Ÿ“จ ๐Ÿ“จ ๐Ÿ’ฝ (, ๐Ÿ™…โ€โ™‚ ๐ŸŽป ๐Ÿ“ฅ).
### `scope`
๐Ÿ”Œ ๐Ÿ’ฌ ๐Ÿ‘ˆ ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ’ช ๐Ÿ“จ โž•1๏ธโƒฃ ๐Ÿ“จ ๐Ÿ‘ "`scope`".
๐Ÿ“จ ๐Ÿ‘ ๐Ÿ“› `scope` (โญ), โœ‹๏ธ โšซ๏ธ ๐Ÿค™ ๐Ÿ“ ๐ŸŽป โฎ๏ธ "โ†”" ๐ŸŽ ๐Ÿš€.
๐Ÿ”  "โ†”" ๐ŸŽป (๐Ÿต ๐Ÿš€).
๐Ÿ‘ซ ๐Ÿ›Ž โš™๏ธ ๐Ÿ“ฃ ๐ŸŽฏ ๐Ÿ’‚โ€โ™‚ โœ”, ๐Ÿ–ผ:
* `users:read` โš–๏ธ `users:write` โš  ๐Ÿ–ผ.
* `instagram_basic` โš™๏ธ ๐Ÿ‘ฑ๐Ÿ“” / ๐Ÿ‘ฑ๐Ÿ“”.
* `https://www.googleapis.com/auth/drive` โš™๏ธ ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ”.
!!! info
Oauth2๏ธโƒฃ "โ†”" ๐ŸŽป ๐Ÿ‘ˆ ๐Ÿ“ฃ ๐ŸŽฏ โœ” โœ”.
โšซ๏ธ ๐Ÿšซ ๐Ÿค” ๐Ÿšฅ โšซ๏ธ โœ”๏ธ ๐ŸŽ ๐Ÿฆน ๐Ÿ’– `:` โš–๏ธ ๐Ÿšฅ โšซ๏ธ ๐Ÿ“›.
๐Ÿ‘ˆ โ„น ๐Ÿ› ๏ธ ๐ŸŽฏ.
Oauth2๏ธโƒฃ ๐Ÿ‘ซ ๐ŸŽป.
## ๐Ÿ“Ÿ ๐Ÿคš `username` &amp; `password`
๐Ÿ”œ โžก๏ธ โš™๏ธ ๐Ÿš™ ๐Ÿšš **FastAPI** ๐Ÿต ๐Ÿ‘‰.
### `OAuth2PasswordRequestForm`
๐Ÿฅ‡, ๐Ÿ—„ `OAuth2PasswordRequestForm`, &amp; โš™๏ธ โšซ๏ธ ๐Ÿ”— โฎ๏ธ `Depends` *โžก ๐Ÿ› ๏ธ* `/token`:
=== "๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="4 76"
{!> ../../../docs_src/security/tutorial003.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.1๏ธโƒฃ0๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="2 74"
{!> ../../../docs_src/security/tutorial003_py310.py!}
```
`OAuth2PasswordRequestForm` ๐ŸŽ“ ๐Ÿ”— ๐Ÿ‘ˆ ๐Ÿ“ฃ ๐Ÿ“จ ๐Ÿ’ช โฎ๏ธ:
* `username`.
* `password`.
* ๐Ÿ“ฆ `scope` ๐Ÿ‘ ๐Ÿฆ ๐ŸŽป, โœ ๐ŸŽป ๐ŸŽ ๐Ÿš€.
* ๐Ÿ“ฆ `grant_type`.
!!! tip
Oauth2๏ธโƒฃ ๐Ÿ”Œ ๐Ÿค™ *๐Ÿšš* ๐Ÿ‘ `grant_type` โฎ๏ธ ๐Ÿ”ง ๐Ÿ’ฒ `password`, โœ‹๏ธ `OAuth2PasswordRequestForm` ๐Ÿšซ ๐Ÿ› ๏ธ โšซ๏ธ.
๐Ÿšฅ ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ› ๏ธ โšซ๏ธ, โš™๏ธ `OAuth2PasswordRequestFormStrict` โ†ฉ๏ธ `OAuth2PasswordRequestForm`.
* ๐Ÿ“ฆ `client_id` (๐Ÿ‘ฅ ๐Ÿšซ ๐Ÿ’ช โšซ๏ธ ๐Ÿ‘† ๐Ÿ–ผ).
* ๐Ÿ“ฆ `client_secret` (๐Ÿ‘ฅ ๐Ÿšซ ๐Ÿ’ช โšซ๏ธ ๐Ÿ‘† ๐Ÿ–ผ).
!!! info
`OAuth2PasswordRequestForm` ๐Ÿšซ ๐ŸŽ ๐ŸŽ“ **FastAPI** `OAuth2PasswordBearer`.
`OAuth2PasswordBearer` โš’ **FastAPI** ๐Ÿ’ญ ๐Ÿ‘ˆ โšซ๏ธ ๐Ÿ’‚โ€โ™‚ โš–. โšซ๏ธ ๐Ÿšฎ ๐Ÿ‘ˆ ๐ŸŒŒ ๐Ÿ—„.
โœ‹๏ธ `OAuth2PasswordRequestForm` ๐ŸŽ“ ๐Ÿ”— ๐Ÿ‘ˆ ๐Ÿ‘† ๐Ÿ’ช โœ”๏ธ โœ ๐Ÿ‘†, โš–๏ธ ๐Ÿ‘† ๐Ÿ’ช โœ”๏ธ ๐Ÿ“ฃ `Form` ๐Ÿ”ข ๐Ÿ”—.
โœ‹๏ธ โšซ๏ธ โš  โš™๏ธ ๐Ÿ’ผ, โšซ๏ธ ๐Ÿšš **FastAPI** ๐Ÿ”—, โš’ โšซ๏ธ โฉ.
### โš™๏ธ ๐Ÿ“จ ๐Ÿ’ฝ
!!! tip
๐Ÿ‘ ๐Ÿ”— ๐ŸŽ“ `OAuth2PasswordRequestForm` ๐Ÿ† ๐Ÿšซ โœ”๏ธ ๐Ÿ”ข `scope` โฎ๏ธ ๐Ÿ“ ๐ŸŽป ๐Ÿ‘ฝ ๐Ÿš€, โ†ฉ๏ธ, โšซ๏ธ ๐Ÿ”œ โœ”๏ธ `scopes` ๐Ÿ”ข โฎ๏ธ โ˜‘ ๐Ÿ“‡ ๐ŸŽป ๐Ÿ”  โ†” ๐Ÿ“จ.
๐Ÿ‘ฅ ๐Ÿšซ โš™๏ธ `scopes` ๐Ÿ‘‰ ๐Ÿ–ผ, โœ‹๏ธ ๐Ÿ› ๏ธ ๐Ÿ“ค ๐Ÿšฅ ๐Ÿ‘† ๐Ÿ’ช โšซ๏ธ.
๐Ÿ”œ, ๐Ÿคš ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ“Š โšช๏ธโžก๏ธ (โŒ) ๐Ÿ’ฝ, โš™๏ธ `username` โšช๏ธโžก๏ธ ๐Ÿ“จ ๐Ÿ‘.
๐Ÿšฅ ๐Ÿ“ค ๐Ÿ™…โ€โ™‚ โœ… ๐Ÿ‘ฉโ€๐Ÿ’ป, ๐Ÿ‘ฅ ๐Ÿ“จ โŒ ๐Ÿ’ฌ "โŒ ๐Ÿ†” โš–๏ธ ๐Ÿ”".
โŒ, ๐Ÿ‘ฅ โš™๏ธ โš  `HTTPException`:
=== "๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="3 77-79"
{!> ../../../docs_src/security/tutorial003.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.1๏ธโƒฃ0๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="1 75-77"
{!> ../../../docs_src/security/tutorial003_py310.py!}
```
### โœ… ๐Ÿ”
๐Ÿ‘‰ โ˜ ๐Ÿ‘ฅ โœ”๏ธ ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ“Š โšช๏ธโžก๏ธ ๐Ÿ‘† ๐Ÿ’ฝ, โœ‹๏ธ ๐Ÿ‘ฅ ๐Ÿšซ โœ… ๐Ÿ”.
โžก๏ธ ๐Ÿšฎ ๐Ÿ‘ˆ ๐Ÿ’ฝ Pydantic `UserInDB` ๐Ÿท ๐Ÿฅ‡.
๐Ÿ‘† ๐Ÿ”œ ๐Ÿ™… ๐Ÿ–Š ๐Ÿ”ข ๐Ÿ”,, ๐Ÿ‘ฅ ๐Ÿ”œ โš™๏ธ (โŒ) ๐Ÿ” ๐Ÿ” โš™๏ธ.
๐Ÿšฅ ๐Ÿ” ๐Ÿšซ ๐Ÿ, ๐Ÿ‘ฅ ๐Ÿ“จ ๐ŸŽ โŒ.
#### ๐Ÿ” ๐Ÿ”
"๐Ÿ”" โ›“: ๐Ÿญ ๐ŸŽš (๐Ÿ” ๐Ÿ‘‰ ๐Ÿ’ผ) ๐Ÿ”˜ ๐Ÿ” ๐Ÿ”ข (๐ŸŽป) ๐Ÿ‘ˆ ๐Ÿ‘€ ๐Ÿ’– ๐Ÿ™ƒ.
๐Ÿ•โ” ๐Ÿ‘† ๐Ÿšถโ€โ™€๏ธ โšซ๏ธโ” ๐ŸŽ ๐ŸŽš (โšซ๏ธโ” ๐ŸŽ ๐Ÿ”) ๐Ÿ‘† ๐Ÿคš โšซ๏ธโ” ๐ŸŽ ๐Ÿ™ƒ.
โœ‹๏ธ ๐Ÿ‘† ๐Ÿšซ๐Ÿ”œ ๐Ÿ—œ โšช๏ธโžก๏ธ ๐Ÿ™ƒ ๐Ÿ”™ ๐Ÿ”.
##### โšซ๏ธโ” โš™๏ธ ๐Ÿ” ๐Ÿ”
๐Ÿšฅ ๐Ÿ‘† ๐Ÿ’ฝ ๐Ÿ“Ž, ๐Ÿง™โ€โ™€ ๐Ÿ† ๐Ÿšซ โœ”๏ธ ๐Ÿ‘† ๐Ÿ‘ฉโ€๐Ÿ’ป' ๐Ÿ”ข ๐Ÿ”, ๐Ÿ•ด#๏ธโƒฃ.
, ๐Ÿง™โ€โ™€ ๐Ÿ† ๐Ÿšซ ๐Ÿ’ช ๐Ÿ”„ โš™๏ธ ๐Ÿ‘ˆ ๐ŸŽ ๐Ÿ” โž•1๏ธโƒฃ โš™๏ธ (๐Ÿ“š ๐Ÿ‘ฉโ€๐Ÿ’ป โš™๏ธ ๐ŸŽ ๐Ÿ” ๐ŸŒ, ๐Ÿ‘‰ ๐Ÿ”œ โš ).
=== "๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="80-83"
{!> ../../../docs_src/security/tutorial003.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.1๏ธโƒฃ0๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="78-81"
{!> ../../../docs_src/security/tutorial003_py310.py!}
```
#### ๐Ÿ”ƒ `**user_dict`
`UserInDB(**user_dict)` โ›“:
*๐Ÿšถโ€โ™€๏ธ ๐Ÿ”‘ &amp; ๐Ÿ’ฒ `user_dict` ๐Ÿ”— ๐Ÿ”‘-๐Ÿ’ฒ โŒ, ๐ŸŒ“:*
```Python
UserInDB(
username = user_dict["username"],
email = user_dict["email"],
full_name = user_dict["full_name"],
disabled = user_dict["disabled"],
hashed_password = user_dict["hashed_password"],
)
```
!!! info
๐ŸŒ… ๐Ÿ ๐Ÿ”‘ `**๐Ÿ‘ฉโ€๐Ÿ’ป_ #๏ธโƒฃ ` โœ… ๐Ÿ”™ [๐Ÿงพ **โž• ๐Ÿท**](../extra-models.md#about-user_indict){.internal-link target=_blank}.
## ๐Ÿ“จ ๐Ÿค
๐Ÿ“จ `token` ๐Ÿ”— ๐Ÿ”œ ๐ŸŽป ๐ŸŽš.
โšซ๏ธ ๐Ÿ”œ โœ”๏ธ `token_type`. ๐Ÿ‘† ๐Ÿ’ผ, ๐Ÿ‘ฅ โš™๏ธ "๐Ÿ“จ" ๐Ÿค, ๐Ÿค ๐Ÿ†Ž ๐Ÿ”œ "`bearer`".
&amp; โšซ๏ธ ๐Ÿ”œ โœ”๏ธ `access_token`, โฎ๏ธ ๐ŸŽป โš— ๐Ÿ‘† ๐Ÿ” ๐Ÿค.
๐Ÿ‘‰ ๐Ÿ™… ๐Ÿ–ผ, ๐Ÿ‘ฅ ๐Ÿ”œ ๐Ÿ• ๐Ÿ˜Ÿ &amp; ๐Ÿ“จ ๐ŸŽ `username` ๐Ÿค.
!!! tip
โญ ๐Ÿ“ƒ, ๐Ÿ‘† ๐Ÿ”œ ๐Ÿ‘€ ๐ŸŽฐ ๐Ÿ” ๐Ÿ› ๏ธ, โฎ๏ธ ๐Ÿ” #๏ธโƒฃ &amp; <abbr title="JSON Web Tokens">๐Ÿฅ™</abbr> ๐Ÿค.
โœ‹๏ธ ๐Ÿ”œ, โžก๏ธ ๐ŸŽฏ ๐Ÿ”› ๐ŸŽฏ โ„น ๐Ÿ‘ฅ ๐Ÿ’ช.
=== "๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="85"
{!> ../../../docs_src/security/tutorial003.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.1๏ธโƒฃ0๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="83"
{!> ../../../docs_src/security/tutorial003_py310.py!}
```
!!! tip
๐Ÿ”Œ, ๐Ÿ‘† ๐Ÿ”œ ๐Ÿ“จ ๐ŸŽป โฎ๏ธ `access_token` &amp; `token_type`, ๐ŸŽ ๐Ÿ‘‰ ๐Ÿ–ผ.
๐Ÿ‘‰ ๐Ÿ•ณ ๐Ÿ‘ˆ ๐Ÿ‘† โœ”๏ธ ๐Ÿ‘† ๐Ÿ‘† ๐Ÿ“Ÿ, &amp; โš’ ๐Ÿ’ญ ๐Ÿ‘† โš™๏ธ ๐Ÿ“š ๐ŸŽป ๐Ÿ”‘.
โšซ๏ธ ๐ŸŒ– ๐Ÿ•ด ๐Ÿ‘œ ๐Ÿ‘ˆ ๐Ÿ‘† โœ”๏ธ ๐Ÿ’ญ โ˜‘ ๐Ÿ‘†, ๐Ÿ› ๏ธ โฎ๏ธ ๐Ÿ”ง.
๐ŸŽ‚, **FastAPI** ๐Ÿต โšซ๏ธ ๐Ÿ‘†.
## โ„น ๐Ÿ”—
๐Ÿ”œ ๐Ÿ‘ฅ ๐Ÿ”œ โ„น ๐Ÿ‘† ๐Ÿ”—.
๐Ÿ‘ฅ ๐Ÿ’š ๐Ÿคš `current_user` *๐Ÿ•ด* ๐Ÿšฅ ๐Ÿ‘‰ ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿฆ.
, ๐Ÿ‘ฅ โœ ๐ŸŒ– ๐Ÿ”— `get_current_active_user` ๐Ÿ‘ˆ ๐Ÿ”„ โš™๏ธ `get_current_user` ๐Ÿ”—.
๐Ÿ‘ฏโ€โ™‚๏ธ ๐Ÿ‘‰ ๐Ÿ”— ๐Ÿ”œ ๐Ÿ“จ ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ” โŒ ๐Ÿšฅ ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿšซ ๐Ÿ”€, โš–๏ธ ๐Ÿšฅ ๐Ÿ”•.
, ๐Ÿ‘† ๐Ÿ”—, ๐Ÿ‘ฅ ๐Ÿ”œ ๐Ÿ•ด ๐Ÿคš ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿšฅ ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ”€, โ˜‘ ๐Ÿ”“, &amp; ๐Ÿฆ:
=== "๐Ÿ 3๏ธโƒฃ.6๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="58-66 69-72 90"
{!> ../../../docs_src/security/tutorial003.py!}
```
=== "๐Ÿ 3๏ธโƒฃ.1๏ธโƒฃ0๏ธโƒฃ &amp; ๐Ÿ”›"
```Python hl_lines="55-64 67-70 88"
{!> ../../../docs_src/security/tutorial003_py310.py!}
```
!!! info
๐ŸŒ– ๐ŸŽš `WWW-Authenticate` โฎ๏ธ ๐Ÿ’ฒ `Bearer` ๐Ÿ‘ฅ ๐Ÿ›ฌ ๐Ÿ“ฅ ๐Ÿ• ๐Ÿ”Œ.
๐Ÿ™† ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ” (โŒ) ๐Ÿ‘” ๐Ÿ“Ÿ 4๏ธโƒฃ0๏ธโƒฃ1๏ธโƒฃ "โ›”" ๐Ÿค” ๐Ÿ“จ `WWW-Authenticate` ๐ŸŽš.
๐Ÿ’ผ ๐Ÿ“จ ๐Ÿค (๐Ÿ‘† ๐Ÿ’ผ), ๐Ÿ’ฒ ๐Ÿ‘ˆ ๐ŸŽš ๐Ÿ”œ `Bearer`.
๐Ÿ‘† ๐Ÿ’ช ๐Ÿค™ ๐Ÿšถ ๐Ÿ‘ˆ โž• ๐ŸŽš &amp; โšซ๏ธ ๐Ÿ”œ ๐Ÿ‘ท.
โœ‹๏ธ โšซ๏ธ ๐Ÿšš ๐Ÿ“ฅ ๐Ÿ› ๏ธ โฎ๏ธ ๐Ÿ”ง.
, ๐Ÿ“ค 5๏ธโƒฃ๐Ÿ“† ๐Ÿงฐ ๐Ÿ‘ˆ โŒ› &amp; โš™๏ธ โšซ๏ธ (๐Ÿ”œ โš–๏ธ ๐Ÿ”ฎ) &amp; ๐Ÿ‘ˆ ๐Ÿ’ช โš  ๐Ÿ‘† โš–๏ธ ๐Ÿ‘† ๐Ÿ‘ฉโ€๐Ÿ’ป, ๐Ÿ”œ โš–๏ธ ๐Ÿ”ฎ.
๐Ÿ‘ˆ ๐Ÿ’ฐ ๐Ÿฉ...
## ๐Ÿ‘€ โšซ๏ธ ๐ŸŽฏ
๐Ÿ“‚ ๐ŸŽ“ ๐Ÿฉบ: <a href="http://127.0.0.1:8000/docs" class="external-link" target="_blank">http://127.0.0.1:8000/docs</a>.
### ๐Ÿ”“
๐Ÿ–Š "โœ”" ๐Ÿ”ผ.
โš™๏ธ ๐ŸŽ“:
๐Ÿ‘ฉโ€๐Ÿ’ป: `johndoe`
๐Ÿ”: `secret`
<img src="/img/tutorial/security/image04.png">
โฎ๏ธ ๐Ÿ”— โš™๏ธ, ๐Ÿ‘† ๐Ÿ”œ ๐Ÿ‘€ โšซ๏ธ ๐Ÿ’–:
<img src="/img/tutorial/security/image05.png">
### ๐Ÿคš ๐Ÿ‘† ๐Ÿ‘ ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ’ฝ
๐Ÿ”œ โš™๏ธ ๐Ÿ› ๏ธ `GET` โฎ๏ธ โžก `/users/me`.
๐Ÿ‘† ๐Ÿ”œ ๐Ÿคš ๐Ÿ‘† ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ“Š, ๐Ÿ’–:
```JSON
{
"username": "johndoe",
"email": "[email protected]",
"full_name": "John Doe",
"disabled": false,
"hashed_password": "fakehashedsecret"
}
```
<img src="/img/tutorial/security/image06.png">
๐Ÿšฅ ๐Ÿ‘† ๐Ÿ–Š ๐Ÿ”’ โ„น &amp; โ, &amp; โคด๏ธ ๐Ÿ”„ ๐ŸŽ ๐Ÿ› ๏ธ ๐Ÿ”„, ๐Ÿ‘† ๐Ÿ”œ ๐Ÿคš ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ” 4๏ธโƒฃ0๏ธโƒฃ1๏ธโƒฃ โŒ:
```JSON
{
"detail": "Not authenticated"
}
```
### ๐Ÿ”• ๐Ÿ‘ฉโ€๐Ÿ’ป
๐Ÿ”œ ๐Ÿ”„ โฎ๏ธ ๐Ÿ”• ๐Ÿ‘ฉโ€๐Ÿ’ป, ๐Ÿ”“ โฎ๏ธ:
๐Ÿ‘ฉโ€๐Ÿ’ป: `alice`
๐Ÿ”: `secret2`
&amp; ๐Ÿ”„ โš™๏ธ ๐Ÿ› ๏ธ `GET` โฎ๏ธ โžก `/users/me`.
๐Ÿ‘† ๐Ÿ”œ ๐Ÿคš "๐Ÿ”• ๐Ÿ‘ฉโ€๐Ÿ’ป" โŒ, ๐Ÿ’–:
```JSON
{
"detail": "Inactive user"
}
```
## ๐ŸŒƒ
๐Ÿ‘† ๐Ÿ”œ โœ”๏ธ ๐Ÿงฐ ๐Ÿ› ๏ธ ๐Ÿ ๐Ÿ’‚โ€โ™‚ โš™๏ธ โš“๏ธ ๐Ÿ”› `username` &amp; `password` ๐Ÿ‘† ๐Ÿ› ๏ธ.
โš™๏ธ ๐Ÿ‘ซ ๐Ÿงฐ, ๐Ÿ‘† ๐Ÿ’ช โš’ ๐Ÿ’‚โ€โ™‚ โš™๏ธ ๐Ÿ”— โฎ๏ธ ๐Ÿ™† ๐Ÿ’ฝ &amp; โฎ๏ธ ๐Ÿ™† ๐Ÿ‘ฉโ€๐Ÿ’ป โš–๏ธ ๐Ÿ’ฝ ๐Ÿท.
๐Ÿ•ด โ„น โŒ ๐Ÿ‘ˆ โšซ๏ธ ๐Ÿšซ ๐Ÿค™ "๐Ÿ”".
โญ ๐Ÿ“ƒ ๐Ÿ‘† ๐Ÿ”œ ๐Ÿ‘€ โ” โš™๏ธ ๐Ÿ” ๐Ÿ” ๐Ÿ” ๐Ÿ—ƒ &amp; <abbr title="JSON Web Tokens">๐Ÿฅ™</abbr> ๐Ÿค.

Some files were not shown because too many files changed in this diff

Loadingโ€ฆ
Cancel
Save