emptygif
Language: English

All languages and frameworks

FastAPI Python

A Python snippet for FastAPI that answers requests for /pixel.gif with the empty GIF, decoded once at startup.

FastAPI Python

Install
pip install "fastapi[standard]"
File
main.py
Run
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"})

We ran this snippet and compared the bytes it returned.

Check it

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

Official site: FastAPI

More in Python