asp.net-core - Ocelot API 网关可选参数

标签 asp.net-core api-gateway ocelot

有没有办法告诉 Ocelot 一个参数是可选的?

假设下面的查询参数是可选的:

"DownstreamPathTemplate": "/api/SearchAPI/?query={query}",
"DownstreamScheme": "https",
"DownstreamHostAndPorts": [
    {
        "Host": "localhost",
        "Port": 5000
    }
],
"UpstreamPathTemplate": "/api/SearchAPI/?query={query}",
"UpstreamHttpMethod": [ "GET" ],
"FileCacheOptions": {
    "TtlSeconds": 60
}

如果我向 /SearchAPI/?query= 发送请求,我会收到 404 作为响应。我需要复制 Upstream 以不使用参数来修复。还有其他方法可以解决这个问题吗?

最佳答案

你可以像这样使用{everything}

"DownstreamPathTemplate": "/api/SearchAPI/{everything}"

关于asp.net-core - Ocelot API 网关可选参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59637188/

相关文章:

c# - Chrome 使用与 Visual Studio 不同的 localhost SSL 证书

c# - 如何在 ConfigureServices .Net Core 3.1 中注册具有多个接口(interface)的服务并将该服务用作单个实例

c# - 通过 React 客户端应用程序连接到 Ocelot Api 网关中的 SignalR 集线器时,出现未处理的拒绝(错误)(HttpError)

asp.net-core - 红隼服务器 : How to bind different ports to different controllers?

oauth - 使用 Openiddict 的 ASP.NET Core 1.0 OAuth 服务器

c# - 如何停止 Ocelot 的 PreAuthenticationMiddleware 中的请求?

amazon-web-services - 如何在 API 网关中对每个用户进行速率限制?

docker - 在没有 Kubernetes 的本地开发环境中运行 Ambassador

.net-core - 如何使用声明(角色)设置 Ocelot?

asp.net-core - API 网关 Ocelot 和 Kubernetes