From f4ed6c2d6f4ece463e35263de22faf85563c7702 Mon Sep 17 00:00:00 2001 From: Xeryus Stokkel Date: Wed, 2 Feb 2022 12:25:58 +0100 Subject: [PATCH] Return information about the request --- .gitignore | 2 ++ main.py | 21 +++++++++++++++++++++ requirements.txt | 17 +++++++++++++++++ 3 files changed, 40 insertions(+) create mode 100644 .gitignore create mode 100644 main.py create mode 100644 requirements.txt diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7a60b85 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +__pycache__/ +*.pyc diff --git a/main.py b/main.py new file mode 100644 index 0000000..80351dc --- /dev/null +++ b/main.py @@ -0,0 +1,21 @@ +from fastapi import FastAPI, Header, Request + +app = FastAPI() + +@app.get("/") +def root(request: Request): + return { + "method": request.method, + "url": { + "url": request.url._url, + "scheme": request.url.scheme, + "hostname": request.url.hostname, + "port": request.url.port, + "path": request.url.path, + }, + "headers": request.headers, + "client": { + "ip-address": request.client.host, + "port": request.client.port, + }, + } diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..b3701e3 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,17 @@ +anyio==3.5.0 +asgiref==3.5.0 +click==8.0.3 +fastapi==0.73.0 +h11==0.13.0 +httptools==0.3.0 +idna==3.3 +pydantic==1.9.0 +python-dotenv==0.19.2 +PyYAML==6.0 +sniffio==1.2.0 +starlette==0.17.1 +typing_extensions==4.0.1 +uvicorn==0.17.1 +uvloop==0.16.0 +watchgod==0.7 +websockets==10.1