Return information about the request

This commit is contained in:
Xeryus Stokkel 2022-02-02 12:25:58 +01:00
parent 44d851b14f
commit f4ed6c2d6f
Signed by: Xeryus Stokkel
GPG Key ID: 7023C2C891DDE681
3 changed files with 40 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
__pycache__/
*.pyc

21
main.py Normal file
View File

@ -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,
},
}

17
requirements.txt Normal file
View File

@ -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