emptygif
Sprache: Deutsch

Alle Sprachen und Frameworks

FastAPI Python

Ein Python-Snippet für FastAPI, das Anfragen an /pixel.gif mit dem leeren GIF beantwortet, das einmal beim Start dekodiert wird.

FastAPI Python

Installieren
pip install "fastapi[standard]"
Datei
main.py
Ausführen
fastapi run main.py --port 8080
import base64

from fastapi import FastAPI, Response

GIF = base64.b64decode("R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==")

app = FastAPI()


@app.get("/pixel.gif", include_in_schema=False)
def pixel() -> Response:
    return Response(GIF, media_type="image/gif", headers={"Cache-Control": "no-store"})

Wir haben dieses Snippet ausgeführt und die zurückgegebenen Bytes verglichen.

Prüfen

curl -sI http://localhost:8080/pixel.gif

Offizielle Website: FastAPI

Mehr in Python