OpenFunction / functions-framework

functions-framework for multi-runtime, multi-type functions, and multi-language support
10 stars 6 forks source link

Serve multipe routes on the same function #17

Closed lizzzcai closed 2 years ago

lizzzcai commented 2 years ago

Hi OpenFunction team,

I would like to request a feature of supporting multi routes in the function framework (mainly in python).

use cases:

  1. define custom health endpoint and endpoints for liveness probe and readiness probe (similar issue here https://github.com/OpenFunction/functions-framework/issues/11).
  2. support multi-functions (routes) in a function instance as it is very limited to only support one function in a function instance.
  3. dynamically extract params from the route path. for example: @app.route('/product/<name>', methods=["GET"])

example:

# health function
@app.route("/functions/<funcname>/health", methods=["GET"])
def health(request, funcname):
    return "", 200

# dynamic process function
@app.route("/functions/<funcname>:process", methods=["POST"])
def process(request, funcname):

    function = FUNCTIONS.get(funcname)
    data = dict(request.json)
    return {"output": function.process(data["input"])}

Similiar requests in gcp function-framework:

  1. https://github.com/GoogleCloudPlatform/functions-framework-python/issues/159
  2. https://github.com/GoogleCloudPlatform/functions-framework-python/issues/98
benjaminhuo commented 2 years ago

This is a good requirement, thanks @lizzzcai

benjaminhuo commented 2 years ago

Fixed by https://github.com/OpenFunction/functions-framework-go/issues/51