Skip to content
GitLab
  • Menu
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in / Register
  • F FastAPI
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 0
    • Issues 0
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
  • Deployments
    • Deployments
    • Releases
  • Packages & Registries
    • Packages & Registries
    • Package Registry
    • Container Registry
    • Infrastructure Registry
  • Wiki
    • Wiki
  • Activity
  • Graph
  • Create a new issue
  • Commits
  • Issue Boards
Collapse sidebar
  • Sitemule
  • Public
  • workshops
  • open source on IBM i
  • FastAPI
  • Wiki
  • Part 2a. Extending my first service

Part 2a. Extending my first service · Changes

Page history
Update Part 2a. Extending my first service authored Oct 30, 2021 by Jens Melgard Churchill's avatar Jens Melgard Churchill
Hide whitespace changes
Inline Side-by-side
Part-2a.-Extending-my-first-service.md
View page @ 13e08c96
......@@ -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
Clone repository
  • Part 1a. My first service
  • Part 1b. Testing my first service
  • Part 2a. Extending my first service
  • Part 2b. Organise my first service
  • Part 3a. Review my first service
  • Part 3b. Connecting my first service
  • Home