【发布时间】:2020-09-09 23:02:23
【问题描述】:
我仍在尝试了解 Azure Functions 和最佳实践,但据我了解,有两种方法可以通过 http 动词(GET、POST 等)分隔逻辑。是否有更喜欢以下两种方法中的任何一种的标准或最佳实践?更重要的是,假设底层逻辑保持不变,这两种方法在 Azure 中运行时是否存在成本差异?
方法一:
public static class Function1
{
[FunctionName("Function1")]
public static async Task<IActionResult> Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req)
{
if (req.Method == HttpMethods.Get)
{
// do stuff here
}
else if (req.Method == HttpMethods.Post)
{
// do stuff here
}
}
}
方法B:
public static class GetFunction
{
[FunctionName("GetFunction")]
public static async Task<IActionResult> Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = null)] HttpRequest req)
{
// do stuff here
}
}
public static class PostFunction
{
[FunctionName("PostFunction")]
public static async Task<IActionResult> Run([HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)] HttpRequest req)
{
// do stuff here
}
}
【问题讨论】:
标签: azure .net-core azure-functions azure-function-app azure-functions-core-tools