Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions docs/ko/docs/_llm-test.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

//// tab | ν…ŒμŠ€νŠΈ

μ–΄μ œ 제 μΉœκ΅¬κ°€ μ΄λ ‡κ²Œ μΌμŠ΅λ‹ˆλ‹€: "If you spell incorrectly correctly, you have spelled it incorrectly". 이에 μ €λŠ” μ΄λ ‡κ²Œ λ‹΅ν–ˆμŠ΅λ‹ˆλ‹€: "Correct, but 'incorrectly' is incorrectly not '"incorrectly"'"".
μ–΄μ œ 제 μΉœκ΅¬κ°€ μ΄λ ‡κ²Œ μΌμŠ΅λ‹ˆλ‹€: "If you spell incorrectly correctly, you have spelled it incorrectly". 이에 μ €λŠ” μ΄λ ‡κ²Œ λ‹΅ν–ˆμŠ΅λ‹ˆλ‹€: "Correct, but 'incorrectly' is incorrectly not '"incorrectly"'".

/// note | μ°Έκ³ 

Expand Down Expand Up @@ -256,15 +256,15 @@ works(foo="bar") # 이건 λ™μž‘ν•©λ‹ˆλ‹€ πŸŽ‰

//// tab | ν…ŒμŠ€νŠΈ

* λ‹Ήμ‹ 
* λ‹Ήμ‹ μ˜
* μ—¬λŸ¬λΆ„
* μ—¬λŸ¬λΆ„μ˜

* 예: (e.g.)
* λ“± (etc.)

* `int`λ‘œμ„œμ˜ `foo`
* `str`λ‘œμ„œμ˜ `bar`
* `list`λ‘œμ„œμ˜ `baz`
* `foo`λ‘œμ„œμ˜ `int`
* `bar`λ‘œμ„œμ˜ `str`
* `baz`λ‘œμ„œμ˜ `list`

* νŠœν† λ¦¬μ–Ό - μ‚¬μš©μž κ°€μ΄λ“œ
* κ³ κΈ‰ μ‚¬μš©μž κ°€μ΄λ“œ
Expand Down
4 changes: 2 additions & 2 deletions docs/ko/docs/advanced/additional-responses.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

예λ₯Ό λ“€μ–΄, μƒνƒœ μ½”λ“œ `404`와 Pydantic λͺ¨λΈ `Message`λ₯Ό μ‚¬μš©ν•˜λŠ” λ‹€λ₯Έ 응닡을 μ„ μ–Έν•˜λ €λ©΄ λ‹€μŒκ³Ό 같이 μž‘μ„±ν•  수 μžˆμŠ΅λ‹ˆλ‹€:

{* ../../docs_src/additional_responses/tutorial001_py39.py hl[18,22] *}
{* ../../docs_src/additional_responses/tutorial001_py310.py hl[18,22] *}

/// note | μ°Έκ³ 

Expand Down Expand Up @@ -203,7 +203,7 @@

λ˜ν•œ `response_model`을 μ‚¬μš©ν•˜λŠ” μƒνƒœ μ½”λ“œ `200` 응닡을 μ„ μ–Έν•˜λ˜, μ»€μŠ€ν…€ `example`을 포함할 μˆ˜λ„ μžˆμŠ΅λ‹ˆλ‹€:

{* ../../docs_src/additional_responses/tutorial003_py39.py hl[20:31] *}
{* ../../docs_src/additional_responses/tutorial003_py310.py hl[20:31] *}

이 λͺ¨λ“  λ‚΄μš©μ€ OpenAPI에 κ²°ν•©λ˜μ–΄ ν¬ν•¨λ˜κ³ , API λ¬Έμ„œμ— ν‘œμ‹œλ©λ‹ˆλ‹€:

Expand Down
8 changes: 4 additions & 4 deletions docs/ko/docs/advanced/additional-status-codes.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
# μΆ”κ°€ μƒνƒœ μ½”λ“œ { #additional-status-codes }

기본적으둜 **FastAPI**λŠ” 응닡을 `JSONResponse`λ₯Ό μ‚¬μš©ν•˜μ—¬ λ°˜ν™˜ν•˜λ©°, *경둜 μž‘μ—…(path operation)*μ—μ„œ λ°˜ν™˜ν•œ λ‚΄μš©μ„ ν•΄λ‹Ή `JSONResponse` μ•ˆμ— λ„£μ–΄ λ°˜ν™˜ν•©λ‹ˆλ‹€.
기본적으둜 **FastAPI**λŠ” 응닡을 `JSONResponse`λ₯Ό μ‚¬μš©ν•˜μ—¬ λ°˜ν™˜ν•˜λ©°, *경둜 처리*μ—μ„œ λ°˜ν™˜ν•œ λ‚΄μš©μ„ ν•΄λ‹Ή `JSONResponse` μ•ˆμ— λ„£μ–΄ λ°˜ν™˜ν•©λ‹ˆλ‹€.

