ThreeMammals / Ocelot

.NET API Gateway

Home Page:https://www.nuget.org/packages/Ocelot

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Proposal to add ExtraProps to the configuration

Burgyn opened this issue · comments

If the need arises on the Ocelot usage side for an extension, we usually have to work with some custom settings in the Ocelot downstream route configuration as well.

The current options are that we put the custom settings into a custom setup and use the downstream key as a reference to it, or we can add them to the original JSON setup and read them ourselves (duplicate read).

From an extensibility point of view, it would be nice if we could add additional properties that the programmer could then read.

Proposal

 "ExtraProps" : {
    "CachePolicies": ["policy1", "policy2"],
    "SwaggerKey": "todo"
  }

Whole usage

{
    "Routes": [
        {
          "DownstreamPathTemplate": "/todos/{id}",
          "DownstreamScheme": "https",
          "DownstreamHostAndPorts": [
            {
               "Host": "jsonplaceholder.typicode.com",
               "Port": 443
            }
          ],
         "UpstreamPathTemplate": "/todos/{id}",
         "UpstreamHttpMethod": [ "Get" ],
         // 👇 additional properties for better extensibility
         "ExtraProps" : {
            "CachePolicies": ["policy1", "policy2"],
            "SwaggerKey": "todo",
            "AnotherProp": "value"
          }
        }
    ]
}

Usage in middleware:

PreQueryStringBuilderMiddleware = async (context, next) =>
{
  DownstreamRoute? route = context.Items.DownstreamRoute();
  var cachePolicies = route.GetExtraProps<string[]>("CachePolicies");
  ...
}

I can prepare PR for this change. I just want to check if this is a change that fits the direction of the project.

Thank you in advance for your reply.


{
    "Routes": [
        {
          "DownstreamPathTemplate": "/todos/{id}",
          "DownstreamScheme": "https",
          "DownstreamHostAndPorts": [
            {
               "Host": "jsonplaceholder.typicode.com",
               "Port": 443
            }
          ],
         "UpstreamPathTemplate": "/todos/{id}",
         "UpstreamHttpMethod": [ "Get" ],
         // 👇 additional properties for better extensibility
         "CachePolicies": ["policy1", "policy2"],
         "SwaggerKey": "todo",
         "AnotherProp": "value"
        }
    ]
}

Theoretically, we can also do that extra properties will be on the main level. This is nicer from a usage point of view, but more complicated to implement.
I don't know what you prefer.

Duplicate of #738

Hi Miňo!
Thanks for PR creation! But unfortunately your issue is duplicate of #738 which can be closed by #1843 (ready on 80-90%)


I can prepare PR for this change. I just want to check if this is a change that fits the direction of the project.

No, thanks! See #1843
I invite you to review #1843 only...
Your issue will be linked to #1843 too.

Hi @raman-m,

thanks for linking.

M.

Reopen for official closing