emptygif
Harshe: Hausa

Duk harsuna da frameworks

FastAPI Python

Snippet na Python don FastAPI da ke amsa requests zuwa /pixel.gif da empty GIF, wanda ake decoding ɗinsa sau ɗaya lokacin farawa.

FastAPI Python

Girkawa
pip install "fastapi[standard]"
Fayil
main.py
Gudanar
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"})

Mun gudanar da wannan snippet kuma mun kwatanta bytes ɗin da ya mayar.

Duba shi

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

Shafin hukuma: FastAPI

Ƙari a Python