κΈ°λ³Έ μƒνƒœ μ½”λ“œ λ˜λŠ” *경둜 μž‘μ—…*μ—μ„œ μ„€μ •ν•œ μƒνƒœ μ½”λ“œλ₯Ό μ‚¬μš©ν•©λ‹ˆλ‹€.
κΈ°λ³Έ μƒνƒœ μ½”λ“œ λ˜λŠ” *경둜 처리*μ—μ„œ μ„€μ •ν•œ μƒνƒœ μ½”λ“œλ₯Ό μ‚¬μš©ν•©λ‹ˆλ‹€.

## μΆ”κ°€ μƒνƒœ μ½”λ“œ { #additional-status-codes_1 }

κΈ°λ³Έ μƒνƒœ μ½”λ“œμ™€ λ³„λ„λ‘œ μΆ”κ°€ μƒνƒœ μ½”λ“œλ₯Ό λ°˜ν™˜ν•˜λ €λ©΄ `JSONResponse`와 같이 `Response`λ₯Ό 직접 λ°˜ν™˜ν•˜κ³  μΆ”κ°€ μƒνƒœ μ½”λ“œλ₯Ό 직접 μ„€μ •ν•  수 μžˆμŠ΅λ‹ˆλ‹€.

예λ₯Ό λ“€μ–΄ ν•­λͺ©μ„ μ—…λ°μ΄νŠΈν•  수 μžˆλŠ” *경둜 μž‘μ—…*이 있고 성곡 μ‹œ 200 β€œOKβ€μ˜ HTTP μƒνƒœ μ½”λ“œλ₯Ό λ°˜ν™˜ν•œλ‹€κ³  κ°€μ •ν•΄ λ³΄κ² μŠ΅λ‹ˆλ‹€.
예λ₯Ό λ“€μ–΄ ν•­λͺ©μ„ μ—…λ°μ΄νŠΈν•  수 μžˆλŠ” *경둜 처리*κ°€ 있고 성곡 μ‹œ 200 β€œOKβ€μ˜ HTTP μƒνƒœ μ½”λ“œλ₯Ό λ°˜ν™˜ν•œλ‹€κ³  κ°€μ •ν•΄ λ³΄κ² μŠ΅λ‹ˆλ‹€.

ν•˜μ§€λ§Œ μƒˆλ‘œμš΄ ν•­λͺ©μ„ ν—ˆμš©ν•˜κΈ°λ₯Ό 원할 κ²ƒμž…λ‹ˆλ‹€. 그리고 ν•­λͺ©μ΄ 이전에 μ‘΄μž¬ν•˜μ§€ μ•Šμ•˜λ‹€λ©΄ 이λ₯Ό μƒμ„±ν•˜κ³  HTTP μƒνƒœ μ½”λ“œ 201 "Created"λ₯Ό λ°˜ν™˜ν•©λ‹ˆλ‹€.

이λ₯Ό μœ„ν•΄μ„œλŠ” `JSONResponse`λ₯Ό κ°€μ Έμ™€μ„œ μ›ν•˜λŠ” `status_code`λ₯Ό μ„€μ •ν•˜μ—¬ μ½˜ν…μΈ λ₯Ό 직접 λ°˜ν™˜ν•©λ‹ˆλ‹€:

{* ../../docs_src/additional_status_codes/tutorial001_an_py310.py hl[4,25] *}

/// warning | κ²½κ³ 
/// warning

μœ„μ˜ 예제처럼 `Response`λ₯Ό 직접 λ°˜ν™˜ν•˜λ©΄ λ°”λ‘œ λ°˜ν™˜λ©λ‹ˆλ‹€.

Expand Down
8 changes: 4 additions & 4 deletions docs/ko/docs/advanced/advanced-dependencies.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Pythonμ—λŠ” 클래슀의 μΈμŠ€ν„΄μŠ€λ₯Ό "호좜 κ°€λŠ₯"ν•˜κ²Œ λ§Œλ“œλŠ” 방법

이λ₯Ό μœ„ν•΄ `__call__` λ©”μ„œλ“œλ₯Ό μ„ μ–Έν•©λ‹ˆλ‹€:

{* ../../docs_src/dependencies/tutorial011_an_py39.py hl[12] *}
{* ../../docs_src/dependencies/tutorial011_an_py310.py hl[12] *}

이 경우, **FastAPI**λŠ” μΆ”κ°€ λ§€κ°œλ³€μˆ˜μ™€ ν•˜μœ„ μ˜μ‘΄μ„±μ„ ν™•μΈν•˜κΈ° μœ„ν•΄ `__call__`을 μ‚¬μš©ν•˜κ²Œ 되며,
λ‚˜μ€‘μ— *경둜 처리 ν•¨μˆ˜*μ—μ„œ λ§€κ°œλ³€μˆ˜μ— 값을 전달할 λ•Œ 이λ₯Ό ν˜ΈμΆœν•˜κ²Œ λ©λ‹ˆλ‹€.
Expand All @@ -27,15 +27,15 @@ Pythonμ—λŠ” 클래슀의 μΈμŠ€ν„΄μŠ€λ₯Ό "호좜 κ°€λŠ₯"ν•˜κ²Œ λ§Œλ“œλŠ” 방법

