Browse Source

๐ŸŒ Add Korean translation for `docs/ko/docs/advanced/response-directly.md` (#12674)

pull/12733/head
namjimin_43 5 months ago
committed by GitHub
parent
commit
e93b27452b
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 67
      docs/ko/docs/advanced/response-directly.md

67
docs/ko/docs/advanced/response-directly.md

@ -0,0 +1,67 @@
# ์‘๋‹ต์„ ์ง์ ‘ ๋ฐ˜ํ™˜ํ•˜๊ธฐ
**FastAPI**์—์„œ *๊ฒฝ๋กœ ์ž‘์—…(path operation)*์„ ์ƒ์„ฑํ•  ๋•Œ, ์ผ๋ฐ˜์ ์œผ๋กœ `dict`, `list`, Pydantic ๋ชจ๋ธ, ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ๋ชจ๋ธ ๋“ฑ์˜ ๋ฐ์ดํ„ฐ๋ฅผ ๋ฐ˜ํ™˜ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
๊ธฐ๋ณธ์ ์œผ๋กœ **FastAPI**๋Š” [JSON ํ˜ธํ™˜ ๊ฐ€๋Šฅ ์ธ์ฝ”๋”](../tutorial/encoder.md){.internal-link target=_blank}์— ์„ค๋ช…๋œ `jsonable_encoder`๋ฅผ ์‚ฌ์šฉํ•ด ํ•ด๋‹น ๋ฐ˜ํ™˜ ๊ฐ’์„ ์ž๋™์œผ๋กœ `JSON`์œผ๋กœ ๋ณ€ํ™˜ํ•ฉ๋‹ˆ๋‹ค.
๊ทธ๋Ÿฐ ๋‹ค์Œ, JSON ํ˜ธํ™˜ ๋ฐ์ดํ„ฐ(์˜ˆ: `dict`)๋ฅผ `JSONResponse`์— ๋„ฃ์–ด ์‚ฌ์šฉ์ž์˜ ์‘๋‹ต์„ ์ „์†กํ•˜๋Š” ๋ฐฉ์‹์œผ๋กœ ์ฒ˜๋ฆฌ๋ฉ๋‹ˆ๋‹ค.
๊ทธ๋Ÿฌ๋‚˜ *๊ฒฝ๋กœ ์ž‘์—…*์—์„œ `JSONResponse`๋ฅผ ์ง์ ‘ ๋ฐ˜ํ™˜ํ•  ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค.
์˜ˆ๋ฅผ ๋“ค์–ด, ์‚ฌ์šฉ์ž ์ •์˜ ํ—ค๋”๋‚˜ ์ฟ ํ‚ค๋ฅผ ๋ฐ˜ํ™˜ํ•ด์•ผ ํ•˜๋Š” ๊ฒฝ์šฐ์— ์œ ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
## `Response` ๋ฐ˜ํ™˜ํ•˜๊ธฐ
์‚ฌ์‹ค, `Response` ๋˜๋Š” ๊ทธ ํ•˜์œ„ ํด๋ž˜์Šค๋ฅผ ๋ฐ˜ํ™˜ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
/// tip
`JSONResponse` ์ž์ฒด๋„ `Response`์˜ ํ•˜์œ„ ํด๋ž˜์Šค์ž…๋‹ˆ๋‹ค.
///
๊ทธ๋ฆฌ๊ณ  `Response`๋ฅผ ๋ฐ˜ํ™˜ํ•˜๋ฉด **FastAPI**๊ฐ€ ์ด๋ฅผ ๊ทธ๋Œ€๋กœ ์ „๋‹ฌํ•ฉ๋‹ˆ๋‹ค.
Pydantic ๋ชจ๋ธ๋กœ ๋ฐ์ดํ„ฐ ๋ณ€ํ™˜์„ ์ˆ˜ํ–‰ํ•˜์ง€ ์•Š์œผ๋ฉฐ, ๋‚ด์šฉ์„ ๋‹ค๋ฅธ ํ˜•์‹์œผ๋กœ ๋ณ€ํ™˜ํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.
์ด๋กœ ์ธํ•ด ๋งŽ์€ ์œ ์—ฐ์„ฑ์„ ์–ป์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์–ด๋–ค ๋ฐ์ดํ„ฐ ์œ ํ˜•์ด๋“  ๋ฐ˜ํ™˜ํ•  ์ˆ˜ ์žˆ๊ณ , ๋ฐ์ดํ„ฐ ์„ ์–ธ์ด๋‚˜ ์œ ํšจ์„ฑ ๊ฒ€์‚ฌ๋ฅผ ์žฌ์ •์˜ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
## `Response`์—์„œ `jsonable_encoder` ์‚ฌ์šฉํ•˜๊ธฐ
**FastAPI**๋Š” ๋ฐ˜ํ™˜ํ•˜๋Š” `Response`์— ์•„๋ฌด๋Ÿฐ ๋ณ€ํ™˜์„ ํ•˜์ง€ ์•Š์œผ๋ฏ€๋กœ, ๊ทธ ๋‚ด์šฉ์ด ์ค€๋น„๋˜์–ด ์žˆ์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.
์˜ˆ๋ฅผ ๋“ค์–ด, Pydantic ๋ชจ๋ธ์„ `dict`๋กœ ๋ณ€ํ™˜ํ•ด `JSONResponse`์— ๋„ฃ์ง€ ์•Š์œผ๋ฉด JSON ํ˜ธํ™˜ ์œ ํ˜•์œผ๋กœ ๋ณ€ํ™˜๋œ ๋ฐ์ดํ„ฐ ์œ ํ˜•(์˜ˆ: `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`๋กœ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค. ๊ทธ๋Ÿฌ๋‚˜ ๋Œ€๋ถ€๋ถ„์˜ ๊ฐ€๋Šฅํ•œ ์‘๋‹ต์€ Starlette์—์„œ ์ง์ ‘ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค.
///
## ์‚ฌ์šฉ์ž ์ •์˜ `Response` ๋ฐ˜ํ™˜ํ•˜๊ธฐ
์œ„ ์˜ˆ์ œ๋Š” ํ•„์š”ํ•œ ๋ชจ๋“  ๋ถ€๋ถ„์„ ๋ณด์—ฌ์ฃผ์ง€๋งŒ, ์•„์ง ์œ ์šฉํ•˜์ง€๋Š” ์•Š์Šต๋‹ˆ๋‹ค. ์‚ฌ์‹ค ๋ฐ์ดํ„ฐ๋ฅผ ์ง์ ‘ ๋ฐ˜ํ™˜ํ•˜๋ฉด **FastAPI**๊ฐ€ ์ด๋ฅผ `JSONResponse`์— ๋„ฃ๊ณ  `dict`๋กœ ๋ณ€ํ™˜ํ•˜๋Š” ๋“ฑ ๋ชจ๋“  ์ž‘์—…์„ ์ž๋™์œผ๋กœ ์ฒ˜๋ฆฌํ•ฉ๋‹ˆ๋‹ค.
์ด์ œ, ์‚ฌ์šฉ์ž ์ •์˜ ์‘๋‹ต์„ ๋ฐ˜ํ™˜ํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ์•Œ์•„๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.
์˜ˆ๋ฅผ ๋“ค์–ด <a href="https://en.wikipedia.org/wiki/XML" class="external-link" target="_blank">XML</a> ์‘๋‹ต์„ ๋ฐ˜ํ™˜ํ•˜๊ณ  ์‹ถ๋‹ค๊ณ  ๊ฐ€์ •ํ•ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.
XML ๋‚ด์šฉ์„ ๋ฌธ์ž์—ด์— ๋„ฃ๊ณ , ์ด๋ฅผ `Response`์— ๋„ฃ์–ด ๋ฐ˜ํ™˜ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค:
```Python hl_lines="1 18"
{!../../docs_src/response_directly/tutorial002.py!}
```
## ์ฐธ๊ณ  ์‚ฌํ•ญ
`Response`๋ฅผ ์ง์ ‘ ๋ฐ˜ํ™˜ํ•  ๋•Œ, ๊ทธ ๋ฐ์ดํ„ฐ๋Š” ์ž๋™์œผ๋กœ ์œ ํšจ์„ฑ ๊ฒ€์‚ฌ๋˜๊ฑฐ๋‚˜, ๋ณ€ํ™˜(์ง๋ ฌํ™”)๋˜๊ฑฐ๋‚˜, ๋ฌธ์„œํ™”๋˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.
๊ทธ๋Ÿฌ๋‚˜ [OpenAPI์—์„œ ์ถ”๊ฐ€ ์‘๋‹ต](additional-responses.md){.internal-link target=_blank}์—์„œ ์„ค๋ช…๋œ ๋Œ€๋กœ ๋ฌธ์„œํ™”ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
์ดํ›„ ๋‹จ๋ฝ์—์„œ ์ž๋™ ๋ฐ์ดํ„ฐ ๋ณ€ํ™˜, ๋ฌธ์„œํ™” ๋“ฑ์„ ์‚ฌ์šฉํ•˜๋ฉด์„œ ์‚ฌ์šฉ์ž ์ •์˜ `Response`๋ฅผ ์„ ์–ธํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
Loadingโ€ฆ
Cancel
Save