Starlette Python
Snippet Python untuk Starlette yang menjawab request ke /pixel.gif dengan empty GIF, yang di-decode sekali saat startup.
Starlette Python
import base64
from starlette.applications import Starlette
from starlette.requests import Request
from starlette.responses import Response
from starlette.routing import Route
GIF = base64.b64decode("R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==")
async def pixel(request: Request) -> Response:
return Response(GIF, media_type="image/gif", headers={"Cache-Control": "no-store"})
app = Starlette(routes=[Route("/pixel.gif", pixel)])
Kami telah menjalankan snippet ini dan membandingkan byte yang dikembalikannya.
Periksa
curl -sI http://localhost:8080/pixel.gif
Lainnya dalam Python
- AWS Lambda (Python)
- Google Cloud Run functions (Python)
- FastAPI
- Litestar
- Django
- Flask
- aiohttp
- Sanic
- Quart
- Falcon
- Robyn
- BlackSheep
- Tornado
- Bottle
- Pyramid
- Microdot (CPython and MicroPython)
- Raw ASGI (Uvicorn, Granian, Hypercorn)
- Raw WSGI (Gunicorn, uWSGI, mod_wsgi)
- Python standard library (http.server)
- FastHTML
- Python one-liner