이제 `__init__`을 μ‚¬μš©ν•˜μ—¬ μ˜μ‘΄μ„±μ„ "λ§€κ°œλ³€μˆ˜ν™”"ν•  수 μžˆλŠ” μΈμŠ€ν„΄μŠ€μ˜ λ§€κ°œλ³€μˆ˜λ₯Ό μ„ μ–Έν•  수 μžˆμŠ΅λ‹ˆλ‹€:

{* ../../docs_src/dependencies/tutorial011_an_py39.py hl[9] *}
{* ../../docs_src/dependencies/tutorial011_an_py310.py hl[9] *}

이 경우, **FastAPI**λŠ” `__init__`에 μ „ν˜€ κ΄€μ—¬ν•˜μ§€ μ•ŠμœΌλ©°, μš°λ¦¬λŠ” 이 λ©”μ„œλ“œλ₯Ό μ½”λ“œμ—μ„œ 직접 μ‚¬μš©ν•˜κ²Œ λ©λ‹ˆλ‹€.

## μΈμŠ€ν„΄μŠ€ μƒμ„±ν•˜κΈ° { #create-an-instance }

λ‹€μŒκ³Ό 같이 이 클래슀의 μΈμŠ€ν„΄μŠ€λ₯Ό 생성할 수 μžˆμŠ΅λ‹ˆλ‹€:

{* ../../docs_src/dependencies/tutorial011_an_py39.py hl[18] *}
{* ../../docs_src/dependencies/tutorial011_an_py310.py hl[18] *}

μ΄λ ‡κ²Œ ν•˜λ©΄ `checker.fixed_content` 속성에 `"bar"`λΌλŠ” 값을 λ‹΄μ•„ μ˜μ‘΄μ„±μ„ "λ§€κ°œλ³€μˆ˜ν™”"ν•  수 μžˆμŠ΅λ‹ˆλ‹€.

Expand All @@ -51,7 +51,7 @@ checker(q="somequery")

...그리고 μ΄λ•Œ λ°˜ν™˜λ˜λŠ” 값을 *경둜 처리 ν•¨μˆ˜*의 μ˜μ‘΄μ„± κ°’μœΌλ‘œ, `fixed_content_included` λ§€κ°œλ³€μˆ˜μ— μ „λ‹¬ν•©λ‹ˆλ‹€:

{* ../../docs_src/dependencies/tutorial011_an_py39.py hl[22] *}
{* ../../docs_src/dependencies/tutorial011_an_py310.py hl[22] *}

/// tip | 팁

Expand Down
61 changes: 61 additions & 0 deletions docs/ko/docs/advanced/advanced-python-types.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# κ³ κΈ‰ Python νƒ€μž… { #advanced-python-types }

Python νƒ€μž…μ„ λ‹€λ£° λ•Œ μœ μš©ν•  수 μžˆλŠ” λͺ‡ κ°€μ§€ μΆ”κ°€ 아이디어λ₯Ό μ†Œκ°œν•©λ‹ˆλ‹€.

## `Union` λ˜λŠ” `Optional` μ‚¬μš© { #using-union-or-optional }

μ–΄λ–€ 이유둜 μ½”λ“œμ—μ„œ `|`λ₯Ό μ‚¬μš©ν•  수 μ—†λ‹€λ©΄, 예λ₯Ό λ“€μ–΄ νƒ€μž… μ–΄λ…Έν…Œμ΄μ…˜μ΄ μ•„λ‹ˆλΌ `response_model=` 같은 곳이라면, νŒŒμ΄ν”„ 문자(`|`) λŒ€μ‹  `typing`의 `Union`을 μ‚¬μš©ν•  수 μžˆμŠ΅λ‹ˆλ‹€.

예λ₯Ό λ“€μ–΄, μ–΄λ–€ 값이 `str` λ˜λŠ” `None`이 될 수 μžˆλ‹€κ³  μ„ μ–Έν•  수 μžˆμŠ΅λ‹ˆλ‹€:

```python
from typing import Union


def say_hi(name: Union[str, None]):
print(f"Hi {name}!")
```

`typing`μ—λŠ” `None`이 될 수 μžˆμŒμ„ μ„ μ–Έν•˜λŠ” μΆ•μ•½ν˜•μœΌλ‘œ `Optional`도 μžˆμŠ΅λ‹ˆλ‹€.

μ•„μ£Ό 개인적인 κ΄€μ μ—μ„œμ˜ νŒμž…λ‹ˆλ‹€:

- 🚨 `Optional[SomeType]` μ‚¬μš©μ€ ν”Όν•˜μ„Έμš”
- λŒ€μ‹  ✨ **`Union[SomeType, None]`λ₯Ό μ‚¬μš©ν•˜μ„Έμš”** ✨.

