使用Azure API Management, Functions, Power Apps和Logic App构建应用
ASP.NET OpenAPI 可以非常方便的将我们的Web API项目自动文档化,除了自动文档化以外,我们还可以利用Azure API Management将Open API自动文档化了的Web API整合到当下最火的低代码应用当中,在这篇文章中,我将向您展示如何使用Azure API Management将Azure Functions,Power Apps和Logic Apps等等Azure Service 串联在一起。Azure API Management能够利用已文档化的API定义来公开我们的API 端点,这些端点可以轻松使用在低代码的应用程序中。来看看这有多简单:
将您的API导入Azure API Management
随着Visual Studio 2019 16.9的发布,我们增加了对发布到现有Azure API Management服务实例以及创建Azure API Management的新消费模式实例的支持,所以只要您是Azure的客户,您就可以在需要时使用API Management的监视,安全和集成功能。
当您发布一个已经整合了Swashbukle.AspNetCore(在ASP.NET Core 5 Web API项目中为默认整合选项)的.NET Core API项目到Azure App Service的时候,Azure API Management 选项卡就会出现在发布对话框中,你可以选择一个现成的Azure API Management实例,也可以新建一个实例。
发布完成后,您将能够直接在Azure API Management门户中测试您的API。在这里,您还可以监测流量,控制访问权限并将API导出到其他服务(本文的下一部分中将介绍如何将API导出到其他服务)。
注:Visual Studio中只能新建Azure API Management的消费模式实例。这是Azure API Management的轻量级,无服务器版本,按执行次数收费,每月提供100万次免费调用。如果有现有的Azure API Management实例,也可以将其导入其中。该功能可用于Azure API Management的任何服务级别。
如果您不熟悉Azure API Management,您可以在docs.microsoft.com上了解更多有关使用Visual Studio或Visual Studio Code将API发布到Azure API Management中的信息。
Azure API Management:
https://translate.google.com/translate?hl=zh-CN&prev=_t&sl=en&tl=zh-CN&u=https://azure.microsoft.com/services/api-management/%3FWT.mc_id%3Ddotnet-13135-bradyg
Azure API Management的轻量级,无服务器版本,按执行次数收费,每月提供100万次免费调用:
https://azure.microsoft.com/pricing/details/api-management/?WT.mc_id=dotnet-13135-bradyg
Visual Studio:
https://translate.google.com/translate?hl=zh-CN&prev=_t&sl=en&tl=zh-CN&u=https://docs.microsoft.com/aspnet/core/tutorials/publish-to-azure-api-management-using-vs%3Fview%3Daspnetcore-5.0%26WT.mc_id%3Ddotnet-13135-bradyg
Visual Studio Code:
https://translate.google.com/translate?hl=zh-CN&prev=_t&sl=en&tl=zh-CN&u=https://docs.microsoft.com/azure/api-management/visual-studio-code-tutorial%3FWT.mc_id%3Ddotnet-13135-bradyg
使用您的API和Logic Apps构建工作流程
发布包含OpenAPI的Web API或Azure Functions(包含在本文后附的示例代码库)之后,就可以使用Azure Logic Apps将它们用于业务工作流,定时任务或事件触发的流程中。Logic Apps设计器会自动选择导入现有Azure API Management服务实例中的所有API,从而轻松确定可用的API。
由于Logic Apps设计器知道如何为我在API Management中导入的API绘制OpenAPI文档化的定义,因此很容易弄清楚我需要调用哪个API才能创建重复的库存检查流程。
使用Azure Functions扩展工作流
通过引入Azure Functions的OpenAPI扩展,您能像在WebAPI Controllers中利用NSwag和Swashbukle导出OpenAPI的描述一样, 从Azure Functions中导出你的OpenAPI描述。在示例代码中,您会发现一个通知功能,该功能可以构建一个Adaptive Cards,总结低档产品的库存状态。使用该OpenAPI的扩展的功能属性,Azure Function就可以使用OpenAPI进行文档化描述并导入到Azure API Management了。
public static class InventoryNotifier
{
[OpenApiOperation(operationId: nameof(SendLowStockNotification),
Visibility = OpenApiVisibilityType.Important)
]
[OpenApiRequestBody(contentType: "application/json",
bodyType: typeof(Product[]),
Required = true)
]
[FunctionName(nameof(SendLowStockNotification))]
public static async Task<IActionResult> SendLowStockNotification(
[HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)] HttpRequest req,
ILogger log)
{
// function code...
}
}
导入到Azure API Management后,我们就可以在复杂的Workflow比如Logic App中使用这些Azure Function了。比如我可以在Azure Portal中设计一个workflow, 这个workflow可以混合使用纯Web API和利用OpenAPI导出到Azure API Management的Azure Function。
示例代码库:
https://translate.google.com/translate?hl=zh-CN&prev=_t&sl=en&tl=zh-CN&u=https://github.com/bradygaster/Contoso.Online.Orders%3FWT.mc_id%3Ddotnet-13135-bradyg
OpenAPI:
https://translate.google.com/translate?hl=zh-CN&prev=_t&sl=en&tl=zh-CN&u=https://github.com/Azure/azure-functions-openapi-extension%3FWT.mc_id%3Ddotnet-13135-bradyg
Adaptive Cards:
https://translate.google.com/translate?hl=zh-CN&prev=_t&sl=en&tl=zh-CN&u=https://adaptivecards.io/
使用您的API构建Power Apps
如果要在使用Office 365和Power Apps的环境中构建ASP.NET Core Web API和Azure Functions,Azure API Management可以充分发挥您的HTTP API开发才能。API Management APIs 可以轻松地作为自定义连接器导出到Power Platform。
在这里,我已经开始构建一个可以分发给Microsoft 365 tenant中的任何用户的移动应用程序。因为刚开始,所以我快速地添加了刚刚创建的自定义连接器,该自定义连接器会将Power Platform连接到Azure中托管的API。当我添加新的“Refresh”按钮后,鼠标放上去会出现一个公式输入框,我在这个公式输入框里调用ClearCollect方法以清除集合变量productsCollection ,然后使用StoreAPIs.GetProducts操作重新填充集合。
Power Apps的优点在于,即使在设计模式下,它也可以进行数据绑定。因此,当我开发这个应用程序时,不必一遍又一遍地重新运行,数据会一直绑定到正确的控件上。
如果您对如何使用OpenAPI将您的API文档化并不了解,您可以参考我们之前发布的内容:
使用ASP.NET Core 5 Web API创建可被发现的HTTP API
https://translate.google.com/translate?hl=zh-CN&prev=_t&sl=en&tl=zh-CN&u=https://devblogs.microsoft.com/aspnet/creating-discoverable-http-apis-with-asp-net-core-5-web-api/%3FWT.mc_id%3Ddotnet-13135-bradyg
开源HTTP API软件包和工具
https://translate.google.com/translate?hl=zh-CN&prev=_t&sl=en&tl=zh-CN&u=https://devblogs.microsoft.com/aspnet/open-source-http-api-packages-and-tools/%3FWT.mc_id%3Ddotnet-13135-bradyg
使用Visual Studio Connected Services生成HTTP API客户端
https://translate.google.com/translate?hl=zh-CN&prev=_t&sl=en&tl=zh-CN&u=https://devblogs.microsoft.com/aspnet/generating-http-api-clients-using-visual-studio-connected-services/%3FWT.mc_id%3Ddotnet-13135-bradyg
使用Azure API Management,Functions,Power Apps和Logic Apps构建应用程序(本文)
总结
在这一系列文章中,我们带您从一些确保正确使用OpenAPI对API进行文档化描述的通用指南开始,继而讨论了各种能够帮助您更轻松地设计,构建和测试API的开源项目和工具。最后,向您展示了如何在各种应用程序构建和集成方案中使用这些已经文档化描述的API。希望这些能够带给您一些新的技巧,并给您一些灵感,帮助您在未来的项目中更愉快地构建API和应用程序。
下一步是什么?
我们很高兴能够与您在本系列中分享整个端到端.NET HTTP API开发人员的经验。希望您已经看到.NET可以帮助您构建与行业标准规范,社区项目以及Microsoft工具(例如Visual Studio和Azure)良好集成的高质量API。
如果您是经验丰富的.NET开发人员,则可以在.NET文档中深入研究一些更高级的主题,也可以查看此博客系列中的源代码。
.NET文档:
https://translate.google.com/translate?hl=zh-CN&prev=_t&sl=en&tl=zh-CN&u=https://docs.microsoft.com/aspnet/core/web-api/%3Fview%3Daspnetcore-5.0%26WT.mc_id%3Ddotnet-13135-bradyg
此博客系列中:
https://translate.google.com/translate?hl=zh-CN&prev=_t&sl=en&tl=zh-CN&u=https://github.com/bradygaster/Contoso.Online.Orders%3FWT.mc_id%3Ddotnet-13135-bradyg
源代码:
https://translate.google.com/translate?hl=zh-CN&prev=_t&sl=en&tl=zh-CN&u=https://github.com/bradygaster/Contoso.Online.Orders%3FWT.mc_id%3Ddotnet-13135-bradyg
使用Azure API Management, Functions, Power Apps和Logic App构建应用的更多相关文章
- Azure Data Factory(四)集成 Logic App 的邮件通知提醒
一,引言 上一篇有介绍到使用Azure Data Factory 复制数据,然后有集成 Azure DevOps 实现CI/CD,但是对于真正的项目来说,这些肯定是不够的,比如说在执行 Azure P ...
- 【Azure API 管理】在APIM中使用客户端证书验证API的请求,但是一直提示错误"No client certificate received."
API 管理 (APIM) 是一种为现有后端服务创建一致且现代化的 API 网关的方法. 问题描述 在设置了APIM客户端证书,用户保护后端API,让请求更安全. 但是,最近发现使用客户端证书的API ...
- 【Azure API 管理】APIM 配置Validate-JWT策略,验证RS256非对称(公钥/私钥)加密的Token
问题描述 在APIM中配置对传入的Token进行预验证,确保传入后端被保护的API的Authorization信息正确有效,可以使用validate-jwt策略.validate-jwt 策略强制要求 ...
- 【Azure API 管理】在APIM 中添加 log-to-eventhub 策略,把 Request Body 信息全部记录在Event Hub中
问题描述 根据文档 https://docs.azure.cn/zh-cn/api-management/api-management-howto-log-event-hubs, 可以将Azure A ...
- 【Azure API 管理】Azure APIM服务集成在内部虚拟网络后,在内部环境中打开APIM门户使用APIs中的TEST功能失败
问题描述 使用微软API管理服务(Azure API Management),简称APIM. 因为公司策略要求只能内部网络访问,所以启用了VNET集成.集成方式见: (在内部模式下使用 Azure A ...
- 如何通过Azure Service Management REST API管理Azure服务
通过本文你将了解: 什么是Azure Service Management REST API 如何获取微软Azure 订阅号 如何获取Azure管理证书 如何调用Azure Service Manag ...
- 【Azure API 管理】解决调用REST API操作APIM(API Management)需要认证问题(Authentication failed, The 'Authorization' header is missing)
问题描述 在通过REST API的方式来管理APIM资源,需要调用Azure提供的management接口.而这所有的接口,都是需要有Token并且还需要正确的Token.如若不然,就会获取到如下的错 ...
- 【Azure API 管理】API Management如何有效且快速更新呢?如对APIs/Policy等设置内容
问题描述 APIM中的内容(API, Policy)等内容,如果有需要更新时候,通常可以在Azure APIM门户上操作,通过一个接口一个设置的修改,也可以针对一个接口导入/导出的方式修改.当APIM ...
- 【Azure API 管理】解决API Management添加AAD Group时遇见的 Failed to query Azure Active Directory graph due to error 错误
问题描述 为APIM添加AAD Group时候,等待很长很长的时间,结果添加失败.错误消息为: Write Groups ValidationError :Failed to query Azure ...
随机推荐
- js array contains All In One
js array contains All In One includes & contains & has Array.prototype.contains "use st ...
- SVG tada 🎉 animation effects
SVG tada animation effects symbol & use <svg viewBox="0 0 80 20" xmlns="http:/ ...
- js & array & shuffle
js & array & shuffle const list = [1, 2, 3, 4, 5, 6, 7, 8, 9]; list.sort(() => Math.rando ...
- CSS3 & Grid Layout All In One
CSS3 & Grid Layout All In One W3C https://www.w3.org/TR/css-grid-1/ Grid Layout is a new layout ...
- HTTP cache in depth
HTTP cache in depth HTTP 缓存 https://developers.google.com/web/fundamentals/performance/optimizing-co ...
- Puppeteer: 鼠标移动
文档 mouse.click 是 mouse.move,mouse.down 和 mouse.up 的快捷方式 main.js const pptr = require('puppeteer'); c ...
- spring框架aop用注解形式注入Aspect切面无效的问题解决
由于到最后我的项目还是有个邪门的错没解决,所以先把文章大概内容告知: 1.spring框架aop注解扫描默认是关闭的,得手动开启. 2.关于Con't call commit when autocom ...
- 微信小程序:上滑触底加载下一页
给商品列表页面添加一个上滑触底加载下一页的效果,滚动条触底之后就发送一个请求,来加载下一页数据, 先在getGoodsList中获取总条数 由于总页数需要再另外的一个方法中使用,所以要把总页数变成一个 ...
- Bitter.NotifyOpenPaltform : HTTP 异步消息接收调度中心—开源贡献 之 一:简介
现在互联网的系统越来越趋向于复杂,从单体系统到现在的微服务体系演变.公司与公司的分工也越来越明确. 大数据公司提供了大数据服务 人脸识别公司提供了人脸识别服务 OCR 公司提供了专业的OCR 服务 车 ...
- Android 7.0 TextView点击事件无效修复方案
public class PostTextView extends TextView { private Handler handler = new Handler(Looper.getMainLoo ...