Browse Source

๐ŸŒ Add Korean translation for Tutorial - Query Parameters (#2390)

Co-authored-by: Sebastiรกn Ramรญrez <[email protected]>
pull/3173/head
Spike 4 years ago
committed by GitHub
parent
commit
388e5c0c25
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 198
      docs/ko/docs/tutorial/query-params.md
  2. 1
      docs/ko/mkdocs.yml

198
docs/ko/docs/tutorial/query-params.md

@ -0,0 +1,198 @@
# ์ฟผ๋ฆฌ ๋งค๊ฐœ๋ณ€์ˆ˜
๊ฒฝ๋กœ ๋งค๊ฐœ๋ณ€์ˆ˜์˜ ์ผ๋ถ€๊ฐ€ ์•„๋‹Œ ๋‹ค๋ฅธ ํ•จ์ˆ˜ ๋งค๊ฐœ๋ณ€์ˆ˜๋ฅผ ์„ ์–ธํ•  ๋•Œ, "์ฟผ๋ฆฌ" ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์ž๋™ ํ•ด์„ํ•ฉ๋‹ˆ๋‹ค.
```Python hl_lines="9"
{!../../../docs_src/query_params/tutorial001.py!}
```
์ฟผ๋ฆฌ๋Š” URL์—์„œ `?` ํ›„์— ๋‚˜์˜ค๊ณ  `&`์œผ๋กœ ๊ตฌ๋ถ„๋˜๋Š” ํ‚ค-๊ฐ’ ์Œ์˜ ์ง‘ํ•ฉ์ž…๋‹ˆ๋‹ค.
์˜ˆ๋ฅผ ๋“ค์–ด, URL์—์„œ:
```
http://127.0.0.1:8000/items/?skip=0&limit=10
```
...์ฟผ๋ฆฌ ๋งค๊ฐœ๋ณ€์ˆ˜๋Š”:
* `skip`: ๊ฐ’ `0`์„ ๊ฐ€์ง‘๋‹ˆ๋‹ค.
* `limit`: ๊ฐ’ `10`์„ ๊ฐ€์ง‘๋‹ˆ๋‹ค.
URL์˜ ์ผ๋ถ€์ด๋ฏ€๋กœ "์ž์—ฐ์Šค๋Ÿฝ๊ฒŒ" ๋ฌธ์ž์—ด์ž…๋‹ˆ๋‹ค.
ํ•˜์ง€๋งŒ ํŒŒ์ด์ฌ ํƒ€์ž…๊ณผ ํ•จ๊ป˜ ์„ ์–ธํ•  ๊ฒฝ์šฐ(์œ„ ์˜ˆ์—์„œ `int`), ํ•ด๋‹น ํƒ€์ž…์œผ๋กœ ๋ณ€ํ™˜๋˜๊ณ  ์ด์— ๋Œ€ํ•ด ๊ฒ€์ฆํ•ฉ๋‹ˆ๋‹ค.
๊ฒฝ๋กœ ๋งค๊ฐœ๋ณ€์ˆ˜์— ์ ์šฉ๋œ ๋™์ผํ•œ ํ”„๋กœ์„ธ์Šค๊ฐ€ ์ฟผ๋ฆฌ ๋งค๊ฐœ๋ณ€์ˆ˜์—๋„ ์ ์šฉ๋ฉ๋‹ˆ๋‹ค:
* (๋‹น์—ฐํžˆ) ํŽธ์ง‘๊ธฐ ์ง€์›
* ๋ฐ์ดํ„ฐ <abbr title="HTTP ์š”์ฒญ์—์„œ ์ „๋‹ฌ๋˜๋Š” ๋ฌธ์ž์—ด์„ ํŒŒ์ด์ฌ ๋ฐ์ดํ„ฐ๋กœ ๋ณ€ํ™˜">"ํŒŒ์‹ฑ"</abbr>
* ๋ฐ์ดํ„ฐ ๊ฒ€์ฆ
* ์ž๋™ ๋ฌธ์„œํ™”
## ๊ธฐ๋ณธ๊ฐ’
์ฟผ๋ฆฌ ๋งค๊ฐœ๋ณ€์ˆ˜๋Š” ๊ฒฝ๋กœ์—์„œ ๊ณ ์ •๋œ ๋ถ€๋ถ„์ด ์•„๋‹ˆ๊ธฐ ๋•Œ๋ฌธ์— ์„ ํƒ์ ์ผ ์ˆ˜ ์žˆ๊ณ  ๊ธฐ๋ณธ๊ฐ’์„ ๊ฐ€์งˆ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
์œ„ ์˜ˆ์—์„œ `skip=0`๊ณผ `limit=10`์€ ๊ธฐ๋ณธ๊ฐ’์„ ๊ฐ–๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.
๊ทธ๋Ÿฌ๋ฏ€๋กœ URL๋กœ ์ด๋™ํ•˜๋ฉด:
```
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`: URL์—์„œ ์ง€์ •ํ–ˆ๊ธฐ ๋•Œ๋ฌธ์ž…๋‹ˆ๋‹ค
* `limit=10`: ๊ธฐ๋ณธ๊ฐ’์ด๊ธฐ ๋•Œ๋ฌธ์ž…๋‹ˆ๋‹ค
## ์„ ํƒ์  ๋งค๊ฐœ๋ณ€์ˆ˜
๊ฐ™์€ ๋ฐฉ๋ฒ•์œผ๋กœ ๊ธฐ๋ณธ๊ฐ’์„ `None`์œผ๋กœ ์„ค์ •ํ•˜์—ฌ ์„ ํƒ์  ๋งค๊ฐœ๋ณ€์ˆ˜๋ฅผ ์„ ์–ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค:
```Python hl_lines="9"
{!../../../docs_src/query_params/tutorial002.py!}
```
์ด ๊ฒฝ์šฐ ํ•จ์ˆ˜ ๋งค๊ฐœ๋ณ€์ˆ˜ `q`๋Š” ์„ ํƒ์ ์ด๋ฉฐ ๊ธฐ๋ณธ๊ฐ’์œผ๋กœ `None` ๊ฐ’์ด ๋ฉ๋‹ˆ๋‹ค.
!!! check "ํ™•์ธ"
**FastAPI**๋Š” `item_id`๊ฐ€ ๊ฒฝ๋กœ ๋งค๊ฐœ๋ณ€์ˆ˜์ด๊ณ  `q`๋Š” ๊ฒฝ๋กœ ๋งค๊ฐœ๋ณ€์ˆ˜๊ฐ€ ์•„๋‹Œ ์ฟผ๋ฆฌ ๋งค๊ฐœ๋ณ€์ˆ˜๋ผ๋Š” ๊ฒƒ์„ ์•Œ ์ •๋„๋กœ ์ถฉ๋ถ„ํžˆ ๋˜‘๋˜‘ํ•ฉ๋‹ˆ๋‹ค.
!!! note "์ฐธ๊ณ "
FastAPI๋Š” `q`๊ฐ€ `= None`์ด๋ฏ€๋กœ ์„ ํƒ์ ์ด๋ผ๋Š” ๊ฒƒ์„ ์ธ์ง€ํ•ฉ๋‹ˆ๋‹ค.
`Optional[str]`์— ์žˆ๋Š” `Optional`์€ FastAPI(FastAPI๋Š” `str` ๋ถ€๋ถ„๋งŒ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค)๊ฐ€ ์‚ฌ์šฉํ•˜๋Š”๊ฒŒ ์•„๋‹ˆ์ง€๋งŒ, `Optional[str]`์€ ํŽธ์ง‘๊ธฐ์—๊ฒŒ ์ฝ”๋“œ์—์„œ ์˜ค๋ฅ˜๋ฅผ ์ฐพ์•„๋‚ผ ์ˆ˜ ์žˆ๊ฒŒ ๋„์™€์ค๋‹ˆ๋‹ค.
## ์ฟผ๋ฆฌ ๋งค๊ฐœ๋ณ€์ˆ˜ ํ˜•๋ณ€ํ™˜
`bool` ํ˜•์œผ๋กœ ์„ ์–ธํ•  ์ˆ˜๋„ ์žˆ๊ณ , ์•„๋ž˜์ฒ˜๋Ÿผ ๋ณ€ํ™˜๋ฉ๋‹ˆ๋‹ค:
```Python hl_lines="9"
{!../../../docs_src/query_params/tutorial003.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
```
๋˜๋Š” ๋‹ค๋ฅธ ์–ด๋–ค ๋ณ€ํ˜•(๋Œ€๋ฌธ์ž, ์ฒซ๊ธ€์ž๋งŒ ๋Œ€๋ฌธ์ž ๋“ฑ)์ด๋”๋ผ๋„ ํ•จ์ˆ˜๋Š” ๋งค๊ฐœ๋ณ€์ˆ˜ `bool`ํ˜•์„ ๊ฐ€์ง„ `short`์˜ ๊ฐ’์ด `True`์ž„์„ ์••๋‹ˆ๋‹ค. ๊ทธ๋ ‡์ง€ ์•Š์€ ๊ฒฝ์šฐ `False`์ž…๋‹ˆ๋‹ค.
## ์—ฌ๋Ÿฌ ๊ฒฝ๋กœ/์ฟผ๋ฆฌ ๋งค๊ฐœ๋ณ€์ˆ˜
์—ฌ๋Ÿฌ ๊ฒฝ๋กœ ๋งค๊ฐœ๋ณ€์ˆ˜์™€ ์ฟผ๋ฆฌ ๋งค๊ฐœ๋ณ€์ˆ˜๋ฅผ ๋™์‹œ์— ์„ ์–ธํ•  ์ˆ˜ ์žˆ์œผ๋ฉฐ **FastAPI**๋Š” ์–ด๋Š ๊ฒƒ์ด ๋ฌด์—‡์ธ์ง€ ์•Œ๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.
๊ทธ๋ฆฌ๊ณ  ํŠน์ • ์ˆœ์„œ๋กœ ์„ ์–ธํ•  ํ•„์š”๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค.
๋งค๊ฐœ๋ณ€์ˆ˜๋“ค์€ ์ด๋ฆ„์œผ๋กœ ๊ฐ์ง€๋ฉ๋‹ˆ๋‹ค:
```Python hl_lines="8 10"
{!../../../docs_src/query_params/tutorial004.py!}
```
## ํ•„์ˆ˜ ์ฟผ๋ฆฌ ๋งค๊ฐœ๋ณ€์ˆ˜
๊ฒฝ๋กœ๊ฐ€ ์•„๋‹Œ ๋งค๊ฐœ๋ณ€์ˆ˜์— ๋Œ€ํ•œ ๊ธฐ๋ณธ๊ฐ’์„ ์„ ์–ธํ•  ๋•Œ(์ง€๊ธˆ์€ ์ฟผ๋ฆฌ ๋งค๊ฐœ๋ณ€์ˆ˜๋งŒ ๋ณด์•˜์Šต๋‹ˆ๋‹ค), ํ•ด๋‹น ๋งค๊ฐœ๋ณ€์ˆ˜๋Š” ํ•„์ˆ˜์ (Required)์ด์ง€ ์•Š์•˜์Šต๋‹ˆ๋‹ค.
ํŠน์ •๊ฐ’์„ ์ถ”๊ฐ€ํ•˜์ง€ ์•Š๊ณ  ์„ ํƒ์ ์œผ๋กœ ๋งŒ๋“ค๊ธฐ ์œ„ํ•ด์„  ๊ธฐ๋ณธ๊ฐ’์„ `None`์œผ๋กœ ์„ค์ •ํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค.
๊ทธ๋Ÿฌ๋‚˜ ์ฟผ๋ฆฌ ๋งค๊ฐœ๋ณ€์ˆ˜๋ฅผ ํ•„์ˆ˜๋กœ ๋งŒ๋“ค๋ ค๋ฉด ๊ธฐ๋ณธ๊ฐ’์„ ์„ ์–ธํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค:
```Python hl_lines="6-7"
{!../../../docs_src/query_params/tutorial005.py!}
```
์—ฌ๊ธฐ ์ฟผ๋ฆฌ ๋งค๊ฐœ๋ณ€์ˆ˜ `needy`๋Š” `str`ํ˜•์ธ ํ•„์ˆ˜ ์ฟผ๋ฆฌ ๋งค๊ฐœ๋ณ€์ˆ˜์ž…๋‹ˆ๋‹ค.
๋ธŒ๋ผ์šฐ์ €์—์„œ URL์„ ์•„๋ž˜์ฒ˜๋Ÿผ ์—ฐ๋‹ค๋ฉด:
```
http://127.0.0.1:8000/items/foo-item
```
...ํ•„์ˆ˜ ๋งค๊ฐœ๋ณ€์ˆ˜ `needy`๋ฅผ ๋„ฃ์ง€ ์•Š์•˜๊ธฐ ๋•Œ๋ฌธ์— ์•„๋ž˜์™€ ๊ฐ™์€ ์˜ค๋ฅ˜๋ฅผ ๋ณด๊ฒŒ ๋ฉ๋‹ˆ๋‹ค:
```JSON
{
"detail": [
{
"loc": [
"query",
"needy"
],
"msg": "field required",
"type": "value_error.missing"
}
]
}
```
`needy`๋Š” ํ•„์ˆ˜ ๋งค๊ฐœ๋ณ€์ˆ˜์ด๋ฏ€๋กœ URL์— ๋ฐ˜๋“œ์‹œ ์„ค์ •ํ•ด์ค˜์•ผ ํ•ฉ๋‹ˆ๋‹ค:
```
http://127.0.0.1:8000/items/foo-item?needy=sooooneedy
```
...์•„๋ž˜์ฒ˜๋Ÿผ ์ž‘๋™ํ•ฉ๋‹ˆ๋‹ค:
```JSON
{
"item_id": "foo-item",
"needy": "sooooneedy"
}
```
๊ทธ๋ฆฌ๊ณ  ๋ฌผ๋ก , ์ผ๋ถ€ ๋งค๊ฐœ๋ณ€์ˆ˜๋Š” ํ•„์ˆ˜๋กœ, ๋‹ค๋ฅธ ์ผ๋ถ€๋Š” ๊ธฐ๋ณธ๊ฐ’์„, ๋˜ ๋‹ค๋ฅธ ์ผ๋ถ€๋Š” ์„ ํƒ์ ์œผ๋กœ ์„ ์–ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค:
```Python hl_lines="10"
{!../../../docs_src/query_params/tutorial006.py!}
```
์ด ๊ฒฝ์šฐ 3๊ฐ€์ง€ ์ฟผ๋ฆฌ ๋งค๊ฐœ๋ณ€์ˆ˜๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค:
* `needy`, ํ•„์ˆ˜์ ์ธ `str`.
* `skip`, ๊ธฐ๋ณธ๊ฐ’์ด `0`์ธ `int`.
* `limit`, ์„ ํƒ์ ์ธ `int`.
!!! tip "ํŒ"
[๊ฒฝ๋กœ ๋งค๊ฐœ๋ณ€์ˆ˜](path-params.md#predefined-values){.internal-link target=_blank}์™€ ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ `Enum`์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

1
docs/ko/mkdocs.yml

@ -54,6 +54,7 @@ nav:
- tutorial/index.md
- tutorial/first-steps.md
- tutorial/path-params.md
- tutorial/query-params.md
- tutorial/header-params.md
markdown_extensions:
- toc:

Loadingโ€ฆ
Cancel
Save