λ‘˜μ€ λ™λ“±ν•˜λ©° λ‚΄λΆ€μ μœΌλ‘œλ„ κ°™μŠ΅λ‹ˆλ‹€. ν•˜μ§€λ§Œ 단어 "optional"은 값이 선택 μ‚¬ν•­μ΄λΌλŠ” 인상을 μ£ΌλŠ” 반면, μ‹€μ œ μ˜λ―ΈλŠ” "값이 `None`이 될 수 μžˆλ‹€"λŠ” λœ»μž…λ‹ˆλ‹€. 값이 선택 사항이 μ•„λ‹ˆλΌ μ—¬μ „νžˆ ν•„μˆ˜μΈ κ²½μš°μ—λ„ κ·Έλ ‡μŠ΅λ‹ˆλ‹€.

`Union[SomeType, None]`κ°€ 의미λ₯Ό 더 λͺ…ν™•ν•˜κ²Œ λ“œλŸ¬λ‚Έλ‹€κ³  μƒκ°ν•©λ‹ˆλ‹€.

μ΄λŠ” 단지 단어와 λͺ…μΉ­μ˜ λ¬Έμ œμž…λ‹ˆλ‹€. ν•˜μ§€λ§Œ 이런 단어가 μ—¬λŸ¬λΆ„κ³Ό νŒ€μ›μ΄ μ½”λ“œλ₯Ό μ–΄λ–»κ²Œ μƒκ°ν•˜λŠ”μ§€μ— 영ν–₯을 쀄 수 μžˆμŠ΅λ‹ˆλ‹€.

예λ₯Ό λ“€μ–΄, λ‹€μŒ ν•¨μˆ˜λ₯Ό λ³΄μ„Έμš”:

```python
from typing import Optional


def say_hi(name: Optional[str]):
print(f"Hey {name}!")
```

λ§€κ°œλ³€μˆ˜ `name`은 `Optional[str]`둜 μ •μ˜λ˜μ–΄ μžˆμ§€λ§Œ, 사싀 선택적이지 μ•ŠμŠ΅λ‹ˆλ‹€. 이 λ§€κ°œλ³€μˆ˜ 없이 ν•¨μˆ˜λ₯Ό ν˜ΈμΆœν•  수 μ—†μŠ΅λ‹ˆλ‹€:

```Python
say_hi() # 이런, μ—λŸ¬κ°€ λ°œμƒν•©λ‹ˆλ‹€! 😱
```

`name` λ§€κ°œλ³€μˆ˜λŠ” 기본값이 μ—†κΈ° λ•Œλ¬Έμ— μ—¬μ „νžˆ ν•„μˆ˜μž…λ‹ˆλ‹€(선택적이 μ•„λ‹˜). λŒ€μ‹ , `name`μ—λŠ” `None`을 전달할 수 μžˆμŠ΅λ‹ˆλ‹€:

```Python
say_hi(name=None) # μž‘λ™ν•©λ‹ˆλ‹€. None은 μœ νš¨ν•©λ‹ˆλ‹€ πŸŽ‰
```

쒋은 μ†Œμ‹μ€, λŒ€λΆ€λΆ„μ˜ 경우 νƒ€μž…μ˜ 합집합을 μ •μ˜ν•  λ•Œ κ·Έλƒ₯ `|`λ₯Ό μ‚¬μš©ν•  수 μžˆλ‹€λŠ” μ μž…λ‹ˆλ‹€:

```python
def say_hi(name: str | None):
print(f"Hey {name}!")
```

κ·Έλž˜μ„œ 보톡은 `Optional`κ³Ό `Union` 같은 이름에 λŒ€ν•΄ κ±±μ •ν•˜μ§€ μ•ŠμœΌμ…”λ„ λ©λ‹ˆλ‹€. 😎
8 changes: 4 additions & 4 deletions docs/ko/docs/advanced/async-tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@

`main.py` νŒŒμΌμ€ λ‹€μŒκ³Ό κ°™μŠ΅λ‹ˆλ‹€:

{* ../../docs_src/async_tests/app_a_py39/main.py *}
{* ../../docs_src/async_tests/app_a_py310/main.py *}

`test_main.py` νŒŒμΌμ—λŠ” `main.py`에 λŒ€ν•œ ν…ŒμŠ€νŠΈκ°€ 있으며, 이제 λ‹€μŒκ³Ό 같이 보일 수 μžˆμŠ΅λ‹ˆλ‹€:

{* ../../docs_src/async_tests/app_a_py39/test_main.py *}
{* ../../docs_src/async_tests/app_a_py310/test_main.py *}

## μ‹€ν–‰ν•˜κΈ° { #run-it }

Expand All @@ -56,7 +56,7 @@ $ pytest

`@pytest.mark.anyio` λ§ˆμ»€λŠ” pytestμ—κ²Œ 이 ν…ŒμŠ€νŠΈ ν•¨μˆ˜κ°€ λΉ„λ™κΈ°λ‘œ ν˜ΈμΆœλ˜μ–΄μ•Ό ν•œλ‹€κ³  μ•Œλ €μ€λ‹ˆλ‹€:

