How can I do Routing in Azure Functions?

前端 未结 2 731
不知归路
不知归路 2021-02-05 21:08

I know that I can use url parameters like this:

\"myfunction?p=one&p2=two\"

and in code that becomes

request.query.p = \"o         


        
2条回答
  •  难免孤独
    2021-02-05 21:35

    azure-function-express

    With azure-function-express you can use all expressjs functionalities including routing ;)

    const createHandler = require("azure-function-express").createAzureFunctionHandler;
    const express = require("express");
    
    // Create express app as usual
    const app = express();
    app.get("/api/:foo/:bar", (req, res) => {
      res.json({
        foo  : req.params.foo,
        bar  : req.params.bar
      });
    });
    
    // Binds the express app to an Azure Function handler
    module.exports = createHandler(app);
    

    See more examples here including a way to handle all routes within a single Azure Function handler.

    PS: Feel free to contribute to the project!

提交回复
热议问题