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?

2
  • 2
    You just need to configure a path with no query string - /api/SearchAPI/ - then you can use with and without. Commented Jan 8, 2020 at 8:23
  • 1
    @tomredfern please, add as an answer so I can give you proper credit. Thanks! Commented Jan 8, 2020 at 17:06

1 Answer 1

3

You can use {everything} like

"DownstreamPathTemplate": "/api/SearchAPI/{everything}"
Sign up to request clarification or add additional context in comments.

3 Comments

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?
Same here {everything} does not work for me when I use empty {everything}, any solutions other than specifying separate route?
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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.