emptygif
Bahasa: Bahasa Indonesia

Semua bahasa dan framework

FastAPI Python

Snippet Python untuk FastAPI yang menjawab request ke /pixel.gif dengan empty GIF, yang di-decode sekali saat startup.

FastAPI Python

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

Kami telah menjalankan snippet ini dan membandingkan byte yang dikembalikannya.

Periksa

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

Situs resmi: FastAPI

Lainnya dalam Python