{* ../../docs_src/async_tests/app_a_py39/test_main.py hl[7] *}
{* ../../docs_src/async_tests/app_a_py310/test_main.py hl[7] *}

/// tip | 팁

Expand All @@ -66,7 +66,7 @@ $ pytest

κ·Έ λ‹€μŒ μ•±μœΌλ‘œ `AsyncClient`λ₯Ό λ§Œλ“€κ³ , `await`λ₯Ό μ‚¬μš©ν•΄ 비동기 μš”μ²­μ„ 보낼 수 μžˆμŠ΅λ‹ˆλ‹€.

{* ../../docs_src/async_tests/app_a_py39/test_main.py hl[9:12] *}
{* ../../docs_src/async_tests/app_a_py310/test_main.py hl[9:12] *}

μ΄λŠ” λ‹€μŒκ³Ό λ™λ“±ν•©λ‹ˆλ‹€:

Expand Down
12 changes: 6 additions & 6 deletions docs/ko/docs/advanced/behind-a-proxy.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ $ fastapi run --forwarded-allow-ips="*"

예λ₯Ό λ“€μ–΄, *경둜 처리* `/items/`λ₯Ό μ •μ˜ν–ˆλ‹€κ³  ν•΄λ΄…μ‹œλ‹€:

{* ../../docs_src/behind_a_proxy/tutorial001_01_py39.py hl[6] *}
{* ../../docs_src/behind_a_proxy/tutorial001_01_py310.py hl[6] *}

ν΄λΌμ΄μ–ΈνŠΈκ°€ `/items`둜 μ ‘κ·Όν•˜λ©΄, 기본적으둜 `/items/`둜 λ¦¬λ””λ ‰μ…˜λ©λ‹ˆλ‹€.

Expand Down Expand Up @@ -115,7 +115,7 @@ sequenceDiagram

μ½”λ“œλŠ” λͺ¨λ‘ `/app`만 μžˆλ‹€κ³  κ°€μ •ν•˜κ³  μž‘μ„±λ˜μ–΄ μžˆλŠ”λ°λ„ λ§μž…λ‹ˆλ‹€.

{* ../../docs_src/behind_a_proxy/tutorial001_py39.py hl[6] *}
{* ../../docs_src/behind_a_proxy/tutorial001_py310.py hl[6] *}

그리고 ν”„λ‘μ‹œλŠ” μš”μ²­μ„ μ•± μ„œλ²„(μ•„λ§ˆ FastAPI CLIλ₯Ό 톡해 μ‹€ν–‰λ˜λŠ” Uvicorn)둜 μ „λ‹¬ν•˜κΈ° 전에, λ™μ μœΌλ‘œ **경둜 접두사**λ₯Ό **"제거"**ν•©λ‹ˆλ‹€. κ·Έλž˜μ„œ μ• ν”Œλ¦¬μΌ€μ΄μ…˜μ€ μ—¬μ „νžˆ `/app`μ—μ„œ μ„œλΉ„μŠ€λœλ‹€κ³  믿게 되고, μ½”λ“œ 전체λ₯Ό `/api/v1` 접두사λ₯Ό ν¬ν•¨ν•˜λ„λ‘ μˆ˜μ •ν•  ν•„μš”κ°€ μ—†μ–΄μ§‘λ‹ˆλ‹€.

Expand Down Expand Up @@ -193,7 +193,7 @@ ASGI 사양은 이 μ‚¬μš© 사둀λ₯Ό μœ„ν•΄ `root_path`λ₯Ό μ •μ˜ν•©λ‹ˆλ‹€.

μ—¬κΈ°μ„œλŠ” 데λͺ¨ λͺ©μ μ„ μœ„ν•΄ λ©”μ‹œμ§€μ— ν¬ν•¨ν•˜κ³  μžˆμŠ΅λ‹ˆλ‹€.

{* ../../docs_src/behind_a_proxy/tutorial001_py39.py hl[8] *}
{* ../../docs_src/behind_a_proxy/tutorial001_py310.py hl[8] *}

κ·Έ λ‹€μŒ Uvicorn을 λ‹€μŒκ³Ό 같이 μ‹œμž‘ν•˜λ©΄:

Expand All @@ -220,7 +220,7 @@ $ fastapi run main.py --forwarded-allow-ips="*" --root-path /api/v1

λ˜λŠ” `--root-path` 같은 μ»€λ§¨λ“œ 라인 μ˜΅μ…˜(λ˜λŠ” λ™λ“±ν•œ 방법)을 μ œκ³΅ν•  수 μ—†λŠ” 경우, FastAPI 앱을 생성할 λ•Œ `root_path` νŒŒλΌλ―Έν„°λ₯Ό μ„€μ •ν•  수 μžˆμŠ΅λ‹ˆλ‹€:

