FastAPI의 middleware는 모든 요청과 응답에 대해 실행되는 코드로, 엔드포인트를 감싸 로깅, 타이밍, CORS, 헤더 추가 같은 횡단 관심사(cross-cutting concern)를 처리합니다. FastAPI는 Starlette의 middleware 시스템을 사용합니다(ASGI 기반).
커스텀 middleware 작성
time
():
start = time.time()
response = call_next(request)
response.headers[] = (time.time() - start)
response
