본문 바로가기
카테고리 없음

FastAPI 서버 구축하기

by huffpuffkin 2026. 3. 15.

FastAPI

 

FastAPI

FastAPI framework, high performance, easy to learn, fast to code, ready for production

fastapi.tiangolo.com

 

나는 공식 문서를​ 참고해서 작성했다. 

 

from fastapi import FastAPI
from typing import Union

app = FastAPI()

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

def main():
    print("Hello from chord-ai!")


if __name__ == "__main__":
    main()

공식 문서 기준 다음과 같이 main.py를 작성하고 서버를 실행하면 된다.

 

 

 

 

서버는 다음 명령어를 사용해 실행할 수 있다. 

fastapi dev main.py   # FastAPI 서버 실행

 

 

 

 

 

http://127.0.0.1:8000/ 또는 http://localhost:8000/를 확인하면 다음과 같이 응답을 확인할 수 있다. 기본적으로 서버는 구축이 된 것이다.

 

 

 

 

 

 

http://localhost:8000/docs로 접속하면 다음과 같이 swagger 문서도 확인이 가능하다.

(따로 구축하지 않아도 된다는 점에서 매우매우매우 놀랐다)

 

 

 

 

스웨거 외에도 http://127.0.0.1:8000/redoc도 기본으로 제공한다.

 

 

 

 

https://fastapi.tiangolo.com/ko/advanced/

 

심화 사용자 안내서 - FastAPI

FastAPI framework, high performance, easy to learn, fast to code, ready for production

fastapi.tiangolo.com

 

이후에는 해당 문서를 참고해서 개발을 진행해볼 예정이다