goo*_*ate 6 azure model-binding azure-functions
我需要创建一个响应HTTP POST的Azure功能,并利用集成的模型绑定.
我该怎么修改呢
[FunctionName("TokenPolicy")]
public static HttpResponseMessage Run([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = "TokenPolicy/{IssuerID}/{SpecificationID}")]HttpRequestMessage req, string IssuerID, string specificationID, TraceWriter log)
{
log.Info("C# HTTP trigger function processed a request. TokenPolicy");
// Fetching the name from the path parameter in the request URL
return req.CreateResponse(HttpStatusCode.OK, "data " + specificationID);
}
Run Code Online (Sandbox Code Playgroud)
以这种方式,我的客户端POST的对象,我有正常的ASP.NET样式模型绑定?
HttpRequestMessage您可以使用自定义类型,而不是使用参数。绑定将尝试将请求正文解析为 JSON 并在调用函数之前填充该对象。这里有一些细节:https : //docs.microsoft.com/azure/azure-functions/functions-bindings-http-webhook-trigger?tabs=csharp#payload
根据代码中HTTP触发器的文档,您可以简单地接受自己的对象:
对于自定义类型(例如POCO),Functions将尝试将请求正文解析为JSON,以填充对象属性。
public class MyModel
{
public int Id { get; set; }
public string Name { get; set; }
}
[FunctionName("TokenPolicy")]
public static HttpResponseMessage Run([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = "TokenPolicy/{IssuerID}/{SpecificationID}")]MyModel myObj, string IssuerID, string specificationID, TraceWriter log)
{
log.Info("C# HTTP trigger function processed a request. TokenPolicy");
// Do something your your object
return new HttpResponseMessage(HttpStatusCode.OK);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2662 次 |
| 最近记录: |