@ -40,7 +40,7 @@ FastAPI๋ ํ๋์ ์ด๊ณ , ๋น ๋ฅด๋ฉฐ(๊ณ ์ฑ๋ฅ), ํ์ด์ฌ ํ์ค ํ์
ํํธ
* **๋น ๋ฆ** : (Starlette๊ณผ Pydantic ๋๋ถ์) **NodeJS** ๋ฐ **Go**์ ๋๋ฑํ ์ ๋๋ก ๋งค์ฐ ๋์ ์ฑ๋ฅ. [์ฌ์ฉ ๊ฐ๋ฅํ ๊ฐ์ฅ ๋น ๋ฅธ ํ์ด์ฌ ํ๋ ์์ํฌ ์ค ํ๋ ](#performance ).
* **๋น ๋ฅธ ์ฝ๋ ์์ฑ** : ์ฝ 200%์์ 300%๊น์ง ๊ธฐ๋ฅ ๊ฐ๋ฐ ์๋ ์ฆ๊ฐ. *
* **์ ์ ๋ฒ๊ทธ** : ์ฌ๋(๊ฐ๋ฐ์)์ ์ํ ์๋ฌ ์ฝ 40% ๊ฐ์. *
* **์ง๊ด์ ** : ํ๋ฅญํ ํธ์ง๊ธฐ ์ง์. ๋ชจ๋ ๊ณณ์์ < abbr title = "also known as auto-complete, autocompletion, IntelliSense" > ์๋์์ฑ</ abbr > . ์ ์ ๋๋ฒ๊น
์๊ฐ.
* **์ง๊ด์ ** : ํ๋ฅญํ ํธ์ง๊ธฐ ์ง์. ๋ชจ๋ ๊ณณ์์ < abbr title = "๋ค๋ฅธ ๋ง๋ก๋: auto-complete, autocompletion, IntelliSense" > ์๋์์ฑ</ abbr > . ์ ์ ๋๋ฒ๊น
์๊ฐ.
* **์ฌ์** : ์ฝ๊ฒ ์ฌ์ฉํ๊ณ ๋ฐฐ์ฐ๋๋ก ์ค๊ณ. ์ ์ ๋ฌธ์ ์ฝ๊ธฐ ์๊ฐ.
* **์งง์** : ์ฝ๋ ์ค๋ณต ์ต์ํ. ๊ฐ ๋งค๊ฐ๋ณ์ ์ ์ธ์ ์ฌ๋ฌ ๊ธฐ๋ฅ. ์ ์ ๋ฒ๊ทธ.
* **๊ฒฌ๊ณ ํจ** : ์ค๋น๋ ํ๋ก๋์
์ฉ ์ฝ๋๋ฅผ ์ป์ผ์ญ์์ค. ์๋ ๋ํํ ๋ฌธ์์ ํจ๊ป.
@ -127,7 +127,7 @@ 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 >
์น API ๋์ ํฐ๋ฏธ๋์์ ์ฌ์ฉํ < abbr title = "Command Line Interface" > CLI< / abbr > ์ฑ์ ๋ง๋ค๊ณ ์๋ค๋ฉด, < a href = "https://typer.tiangolo.com/" class = "external-link" target = "_blank" > **Typer**< / a > ๋ฅผ ํ์ธํด ๋ณด์ญ์์ค.
์น API ๋์ ํฐ๋ฏธ๋์์ ์ฌ์ฉํ < abbr title = "Command Line Interface - ์ปค๋งจ๋ ๋ผ์ธ ์ธํฐํ์ด์ค " > CLI< / abbr > ์ฑ์ ๋ง๋ค๊ณ ์๋ค๋ฉด, < a href = "https://typer.tiangolo.com/" class = "external-link" target = "_blank" > **Typer**< / a > ๋ฅผ ํ์ธํด ๋ณด์ญ์์ค.
**Typer**๋ FastAPI์ ๋์์
๋๋ค. ๊ทธ๋ฆฌ๊ณ **CLI๋ฅผ ์ํ FastAPI**๊ฐ ๋๊ธฐ ์ํด ์๊ฒผ์ต๋๋ค. โจ๏ธ ๐
@ -161,8 +161,6 @@ $ pip install "fastapi[standard]"
๋ค์ ๋ด์ฉ์ผ๋ก `main.py` ํ์ผ์ ๋ง๋์ญ์์ค:
```Python
from typing import Union
from fastapi import FastAPI
app = FastAPI()
@ -174,7 +172,7 @@ def read_root():
@app .get("/items/{item_id}")
def read_item(item_id: int, q: Union[str, None] = None):
def read_item(item_id: int, q: str | None = None):
return {"item_id": item_id, "q": q}
```
@ -183,9 +181,7 @@ def read_item(item_id: int, q: Union[str, None] = None):
์ฌ๋ฌ๋ถ์ ์ฝ๋๊ฐ `async` / `await` ์ ์ฌ์ฉํ๋ค๋ฉด, `async def` ๋ฅผ ์ฌ์ฉํ์ญ์์ค:
```Python hl_lines="9 14"
from typing import Union
```Python hl_lines="7 12"
from fastapi import FastAPI
app = FastAPI()
@ -197,7 +193,7 @@ async def read_root():
@app .get("/items/{item_id}")
async def read_item(item_id: int, q: Union[str, None] = None):
async def read_item(item_id: int, q: str | None = None):
return {"item_id": item_id, "q": q}
```
@ -288,9 +284,7 @@ INFO: Application startup complete.
Pydantic ๋๋ถ์ ํ์ค Python ํ์
์ ์ฌ์ฉํด ๋ณธ๋ฌธ์ ์ ์ธํฉ๋๋ค.
```Python hl_lines="4 9-12 25-27"
from typing import Union
```Python hl_lines="2 7-10 23-25"
from fastapi import FastAPI
from pydantic import BaseModel
@ -300,7 +294,7 @@ app = FastAPI()
class Item(BaseModel):
name: str
price: float
is_offer: Union[bool, None] = None
is_offer: bool | None = None
@app .get("/")
@ -309,7 +303,7 @@ def read_root():
@app .get("/items/{item_id}")
def read_item(item_id: int, q: Union[str, None] = None):
def read_item(item_id: int, q: str | None = None):
return {"item_id": item_id, "q": q}
@ -374,7 +368,7 @@ item: Item
* ๋ฐ์ดํฐ ๊ฒ์ฆ:
* ๋ฐ์ดํฐ๊ฐ ์ ํจํ์ง ์์ ๋ ์๋์ผ๋ก ์์ฑํ๋ ๋ช
ํํ ์๋ฌ.
* ๊น์ด ์ค์ฒฉ๋ JSON ๊ฐ์ฒด์ ๋ํ ์ ํจ์ฑ ๊ฒ์ฌ.
* ์
๋ ฅ ๋ฐ์ดํฐ < abbr title = "also known as : serialization, parsing, marshalling" > ๋ณํ< / abbr > : ๋คํธ์ํฌ์์ ํ์ด์ฌ ๋ฐ์ดํฐ ๋ฐ ํ์
์ผ๋ก ์ ์ก. ์ฝ์ ์ ์๋ ๊ฒ๋ค:
* ์
๋ ฅ ๋ฐ์ดํฐ < abbr title = "๋ค๋ฅธ ๋ง๋ก๋ : serialization, parsing, marshalling" > ๋ณํ< / abbr > : ๋คํธ์ํฌ์์ ํ์ด์ฌ ๋ฐ์ดํฐ ๋ฐ ํ์
์ผ๋ก ์ ์ก. ์ฝ์ ์ ์๋ ๊ฒ๋ค:
* JSON.
* ๊ฒฝ๋ก ๋งค๊ฐ๋ณ์.
* ์ฟผ๋ฆฌ ๋งค๊ฐ๋ณ์.
@ -382,7 +376,7 @@ item: Item
* ํค๋.
* ํผ(Forms).
* ํ์ผ.
* ์ถ๋ ฅ ๋ฐ์ดํฐ < abbr title = "also known as : serialization, parsing, marshalling" > ๋ณํ< / abbr > : ํ์ด์ฌ ๋ฐ์ดํฐ ๋ฐ ํ์
์ ๋คํธ์ํฌ ๋ฐ์ดํฐ๋ก ์ ํ(JSON ํ์์ผ๋ก):
* ์ถ๋ ฅ ๋ฐ์ดํฐ < abbr title = "๋ค๋ฅธ ๋ง๋ก๋ : serialization, parsing, marshalling" > ๋ณํ< / abbr > : ํ์ด์ฌ ๋ฐ์ดํฐ ๋ฐ ํ์
์ ๋คํธ์ํฌ ๋ฐ์ดํฐ๋ก ์ ํ(JSON ํ์์ผ๋ก):
* ํ์ด์ฌ ํ์
๋ณํ (`str`, `int` , `float` , `bool` , `list` , ๋ฑ).
* `datetime` ๊ฐ์ฒด.
* `UUID` ๊ฐ์ฒด.
@ -445,7 +439,7 @@ item: Item
* ์๋ก ๋ค๋ฅธ ์ฅ์์์ **๋งค๊ฐ๋ณ์** ์ ์ธ: **ํค๋** , **์ฟ ํค** , **ํผ ํ๋** ๊ทธ๋ฆฌ๊ณ **ํ์ผ** .
* `maximum_length` ๋๋ `regex` ์ฒ๋ผ **์ ํจ์ฑ ์ ์ฝ**ํ๋ ๋ฐฉ๋ฒ.
* ๊ฐ๋ ฅํ๊ณ ์ฌ์ฉํ๊ธฐ ์ฌ์ด ** < abbr title = "also known as components, resources, providers, services, injectables" > ์์กด์ฑ ์ฃผ์
</ abbr > ** ์์คํ
.
* ๊ฐ๋ ฅํ๊ณ ์ฌ์ฉํ๊ธฐ ์ฌ์ด ** < abbr title = "๋ค๋ฅธ ๋ง๋ก๋: components, resources, providers, services, injectables" > ์์กด์ฑ ์ฃผ์
</ abbr > ** ์์คํ
.
* **OAuth2** ์ง์์ ํฌํจํ **JWT tokens** ๋ฐ **HTTP Basic**์ ๊ฐ๋ ๋ณด์๊ณผ ์ธ์ฆ.
* (Pydantic ๋๋ถ์) **๊น์ ์ค์ฒฉ JSON ๋ชจ๋ธ**์ ์ ์ธํ๋๋ฐ ๋ ์ง๋ณดํ (ํ์ง๋ง ๋ง์ฐฌ๊ฐ์ง๋ก ์ฌ์ด) ๊ธฐ์ .
* < a href = "https://strawberry.rocks" class = "external-link" target = "_blank" > Strawberry</ a > ๋ฐ ๊ธฐํ ๋ผ์ด๋ธ๋ฌ๋ฆฌ์์ **GraphQL** ํตํฉ.