1. FastAPI 설치
FastAPI는 파이썬으로 빠르게 웹 개발을 할 수 있는 웹 프레임워크이다.
pip install fastapi
2. Uvicorn 설치
웹 서버로는 Uvicorn을 사용합니다.
pip install uvicorn
3. 파이썬 작성
from fastapi import FastAPI
import uvicorn
# FastAPI 인스턴스 생성
app = FastAPI()
# 요청 시 응답을 해주는 함수들
@app.get("/")
async def root():
return 'welcome!'
@app.get("/hello")
async def world():
return 'hello!'
# 서버 실행
if __name__ == "__main__":
uvicorn.run(app, host="127.0.0.1", port="80")
4. 실행 확인
http://localhost
http://localhost/hello
'Python' 카테고리의 다른 글
html에서 파이썬 변수 사용하기 (0) | 2023.01.05 |
---|---|
FastAPI get방식, post방식 (0) | 2023.01.05 |
파이썬 sqlite 연동 (0) | 2023.01.04 |
파이썬 mssql 연동 (0) | 2023.01.03 |
파이썬 문자열을 리스트로 변환 (0) | 2023.01.02 |