3

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?

Izzy Rodriguez
  • 2,097
  • 3
  • 21
  • 32

1 Answers1

3

You can use {everything} like

"DownstreamPathTemplate": "/api/SearchAPI/{everything}"
Roman Marusyk
  • 23,328
  • 24
  • 73
  • 116
  • I had to create two different templates: one for `/XXX/dev/abp-api/api/identity/roles`, another one - for `/XXX/dev/abp-api/api/identity/roles/{any}` (or "everything" instead of "any", does not matter). Otherwise, my POST request for `/XXX/dev/abp-api/api/identity/roles` is not routed as ``/XXX/dev/abp-api/api/identity/roles/{any}`. I use the latest version of Ocelot (19.0.2). Isn't it possible that some bug has been introduced lately? – Alexander Jun 24 '23 at 00:21
  • Same here {everything} does not work for me when I use empty {everything}, any solutions other than specifying separate route? – QTM Jul 19 '23 at 09:35
  • Look, the answer was valid in 2020, it'd be better to ask a new question for the latest version of Ocelot and include a link to this question if it helps provide context – Roman Marusyk Jul 19 '23 at 10:40