{* ../../docs_src/behind_a_proxy/tutorial002_py39.py hl[3] *}
{* ../../docs_src/behind_a_proxy/tutorial002_py310.py hl[3] *}

`FastAPI`에 `root_path`λ₯Ό μ „λ‹¬ν•˜λŠ” 것은 Uvicornμ΄λ‚˜ Hypercorn에 μ»€λ§¨λ“œ 라인 μ˜΅μ…˜ `--root-path`λ₯Ό μ „λ‹¬ν•˜λŠ” 것과 λ™μΌν•©λ‹ˆλ‹€.

Expand Down Expand Up @@ -400,7 +400,7 @@ $ fastapi run main.py --forwarded-allow-ips="*" --root-path /api/v1

예:

{* ../../docs_src/behind_a_proxy/tutorial003_py39.py hl[4:7] *}
{* ../../docs_src/behind_a_proxy/tutorial003_py310.py hl[4:7] *}

λ‹€μŒκ³Ό 같은 OpenAPI μŠ€ν‚€λ§ˆλ₯Ό μƒμ„±ν•©λ‹ˆλ‹€:

Expand Down Expand Up @@ -455,7 +455,7 @@ OpenAPI μ‚¬μ–‘μ—μ„œ `servers` 속성은 선택 μ‚¬ν•­μž…λ‹ˆλ‹€.

**FastAPI**κ°€ `root_path`λ₯Ό μ‚¬μš©ν•œ μžλ™ serverλ₯Ό ν¬ν•¨ν•˜μ§€ μ•Šκ²Œ ν•˜λ €λ©΄, `root_path_in_servers=False` νŒŒλΌλ―Έν„°λ₯Ό μ‚¬μš©ν•  수 μžˆμŠ΅λ‹ˆλ‹€:

{* ../../docs_src/behind_a_proxy/tutorial004_py39.py hl[9] *}
{* ../../docs_src/behind_a_proxy/tutorial004_py310.py hl[9] *}

그러면 OpenAPI μŠ€ν‚€λ§ˆμ— ν¬ν•¨λ˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€.

Expand Down
32 changes: 16 additions & 16 deletions docs/ko/docs/advanced/custom-response.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

ν•˜μ§€λ§Œ λ°˜ν™˜ν•˜λŠ” λ‚΄μš©μ΄ **JSON으둜 직렬화 κ°€λŠ₯**ν•˜λ‹€κ³  ν™•μ‹ ν•˜λŠ” 경우, ν•΄λ‹Ή λ‚΄μš©μ„ 응닡 ν΄λž˜μŠ€μ— 직접 전달할 수 있으며, FastAPIκ°€ λ°˜ν™˜ λ‚΄μš©μ„ `jsonable_encoder`λ₯Ό 톡해 μ²˜λ¦¬ν•œ λ’€ 응닡 ν΄λž˜μŠ€μ— μ „λ‹¬ν•˜λŠ” μ˜€λ²„ν—€λ“œλ₯Ό ν”Όν•  수 μžˆμŠ΅λ‹ˆλ‹€.

{* ../../docs_src/custom_response/tutorial001b_py39.py hl[2,7] *}
{* ../../docs_src/custom_response/tutorial001b_py310.py hl[2,7] *}

/// info | 정보

Expand All @@ -55,7 +55,7 @@
* `HTMLResponse`λ₯Ό μž„ν¬νŠΈ ν•©λ‹ˆλ‹€.
* *경둜 처리 λ°μ½”λ ˆμ΄ν„°*의 `response_class` λ§€κ°œλ³€μˆ˜λ‘œ `HTMLResponse`λ₯Ό μ „λ‹¬ν•©λ‹ˆλ‹€.

{* ../../docs_src/custom_response/tutorial002_py39.py hl[2,7] *}
{* ../../docs_src/custom_response/tutorial002_py310.py hl[2,7] *}

/// info | 정보

Expand All @@ -73,7 +73,7 @@

μœ„μ˜ μ˜ˆμ œμ™€ λ™μΌν•˜κ²Œ `HTMLResponse`λ₯Ό λ°˜ν™˜ν•˜λŠ” μ½”λ“œλŠ” λ‹€μŒκ³Ό 같을 수 μžˆμŠ΅λ‹ˆλ‹€:

{* ../../docs_src/custom_response/tutorial003_py39.py hl[2,7,19] *}
{* ../../docs_src/custom_response/tutorial003_py310.py hl[2,7,19] *}

/// warning | κ²½κ³ 

Expand All @@ -97,7 +97,7 @@

예λ₯Ό λ“€μ–΄, λ‹€μŒκ³Ό 같이 μž‘μ„±ν•  수 μžˆμŠ΅λ‹ˆλ‹€:

{* ../../docs_src/custom_response/tutorial004_py39.py hl[7,21,23] *}
{* ../../docs_src/custom_response/tutorial004_py310.py hl[7,21,23] *}

