... | ... | @@ -38,16 +38,17 @@ You'll note a lot of new files have appeared, of note are: |
|
|
|
|
|
## Before we start adding stuff, lets introduce some timestamps, everyone loves timestamps!
|
|
|
|
|
|
FastAPI has a concept called _middleware_ - from te documentation:
|
|
|
FastAPI has a concept called _middleware_ - from the documentation:
|
|
|
|
|
|
_A "middleware" is a function that works with every **request** before it is processed by any specific path operation._\
|
|
|
_And also with every **response** before returning it._
|
|
|
|
|
|
Lets take advantage of that, to add timing data our request/response cycle, run `vim main.py`
|
|
|
|
|
|
Enter insert-mode ( press `i` ), and insert the following code at line 12 ( below `app = FastAPI()` )
|
|
|
Enter insert-mode ( press `i` ), and insert the following code at line 7 ( below `app = FastAPI()` )
|
|
|
|
|
|
```plaintext
|
|
|
|
|
|
```
|
|
|
from time import time
|
|
|
from fastapi import Request
|
|
|
|
... | ... | @@ -59,4 +60,5 @@ async def add_process_time_header(request: Request, call_next): |
|
|
|
|
|
response.headers["X-Process-Time"] = str(process_time)
|
|
|
return response
|
|
|
|
|
|
``` |
|
|
\ No newline at end of file |