-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
main.py
100 lines (83 loc) · 3.28 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import platform
from typing import Union
from fastapi import FastAPI, Request, Response
from fastapi.responses import FileResponse
from fastapi.staticfiles import StaticFiles
from pydantic import BaseModel
from lib.apis import methods
from lib.apis import request
from lib.apis import status
from lib.apis import redirect
from lib.apis import redirect_final
from lib.apis import anything
from lib.apis import response
from lib.apis import response_formats
from lib.apis import cookies
from lib.apis import images
from lib.apis import dynamic
from lib.apis import qrcode
from lib.apis import test_password_manager
from lib.apis import meta
from lib.fastapi import tags_metadata, description, app_version
app = FastAPI(docs_url = "/", redoc_url = None,
title = "FastAPI Httpbin",
description = description,
version = app_version,
swagger_ui_parameters = {"docExpansion":"none"},
openapi_tags = tags_metadata
)
#
# Ordering of these in the Swagger docs is set in lib/fastapi.py
#
app.include_router(methods.router, tags = ["HTTP Methods"])
app.include_router(status.router, tags = ["Status Codes"])
app.include_router(request.router, tags = ["Request Inspection"])
app.include_router(response.router, tags = ["Responses"])
app.include_router(response_formats.router, tags = ["Response Formats"])
app.include_router(redirect_final.router, tags = ["Redirects"])
app.include_router(qrcode.router, tags = ["QR Codes"])
app.include_router(redirect.router, tags = ["Redirects"])
app.include_router(anything.router, tags = ["Anything"])
app.include_router(cookies.router, tags = ["Cookies"])
app.include_router(images.router, tags = ["Images"])
app.include_router(dynamic.router, tags = ["Dynamic Data"])
app.include_router(test_password_manager.router, tags = ["Forms"])
app.include_router(meta.router, tags = ["Meta"])
#
# Load some static resources
#
app.mount("/about", StaticFiles(directory = "static/about", html = True), name = "static")
app.mount("/roadmap", StaticFiles(directory = "static/roadmap", html = True), name = "static")
app.mount("/qrcode", StaticFiles(directory = "static/qrcode", html = True), name = "static")
app.mount("/test-password-manager-form", StaticFiles(directory = "static/password-manager", html = True), name = "static")
@app.middleware("http")
async def add_process_time_header(request: Request, call_next):
response = await call_next(request)
response.headers["X-FastAPI-Httpbin-version"] = app_version
response.headers["X-Website"] = "https://httpbin.dmuth.org/"
response.headers["X-app-hostname"] = platform.node()
return response
favicon_path = "static/favicon.jpg"
@app.get('/favicon.ico', summary = "Favicon endpoint", tags = ["Images"],
response_class = FileResponse,
responses={
200: {
"content": {"image/jpeg": {}},
"description": "Return a 32x32 favicon in JPG format.",
}
}
)
async def favicon(response: Response):
return FileResponse(favicon_path)
logo_path = "img/logo.png"
@app.get('/static/logo.png', summary = "Logo endpoint", tags = ["Images"],
response_class = FileResponse,
responses={
200: {
"content": {"image/jpeg": {}},
"description": "Return the logo.",
}
}
)
async def logo(response: Response):
return FileResponse(logo_path)