이 μ˜ˆμ œμ—μ„œ, `generate_html_response()` ν•¨μˆ˜λŠ” HTML을 `str`둜 λ°˜ν™˜ν•˜λŠ” λŒ€μ‹  이미 `Response`λ₯Ό μƒμ„±ν•˜κ³  λ°˜ν™˜ν•©λ‹ˆλ‹€.

Expand Down Expand Up @@ -136,7 +136,7 @@

FastAPI (μ‹€μ œλ‘œλŠ” Starlette)κ°€ μžλ™μœΌλ‘œ Content-Length 헀더λ₯Ό ν¬ν•¨μ‹œν‚΅λ‹ˆλ‹€. λ˜ν•œ `media_type`에 κΈ°λ°˜ν•˜μ—¬ Content-Type 헀더λ₯Ό ν¬ν•¨ν•˜λ©°, ν…μŠ€νŠΈ νƒ€μž…μ˜ 경우 문자 집합을 μΆ”κ°€ ν•©λ‹ˆλ‹€.

{* ../../docs_src/response_directly/tutorial002_py39.py hl[1,18] *}
{* ../../docs_src/response_directly/tutorial002_py310.py hl[1,18] *}

### `HTMLResponse` { #htmlresponse }

Expand All @@ -146,7 +146,7 @@ FastAPI (μ‹€μ œλ‘œλŠ” Starlette)κ°€ μžλ™μœΌλ‘œ Content-Length 헀더λ₯Ό 포함

ν…μŠ€νŠΈ λ˜λŠ” λ°”μ΄νŠΈλ₯Ό λ°›μ•„ 일반 ν…μŠ€νŠΈ 응닡을 λ°˜ν™˜ν•©λ‹ˆλ‹€.

{* ../../docs_src/custom_response/tutorial005_py39.py hl[2,7,9] *}
{* ../../docs_src/custom_response/tutorial005_py310.py hl[2,7,9] *}

### `JSONResponse` { #jsonresponse }

Expand Down Expand Up @@ -180,7 +180,7 @@ FastAPI (μ‹€μ œλ‘œλŠ” Starlette)κ°€ μžλ™μœΌλ‘œ Content-Length 헀더λ₯Ό 포함

///

{* ../../docs_src/custom_response/tutorial001_py39.py hl[2,7] *}
{* ../../docs_src/custom_response/tutorial001_py310.py hl[2,7] *}

/// tip | 팁

Expand All @@ -194,14 +194,14 @@ HTTP λ¦¬λ””λ ‰μ…˜ 응닡을 λ°˜ν™˜ν•©λ‹ˆλ‹€. 기본적으둜 μƒνƒœ μ½”λ“œλŠ” 30

`RedirectResponse`λ₯Ό 직접 λ°˜ν™˜ν•  수 μžˆμŠ΅λ‹ˆλ‹€.

{* ../../docs_src/custom_response/tutorial006_py39.py hl[2,9] *}
{* ../../docs_src/custom_response/tutorial006_py310.py hl[2,9] *}

---

λ˜λŠ” `response_class` λ§€κ°œλ³€μˆ˜μ—μ„œ μ‚¬μš©ν•  μˆ˜λ„ μžˆμŠ΅λ‹ˆλ‹€:


{* ../../docs_src/custom_response/tutorial006b_py39.py hl[2,7,9] *}
{* ../../docs_src/custom_response/tutorial006b_py310.py hl[2,7,9] *}

이 경우, *경둜 처리* ν•¨μˆ˜μ—μ„œ URL을 직접 λ°˜ν™˜ν•  수 μžˆμŠ΅λ‹ˆλ‹€.

Expand All @@ -211,13 +211,13 @@ HTTP λ¦¬λ””λ ‰μ…˜ 응닡을 λ°˜ν™˜ν•©λ‹ˆλ‹€. 기본적으둜 μƒνƒœ μ½”λ“œλŠ” 30

`status_code` λ§€κ°œλ³€μˆ˜λ₯Ό `response_class` λ§€κ°œλ³€μˆ˜μ™€ ν•¨κ»˜ μ‚¬μš©ν•  μˆ˜λ„ μžˆμŠ΅λ‹ˆλ‹€:

{* ../../docs_src/custom_response/tutorial006c_py39.py hl[2,7,9] *}
{* ../../docs_src/custom_response/tutorial006c_py310.py hl[2,7,9] *}

### `StreamingResponse` { #streamingresponse }

비동기 μ œλ„ˆλ ˆμ΄ν„° λ˜λŠ” 일반 μ œλ„ˆλ ˆμ΄ν„°/μ΄ν„°λ ˆμ΄ν„°λ₯Ό λ°›μ•„ 응닡 본문을 슀트리밍 ν•©λ‹ˆλ‹€.

{* ../../docs_src/custom_response/tutorial007_py39.py hl[2,14] *}
{* ../../docs_src/custom_response/tutorial007_py310.py hl[2,14] *}

