Browse Source

๐ŸŒ Add Korean translation for Tutorial - First Steps (#2323)

Co-authored-by: Dahun Jeong <[email protected]>
Co-authored-by: Sebastiรกn Ramรญrez <[email protected]>
pull/3031/head
Spike 4 years ago
committed by GitHub
parent
commit
0250cfa398
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 333
      docs/ko/docs/tutorial/first-steps.md
  2. 1
      docs/ko/mkdocs.yml

333
docs/ko/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)
```
ํ•ด๋‹น ์ค„์€ ๋กœ์ปฌ์—์„œ ์•ฑ์ด ์„œ๋น„์Šค๋˜๋Š” URL์„ ๋ณด์—ฌ์ค๋‹ˆ๋‹ค.
### ํ™•์ธํ•˜๊ธฐ
๋ธŒ๋ผ์šฐ์ €๋กœ <a href="http://127.0.0.1:8000" class="external-link" target="_blank">http://127.0.0.1:8000</a>๋ฅผ ์—ฌ์„ธ์š”.
์•„๋ž˜์™€ ๊ฐ™์€ JSON ์‘๋‹ต์„ ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค:
```JSON
{"message": "Hello World"}
```
### ๋Œ€ํ™”ํ˜• API ๋ฌธ์„œ
์ด์ œ <a href="http://127.0.0.1:8000/docs" class="external-link" target="_blank">http://127.0.0.1:8000/docs</a>๋กœ ๊ฐ€๋ด…๋‹ˆ๋‹ค.
์ž๋™ ๋Œ€ํ™”ํ˜• API ๋ฌธ์„œ๋ฅผ ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค (<a href="https://github.com/swagger-api/swagger-ui" class="external-link" target="_blank">Swagger UI</a> ์ œ๊ณต):
![Swagger UI](https://fastapi.tiangolo.com/img/index/index-01-swagger-ui-simple.png)
### ๋Œ€์•ˆ API ๋ฌธ์„œ
๊ทธ๋ฆฌ๊ณ  ์ด์ œ, <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">ReDoc</a> ์ œ๊ณต):
![ReDoc](https://fastapi.tiangolo.com/img/index/index-02-redoc-simple.png)
### OpenAPI
**FastAPI**๋Š” API๋ฅผ ์ •์˜ํ•˜๊ธฐ ์œ„ํ•œ **OpenAPI** ํ‘œ์ค€์„ ์‚ฌ์šฉํ•˜์—ฌ ์—ฌ๋Ÿฌ๋ถ„์˜ ๋ชจ๋“  API๋ฅผ ์ด์šฉํ•ด "์Šคํ‚ค๋งˆ"๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.
#### "์Šคํ‚ค๋งˆ"
"์Šคํ‚ค๋งˆ"๋Š” ๋ฌด์–ธ๊ฐ€์˜ ์ •์˜ ๋˜๋Š” ์„ค๋ช…์ž…๋‹ˆ๋‹ค. ์ด๋ฅผ ๊ตฌํ˜„ํ•˜๋Š” ์ฝ”๋“œ๊ฐ€ ์•„๋‹ˆ๋ผ ์ถ”์ƒ์ ์ธ ์„ค๋ช…์ผ ๋ฟ์ž…๋‹ˆ๋‹ค.
#### API "์Šคํ‚ค๋งˆ"
์ด ๊ฒฝ์šฐ, <a href="https://github.com/OAI/OpenAPI-Specification" class="external-link" target="_blank">OpenAPI</a>๋Š” API์˜ ์Šคํ‚ค๋งˆ๋ฅผ ์–ด๋–ป๊ฒŒ ์ •์˜ํ•˜๋Š”์ง€ ์ง€์‹œํ•˜๋Š” ๊ทœ๊ฒฉ์ž…๋‹ˆ๋‹ค.
์ด ์Šคํ‚ค๋งˆ ์ •์˜๋Š” API ๊ฒฝ๋กœ, ๊ฐ€๋Šฅํ•œ ๋งค๊ฐœ๋ณ€์ˆ˜ ๋“ฑ์„ ํฌํ•จํ•ฉ๋‹ˆ๋‹ค.
#### ๋ฐ์ดํ„ฐ "์Šคํ‚ค๋งˆ"
"์Šคํ‚ค๋งˆ"๋ผ๋Š” ์šฉ์–ด๋Š” JSON์ฒ˜๋Ÿผ ์–ด๋–ค ๋ฐ์ดํ„ฐ์˜ ํ˜•ํƒœ๋ฅผ ๋‚˜ํƒ€๋‚ผ ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค.
์ด๋Ÿฌํ•œ ๊ฒฝ์šฐ JSON ์†์„ฑ, ๊ฐ€์ง€๊ณ  ์žˆ๋Š” ๋ฐ์ดํ„ฐ ํƒ€์ž… ๋“ฑ์„ ๋œปํ•ฉ๋‹ˆ๋‹ค.
#### OpenAPI์™€ JSON ์Šคํ‚ค๋งˆ
OpenAPI๋Š” API์— ๋Œ€ํ•œ API ์Šคํ‚ค๋งˆ๋ฅผ ์ •์˜ํ•ฉ๋‹ˆ๋‹ค. ๋˜ํ•œ ์ด ์Šคํ‚ค๋งˆ์—๋Š” JSON ๋ฐ์ดํ„ฐ ์Šคํ‚ค๋งˆ์˜ ํ‘œ์ค€์ธ **JSON ์Šคํ‚ค๋งˆ**๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ API์—์„œ ๋ณด๋‚ด๊ณ  ๋ฐ›์€ ๋ฐ์ดํ„ฐ์˜ ์ •์˜(๋˜๋Š” "์Šคํ‚ค๋งˆ")๋ฅผ ํฌํ•จํ•ฉ๋‹ˆ๋‹ค.
#### `openapi.json` ํ™•์ธ
๊ฐ€๊ณต๋˜์ง€ ์•Š์€ OpenAPI ์Šคํ‚ค๋งˆ๊ฐ€ ์–ด๋–ป๊ฒŒ ์ƒ๊ฒผ๋Š”์ง€ ๊ถ๊ธˆํ•˜๋‹ค๋ฉด, FastAPI๋Š” ์ž๋™์œผ๋กœ API์˜ ์„ค๋ช…๊ณผ ํ•จ๊ป˜ JSON (์Šคํ‚ค๋งˆ)๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.
์—ฌ๊ธฐ์—์„œ ์ง์ ‘ ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค: <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์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค:
```JSON
{
"openapi": "3.0.2",
"info": {
"title": "FastAPI",
"version": "0.1.0"
},
"paths": {
"/items/": {
"get": {
"responses": {
"200": {
"description": "Successful Response",
"content": {
"application/json": {
...
```
#### OpenAPI์˜ ์šฉ๋„
OpenAPI ์Šคํ‚ค๋งˆ๋Š” ํฌํ•จ๋œ ๋‘ ๊ฐœ์˜ ๋Œ€ํ™”ํ˜• ๋ฌธ์„œ ์‹œ์Šคํ…œ์„ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค.
๊ทธ๋ฆฌ๊ณ  OpenAPI์˜ ๋ชจ๋“  ๊ฒƒ์„ ๊ธฐ๋ฐ˜์œผ๋กœ ํ•˜๋Š” ์ˆ˜์‹ญ ๊ฐ€์ง€ ๋Œ€์•ˆ์ด ์žˆ์Šต๋‹ˆ๋‹ค. **FastAPI**๋กœ ๋นŒ๋“œํ•œ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์— ์ด๋Ÿฌํ•œ ๋Œ€์•ˆ์„ ์‰ฝ๊ฒŒ ์ถ”๊ฐ€ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
API์™€ ํ†ต์‹ ํ•˜๋Š” ํด๋ผ์ด์–ธํŠธ๋ฅผ ์œ„ํ•ด ์ฝ”๋“œ๋ฅผ ์ž๋™์œผ๋กœ ์ƒ์„ฑํ•˜๋Š” ๋ฐ๋„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์˜ˆ๋กœ ํ”„๋ก ํŠธ์—”๋“œ, ๋ชจ๋ฐ”์ผ, IoT ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์ด ์žˆ์Šต๋‹ˆ๋‹ค.
## ๋‹จ๊ณ„๋ณ„ ์š”์•ฝ
### 1 ๋‹จ๊ณ„: `FastAPI` ์ž„ํฌํŠธ
```Python hl_lines="1"
{!../../../docs_src/first_steps/tutorial001.py!}
```
`FastAPI`๋Š” API์— ๋Œ€ํ•œ ๋ชจ๋“  ๊ธฐ๋Šฅ์„ ์ œ๊ณตํ•˜๋Š” ํŒŒ์ด์ฌ ํด๋ž˜์Šค์ž…๋‹ˆ๋‹ค.
!!! note "๊ธฐ์ˆ  ์„ธ๋ถ€์‚ฌํ•ญ"
`FastAPI`๋Š” `Starlette`๋ฅผ ์ง์ ‘ ์ƒ์†ํ•˜๋Š” ํด๋ž˜์Šค์ž…๋‹ˆ๋‹ค.
`FastAPI`๋กœ <a href="https://www.starlette.io/" class="external-link" target="_blank">Starlette</a>์˜ ๋ชจ๋“  ๊ธฐ๋Šฅ์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
### 2 ๋‹จ๊ณ„: `FastAPI` "์ธ์Šคํ„ด์Šค" ์ƒ์„ฑ
```Python hl_lines="3"
{!../../../docs_src/first_steps/tutorial001.py!}
```
์—ฌ๊ธฐ ์žˆ๋Š” `app` ๋ณ€์ˆ˜๋Š” `FastAPI` ํด๋ž˜์Šค์˜ "์ธ์Šคํ„ด์Šค"๊ฐ€ ๋ฉ๋‹ˆ๋‹ค.
์ด๊ฒƒ์€ ๋ชจ๋“  API๋ฅผ ์ƒ์„ฑํ•˜๊ธฐ ์œ„ํ•œ ์ƒํ˜ธ์ž‘์šฉ์˜ ์ฃผ์š” ์ง€์ ์ด ๋  ๊ฒƒ์ž…๋‹ˆ๋‹ค.
์ด `app`์€ ๋‹ค์Œ ๋ช…๋ น์—์„œ `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!}
```
์ด๋ฅผ `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 ๋‹จ๊ณ„: *๊ฒฝ๋กœ ๋™์ž‘* ์ƒ์„ฑ
#### ๊ฒฝ๋กœ
์—ฌ๊ธฐ์„œ "๊ฒฝ๋กœ"๋Š” ์ฒซ ๋ฒˆ์งธ `/`์—์„œ ์‹œ์ž‘ํ•˜๋Š” URL์˜ ๋งˆ์ง€๋ง‰ ๋ถ€๋ถ„์„ ๋‚˜ํƒ€๋ƒ…๋‹ˆ๋‹ค.
๊ทธ๋Ÿฌ๋ฏ€๋กœ ์•„๋ž˜์™€ ๊ฐ™์€ URL์—์„œ:
```
https://example.com/items/foo
```
...๊ฒฝ๋กœ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค:
```
/items/foo
```
!!! info "์ •๋ณด"
"๊ฒฝ๋กœ"๋Š” ์ผ๋ฐ˜์ ์œผ๋กœ "์•ค๋“œํฌ์ธํŠธ" ๋˜๋Š” "๋ผ์šฐํŠธ"๋ผ๊ณ ๋„ ๋ถˆ๋ฆฝ๋‹ˆ๋‹ค.
API๋ฅผ ๋นŒ๋“œํ•˜๋Š” ๋™์•ˆ "๊ฒฝ๋กœ"๋Š” "๊ด€์‹ฌ์‚ฌ"์™€ "๋ฆฌ์†Œ์Šค"๋ฅผ ๋ถ„๋ฆฌํ•˜๋Š” ์ฃผ์š” ๋ฐฉ๋ฒ•์ž…๋‹ˆ๋‹ค.
#### ๋™์ž‘
์—ฌ๊ธฐ์„œ "๋™์ž‘(Operation)"์€ HTTP "๋ฉ”์†Œ๋“œ" ์ค‘ ํ•˜๋‚˜๋ฅผ ๋‚˜ํƒ€๋ƒ…๋‹ˆ๋‹ค.
๋‹ค์Œ ์ค‘ ํ•˜๋‚˜์ด๋ฉฐ:
* `POST`
* `GET`
* `PUT`
* `DELETE`
...์ด๊ตญ์ ์ธ ๊ฒƒ๋“ค๋„ ์žˆ์Šต๋‹ˆ๋‹ค:
* `OPTIONS`
* `HEAD`
* `PATCH`
* `TRACE`
HTTP ํ”„๋กœํ† ์ฝœ์—์„œ๋Š” ์ด๋Ÿฌํ•œ "๋ฉ”์†Œ๋“œ"๋ฅผ ํ•˜๋‚˜(๋˜๋Š” ์ด์ƒ) ์‚ฌ์šฉํ•˜์—ฌ ๊ฐ ๊ฒฝ๋กœ์™€ ํ†ต์‹ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
---
API๋ฅผ ๋นŒ๋“œํ•˜๋Š” ๋™์•ˆ ์ผ๋ฐ˜์ ์œผ๋กœ ํŠน์ • ํ–‰๋™์„ ์ˆ˜ํ–‰ํ•˜๊ธฐ ์œ„ํ•ด ํŠน์ • HTTP ๋ฉ”์†Œ๋“œ๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.
์ผ๋ฐ˜์ ์œผ๋กœ ๋‹ค์Œ์„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค:
* `POST`: ๋ฐ์ดํ„ฐ๋ฅผ ์ƒ์„ฑํ•˜๊ธฐ ์œ„ํ•ด.
* `GET`: ๋ฐ์ดํ„ฐ๋ฅผ ์ฝ๊ธฐ ์œ„ํ•ด.
* `PUT`: ๋ฐ์ดํ„ฐ๋ฅผ ์—…๋ฐ์ดํŠธํ•˜๊ธฐ ์œ„ํ•ด.
* `DELETE`: ๋ฐ์ดํ„ฐ๋ฅผ ์‚ญ์ œํ•˜๊ธฐ ์œ„ํ•ด.
๊ทธ๋ž˜์„œ OpenAPI์—์„œ๋Š” ๊ฐ HTTP ๋ฉ”์†Œ๋“œ๋“ค์„ "๋™์ž‘"์ด๋ผ ๋ถ€๋ฆ…๋‹ˆ๋‹ค.
์ด์ œ๋ถ€ํ„ฐ ์šฐ๋ฆฌ๋Š” ๋ฉ”์†Œ๋“œ๋ฅผ "**๋™์ž‘**"์ด๋ผ๊ณ ๋„ ๋ถ€๋ฅผ๊ฒ๋‹ˆ๋‹ค.
#### *๊ฒฝ๋กœ ๋™์ž‘ ๋ฐ์ฝ”๋ ˆ์ดํ„ฐ* ์ •์˜
```Python hl_lines="6"
{!../../../docs_src/first_steps/tutorial001.py!}
```
`@app.get("/")`์€ **FastAPI**์—๊ฒŒ ๋ฐ”๋กœ ์•„๋ž˜์— ์žˆ๋Š” ํ•จ์ˆ˜๊ฐ€ ๋‹ค์Œ์œผ๋กœ ์ด๋™ํ•˜๋Š” ์š”์ฒญ์„ ์ฒ˜๋ฆฌํ•œ๋‹ค๋Š” ๊ฒƒ์„ ์•Œ๋ ค์ค๋‹ˆ๋‹ค.
* ๊ฒฝ๋กœ `/`
* <abbr title="HTTP GET ๋ฉ”์†Œ๋“œ"><code>get</code> ๋™์ž‘</abbr> ์‚ฌ์šฉ
!!! info "`@decorator` ์ •๋ณด"
์ด `@something` ๋ฌธ๋ฒ•์€ ํŒŒ์ด์ฌ์—์„œ "๋ฐ์ฝ”๋ ˆ์ดํ„ฐ"๋ผ ๋ถ€๋ฆ…๋‹ˆ๋‹ค.
ํ•จ์ˆ˜ ๋งจ ์œ„์— ๋†“์Šต๋‹ˆ๋‹ค. ๋งˆ์น˜ ์˜ˆ์œ ์žฅ์‹์šฉ(Decorative) ๋ชจ์ž์ฒ˜๋Ÿผ(๊ฐœ์ธ์ ์œผ๋กœ ์ด ์šฉ์–ด๊ฐ€ ์—ฌ๊ธฐ์„œ ์œ ๋ž˜ํ•œ๊ฑฐ ๊ฐ™์Šต๋‹ˆ๋‹ค).
"๋ฐ์ฝ”๋ ˆ์ดํ„ฐ" ์•„๋ž˜ ์žˆ๋Š” ํ•จ์ˆ˜๋ฅผ ๋ฐ›๊ณ  ๊ทธ๊ฑธ ์ด์šฉํ•ด ๋ฌด์–ธ๊ฐ€ ํ•ฉ๋‹ˆ๋‹ค.
์šฐ๋ฆฌ์˜ ๊ฒฝ์šฐ, ์ด ๋ฐ์ฝ”๋ ˆ์ดํ„ฐ๋Š” **FastAPI**์—๊ฒŒ ์•„๋ž˜ ํ•จ์ˆ˜๊ฐ€ **๊ฒฝ๋กœ** `/`์— ํ•ด๋‹นํ•˜๋Š” `get` **๋™์ž‘**ํ•˜๋ผ๊ณ  ์•Œ๋ ค์ค๋‹ˆ๋‹ค.
์ด๊ฒƒ์ด "**๊ฒฝ๋กœ ๋™์ž‘ ๋ฐ์ฝ”๋ ˆ์ดํ„ฐ**"์ž…๋‹ˆ๋‹ค.
๋‹ค๋ฅธ ๋™์ž‘๋„ ์“ธ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค:
* `@app.post()`
* `@app.put()`
* `@app.delete()`
์ด๊ตญ์ ์ธ ๊ฒƒ๋“ค๋„ ์žˆ์Šต๋‹ˆ๋‹ค:
* `@app.options()`
* `@app.head()`
* `@app.patch()`
* `@app.trace()`
!!! tip "ํŒ"
๊ฐ ๋™์ž‘(HTTP ๋ฉ”์†Œ๋“œ)์„ ์›ํ•˜๋Š” ๋Œ€๋กœ ์‚ฌ์šฉํ•ด๋„ ๋ฉ๋‹ˆ๋‹ค.
**FastAPI**๋Š” ํŠน์ • ์˜๋ฏธ๋ฅผ ๊ฐ•์ œํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.
์—ฌ๊ธฐ์„œ ์ •๋ณด๋Š” ์ง€์นจ์„œ์ผ๋ฟ ์š”๊ตฌ์‚ฌํ•ญ์ด ์•„๋‹™๋‹ˆ๋‹ค.
์˜ˆ๋ฅผ ๋“ค์–ด GraphQL์„ ์‚ฌ์šฉํ• ๋•Œ ์ผ๋ฐ˜์ ์œผ๋กœ `POST` ๋™์ž‘๋งŒ ์‚ฌ์šฉํ•˜์—ฌ ๋ชจ๋“  ํ–‰๋™์„ ์ˆ˜ํ–‰ํ•ฉ๋‹ˆ๋‹ค.
### 4 ๋‹จ๊ณ„: **๊ฒฝ๋กœ ๋™์ž‘ ํ•จ์ˆ˜** ์ •์˜
๋‹ค์Œ์€ ์šฐ๋ฆฌ์˜ "**๊ฒฝ๋กœ ๋™์ž‘ ํ•จ์ˆ˜**"์ž…๋‹ˆ๋‹ค:
* **๊ฒฝ๋กœ**: ๋Š” `/`์ž…๋‹ˆ๋‹ค.
* **๋™์ž‘**: ์€ `get`์ž…๋‹ˆ๋‹ค.
* **ํ•จ์ˆ˜**: ๋Š” "๋ฐ์ฝ”๋ ˆ์ดํ„ฐ" ์•„๋ž˜์— ์žˆ๋Š” ํ•จ์ˆ˜์ž…๋‹ˆ๋‹ค (`@app.get("/")` ์•„๋ž˜).
```Python hl_lines="7"
{!../../../docs_src/first_steps/tutorial001.py!}
```
์ด๊ฒƒ์€ ํŒŒ์ด์ฌ ํ•จ์ˆ˜์ž…๋‹ˆ๋‹ค.
`GET` ๋™์ž‘์„ ์‚ฌ์šฉํ•˜์—ฌ URL "`/`"์— ๋Œ€ํ•œ ์š”์ฒญ์„ ๋ฐ›์„ ๋•Œ๋งˆ๋‹ค **FastAPI**์— ์˜ํ•ด ํ˜ธ์ถœ๋ฉ๋‹ˆ๋‹ค.
์œ„์˜ ๊ฒฝ์šฐ `async` ํ•จ์ˆ˜์ž…๋‹ˆ๋‹ค.
---
`async def` ๋Œ€์‹  ์ผ๋ฐ˜ ํ•จ์ˆ˜๋กœ ์ •์˜ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค:
```Python hl_lines="7"
{!../../../docs_src/first_steps/tutorial003.py!}
```
!!! note ์ฐธ๊ณ 
์ฐจ์ด์ ์„ ๋ชจ๋ฅด๊ฒ ๋‹ค๋ฉด [Async: *"In a hurry?"*](../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 ๋ชจ๋ธ์„ ๋ฐ˜ํ™˜ํ•  ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค(๋‚˜์ค‘์— ๋” ์ž์„ธํžˆ ์‚ดํŽด๋ด…๋‹ˆ๋‹ค).
JSON์œผ๋กœ ์ž๋™ ๋ณ€ํ™˜๋˜๋Š” ๊ฐ์ฒด๋“ค๊ณผ ๋ชจ๋ธ๋“ค์ด ๋งŽ์ด ์žˆ์Šต๋‹ˆ๋‹ค(ORM ๋“ฑ์„ ํฌํ•จํ•ด์„œ์š”). ๊ฐ€์žฅ ๋งˆ์Œ์— ๋“œ๋Š” ๊ฒƒ์„ ์‚ฌ์šฉํ•˜์„ธ์š”, ์ด๋ฏธ ์ง€์›๋˜๊ณ  ์žˆ์„ ๊ฒ๋‹ˆ๋‹ค.
## ์š”์•ฝ
* `FastAPI` ์ž„ํฌํŠธ.
* `app` ์ธ์Šคํ„ด์Šค ์ƒ์„ฑ.
* (`@app.get("/")`์ฒ˜๋Ÿผ) **๊ฒฝ๋กœ ๋™์ž‘ ๋ฐ์ฝ”๋ ˆ์ดํ„ฐ** ์ž‘์„ฑ.
* (์œ„์— ์žˆ๋Š” `def root(): ...`์ฒ˜๋Ÿผ) **๊ฒฝ๋กœ ๋™์ž‘ ํ•จ์ˆ˜** ์ž‘์„ฑ.
* (`uvicorn main:app --reload`์ฒ˜๋Ÿผ) ๊ฐœ๋ฐœ ์„œ๋ฒ„ ์‹คํ–‰.

1
docs/ko/mkdocs.yml

@ -52,6 +52,7 @@ nav:
- zh: /zh/
- ์ž์Šต์„œ - ์‚ฌ์šฉ์ž ์•ˆ๋‚ด์„œ:
- tutorial/index.md
- tutorial/first-steps.md
markdown_extensions:
- toc:
permalink: true

Loadingโ€ฆ
Cancel
Save