Starlette Python
ตัวอย่างโค้ด Python สำหรับ Starlette ที่ตอบคำขอไปยัง /pixel.gif ด้วย GIF ว่าง ซึ่งถอดรหัสเพียงครั้งเดียวตอนเริ่มทำงาน
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)])
เรารันตัวอย่างโค้ดนี้และเทียบไบต์ที่ได้กลับมาแล้ว
ตรวจสอบ
curl -sI http://localhost:8080/pixel.gif
เพิ่มเติมใน 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