#### 파일과 같은 객체λ₯Ό μ‚¬μš©ν•œ `StreamingResponse` { #using-streamingresponse-with-file-like-objects }

Expand All @@ -227,7 +227,7 @@ HTTP λ¦¬λ””λ ‰μ…˜ 응닡을 λ°˜ν™˜ν•©λ‹ˆλ‹€. 기본적으둜 μƒνƒœ μ½”λ“œλŠ” 30

이 방식은 ν΄λΌμš°λ“œ μŠ€ν† λ¦¬μ§€, λΉ„λ””μ˜€ 처리 λ“±μ˜ λ‹€μ–‘ν•œ λΌμ΄λΈŒλŸ¬λ¦¬μ™€ ν•¨κ»˜ μ‚¬μš©ν•  수 μžˆμŠ΅λ‹ˆλ‹€.

{* ../../docs_src/custom_response/tutorial008_py39.py hl[2,10:12,14] *}
{* ../../docs_src/custom_response/tutorial008_py310.py hl[2,10:12,14] *}

1. 이것이 μ œλ„ˆλ ˆμ΄ν„° ν•¨μˆ˜μž…λ‹ˆλ‹€. `yield` 문을 ν¬ν•¨ν•˜κ³  μžˆμœΌλ―€λ‘œ "μ œλ„ˆλ ˆμ΄ν„° ν•¨μˆ˜"μž…λ‹ˆλ‹€.
2. `with` 블둝을 μ‚¬μš©ν•¨μœΌλ‘œμ¨, μ œλ„ˆλ ˆμ΄ν„° ν•¨μˆ˜κ°€ μ™„λ£Œλœ ν›„ 파일과 같은 객체가 λ‹«νžˆλ„λ‘ ν•©λ‹ˆλ‹€. 즉, 응닡 전솑이 λλ‚œ ν›„ λ‹«νž™λ‹ˆλ‹€.
Expand Down Expand Up @@ -256,11 +256,11 @@ HTTP λ¦¬λ””λ ‰μ…˜ 응닡을 λ°˜ν™˜ν•©λ‹ˆλ‹€. 기본적으둜 μƒνƒœ μ½”λ“œλŠ” 30

파일 μ‘λ‹΅μ—λŠ” μ μ ˆν•œ `Content-Length`, `Last-Modified`, 및 `ETag` 헀더가 ν¬ν•¨λ©λ‹ˆλ‹€.

{* ../../docs_src/custom_response/tutorial009_py39.py hl[2,10] *}
{* ../../docs_src/custom_response/tutorial009_py310.py hl[2,10] *}

λ˜ν•œ `response_class` λ§€κ°œλ³€μˆ˜λ₯Ό μ‚¬μš©ν•  μˆ˜λ„ μžˆμŠ΅λ‹ˆλ‹€:

{* ../../docs_src/custom_response/tutorial009b_py39.py hl[2,8,10] *}
{* ../../docs_src/custom_response/tutorial009b_py310.py hl[2,8,10] *}

이 경우, 경둜 처리 ν•¨μˆ˜μ—μ„œ 파일 경둜λ₯Ό 직접 λ°˜ν™˜ν•  수 μžˆμŠ΅λ‹ˆλ‹€.

Expand All @@ -274,7 +274,7 @@ HTTP λ¦¬λ””λ ‰μ…˜ 응닡을 λ°˜ν™˜ν•©λ‹ˆλ‹€. 기본적으둜 μƒνƒœ μ½”λ“œλŠ” 30

`CustomORJSONResponse`λ₯Ό 생성할 수 μžˆμŠ΅λ‹ˆλ‹€. μ—¬κΈ°μ„œ 핡심은 `Response.render(content)` λ©”μ„œλ“œλ₯Ό μƒμ„±ν•˜μ—¬ λ‚΄μš©μ„ `bytes`둜 λ°˜ν™˜ν•˜λŠ” κ²ƒμž…λ‹ˆλ‹€:

{* ../../docs_src/custom_response/tutorial009c_py39.py hl[9:14,17] *}
{* ../../docs_src/custom_response/tutorial009c_py310.py hl[9:14,17] *}

이제 λ‹€μŒ λŒ€μ‹ :

Expand All @@ -300,7 +300,7 @@ HTTP λ¦¬λ””λ ‰μ…˜ 응닡을 λ°˜ν™˜ν•©λ‹ˆλ‹€. 기본적으둜 μƒνƒœ μ½”λ“œλŠ” 30

μ•„λž˜ μ˜ˆμ œμ—μ„œ **FastAPI**λŠ” λͺ¨λ“  *경둜 처리*μ—μ„œ 기본적으둜 `JSONResponse` λŒ€μ‹  `ORJSONResponse`λ₯Ό μ‚¬μš©ν•©λ‹ˆλ‹€.

{* ../../docs_src/custom_response/tutorial010_py39.py hl[2,4] *}
{* ../../docs_src/custom_response/tutorial010_py310.py hl[2,4] *}

/// tip | 팁

Expand Down
Loading