.NET Core 微服务—API网关(Ocelot) 教程 [二]
上篇文章( .NET Core 微服务—API网关(Ocelot) 教程 [一] )介绍了Ocelot 的相关介绍。 接下来就一起来看如何使用,让它运行起来。 环境准备 为了验证Ocelot 网关效果,我们先创建3个webapi项目:目录api(Api.Catalog)、订单api(Api.Ordering)、Ocelot网关(ApiGateway.Ocelot);并为每个WebApi项目添加Values控制器(ValuesController),用于区分最终调用效果 如下图: Ocelot使用 1、添加 Ocelot包依赖: 接下来使用Nuget包管理工具为ApiGateway.Ocelot项目添加Ocelot包引用: 当然也可用使用命令方式添加Ocelot包: Install-Package Ocelot 2、添加Ocelot配置文件:(重点) 向ApiGateway.Ocelot项目添加一个Ocelot.json配置文件,并修改配置文件为如下内容: { " GlobalConfiguration " : { }, " Routes " : [ { " DownstreamPathTemplate " : " /api/{everything} " , " DownstreamScheme " : " http " , "