Skip to content

โœ… ๐Ÿ‡จ๐Ÿ‡ป - ๐Ÿบ, โœณ, ๐ŸŽ

๐Ÿ‘† ๐Ÿ’ช ๐Ÿ—ป ๐Ÿ‡จ๐Ÿ‡ป ๐Ÿˆธ ๐Ÿ‘† ๐Ÿ‘€ โฎ๏ธ ๐ŸŽง ๐Ÿˆธ - ๐Ÿ—ป, โ›… ๐Ÿ—ณ.

๐Ÿ‘ˆ, ๐Ÿ‘† ๐Ÿ’ช โš™๏ธ WSGIMiddleware & โš™๏ธ โšซ๏ธ ๐ŸŽ ๐Ÿ‘† ๐Ÿ‡จ๐Ÿ‡ป ๐Ÿˆธ, ๐Ÿ–ผ, ๐Ÿบ, โœณ, โ™’๏ธ.

โš™๏ธ WSGIMiddleware

๐Ÿ‘† ๐Ÿ’ช ๐Ÿ—„ WSGIMiddleware.

โคด๏ธ ๐ŸŽ ๐Ÿ‡จ๐Ÿ‡ป (โœ… ๐Ÿบ) ๐Ÿ“ฑ โฎ๏ธ ๐Ÿ› ๏ธ.

& โคด๏ธ ๐Ÿ—ป ๐Ÿ‘ˆ ๐Ÿ”ฝ โžก.

from fastapi import FastAPI
from fastapi.middleware.wsgi import WSGIMiddleware
from flask import Flask, request
from markupsafe import escape

flask_app = Flask(__name__)


@flask_app.route("/")
def flask_main():
    name = request.args.get("name", "World")
    return f"Hello, {escape(name)} from Flask!"


app = FastAPI()


@app.get("/v2")
def read_main():
    return {"message": "Hello World"}


app.mount("/v1", WSGIMiddleware(flask_app))

โœ… โšซ๏ธ

๐Ÿ”œ, ๐Ÿ”  ๐Ÿ“จ ๐Ÿ”ฝ โžก /v1/ ๐Ÿ”œ ๐Ÿต ๐Ÿบ ๐Ÿˆธ.

& ๐ŸŽ‚ ๐Ÿ”œ ๐Ÿต FastAPI.

๐Ÿšฅ ๐Ÿ‘† ๐Ÿƒ โšซ๏ธ โฎ๏ธ Uvicorn & ๐Ÿšถ http://localhost:8000/v1/ ๐Ÿ‘† ๐Ÿ”œ ๐Ÿ‘€ ๐Ÿ“จ โšช๏ธโžก๏ธ ๐Ÿบ:

Hello, World from Flask!

& ๐Ÿšฅ ๐Ÿ‘† ๐Ÿšถ http://localhost:8000/v2 ๐Ÿ‘† ๐Ÿ”œ ๐Ÿ‘€ ๐Ÿ“จ โšช๏ธโžก๏ธ FastAPI:

{
    "message": "Hello World"
}