Warm tip: This article is reproduced from stackoverflow.com, please click
asp.net-core ocelot api-gateway

Ocelot API Gateway Optional Parameter

发布于 2020-03-29 12:46:51

Is there a way to tell Ocelot that a parameter is optional?

Let's say the query param below is optional:

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

If I send a request to /SearchAPI/?query= I get a 404 as response. I need to duplicate the Upstream to not use the param to fix. Is there another way to fix that?

Questioner
Israel Rodriguez
Viewed
72
Roman Marusyk 2020-01-31 16:56

You can use {everything} like

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