fastapi 베이직 코드 실행

2024. 5. 18. 02:30IT/ServerSide

728x90
반응형

pip3 install fastapi

pip3 install unicorn

 

fastapi랑 unicorn 설치

 

from typing import Union
from fastapi import FastAPI

app = FastAPI()


@app.get("/")
async def root():
    return {"message": "Hello World"}


@app.get("/hello/{tg_name}")
async def say_hello(tg_name: str, q: Union[str, None] = None):
    return {"Hello":  {tg_name}, "Hello": q}

 

f5나 run 말고 fafstapi dev main.py 를 터미널에 입력해서 명령어로 실행,

(ctrl+c 가 종료 명령어)

 

http://127.0.0.1:8000  <- 들어가면 return 값 볼 수 있음.

 

 

레퍼런스

 

https://github.com/tiangolo/fastapi?tab=readme-ov-file

 

GitHub - tiangolo/fastapi: FastAPI framework, high performance, easy to learn, fast to code, ready for production

FastAPI framework, high performance, easy to learn, fast to code, ready for production - tiangolo/fastapi

github.com

 

 

 

728x90
반응형

'IT > ServerSide' 카테고리의 다른 글

[ridercommunity project] docker/ fastapi/ git upload  (0) 2024.06.09
docker fastapi m1 맥북 에어  (0) 2024.06.08
pip 에러  (0) 2024.05.18
ex1  (0) 2024.05.18
[python web project a.k.a pwp] 0.포폴용 커뮤니티 만들기 시작  (0) 2024.04.30