Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use final paths in the reroutes of configuration.json file. #89

Merged

Conversation

juancash
Copy link
Contributor

The idea is the user not have to map all request when use Ocelot like a simple request redirector.

Imagine the following scenario:

  1. An intranet with three web apis.
  2. An internal gateway like unique enter point to internal requests.
  3. An external gateway like unique enter point to external requests.
  4. The web apis (of point 1) can interact via internal gateway.
  5. Our clients and mobiles apps use the api via external gateway.
  6. The external gateway only offers a couple of methods that are mapped in the configuration file. If we need add or quit methods, we edit it´s configuration file.
  7. The apis of intranet can changes frecuently. Every day our developers can implement two o three new controllers per api. We dont want have to edit the internal gateway configuration continously.

The configuration.json for internal gateway could be something like this:

{
      "UpstreamPathTemplate": "/api/api1/{urlPath}",
      "UpstreamHttpMethod": "Get",
      "DownstreamPathTemplate": "/api/{urlPath}",
      "DownstreamScheme": "http",
      "DownstreamHost": "localhost",
      "DownstreamPort": 5001,
      "QoSOptions": {
        "ExceptionsAllowedBeforeBreaking": 3,
        "DurationOfBreak": 10,
        "TimeoutValue": 10000
      }
    },
    ...
    {
      "UpstreamPathTemplate": "/api/api2/{urlPath}",
      "UpstreamHttpMethod": "Get",
      "DownstreamPathTemplate": "/api/{urlPath}",
      "DownstreamScheme": "http",
      "DownstreamHost": "localhost",
      "DownstreamPort": 5002,
      "QoSOptions": {
        "ExceptionsAllowedBeforeBreaking": 3,
        "DurationOfBreak": 10,
        "TimeoutValue": 10000
      }
    },
    ...
    {
      "UpstreamPathTemplate": "/api/api3/{urlPath}",
      "UpstreamHttpMethod": "Get",
      "DownstreamPathTemplate": "/api/{urlPath}",
      "DownstreamScheme": "http",
      "DownstreamHost": "localhost",
      "DownstreamPort": 5003,
      "QoSOptions": {
        "ExceptionsAllowedBeforeBreaking": 3,
        "DurationOfBreak": 10,
        "TimeoutValue": 10000
      }
    },
    ...

If we add new controllers to our web apis, we don´t need edit the internal gateway configuration, because the traffic will be redirected without problems.

Thanks.

…on.json file.

Adds a unit test method to test the functionality.
@TomPallister
Copy link
Member

@juancash Looks good thanks for the effort! Could you write an acceptance test for this so we know it works end to end? If you just add it to the RoutingTests.cs file. This shouldn't be too much work as you can just use the methods already in there! Basically copy a test and change it!

@juancash juancash mentioned this pull request Apr 22, 2017
@juancash
Copy link
Contributor Author

@tom Acceptance test added.

@TomPallister
Copy link
Member

@juancash thank you very much! I will merge this now.

@TomPallister TomPallister merged commit 11f5aa0 into ThreeMammals:master Apr 23, 2017
@raman-m raman-m added proposal Proposal for a new functionality in Ocelot Routing Ocelot feature: Routing labels Nov 14, 2024
raman-m added a commit to ggnaegi/Ocelot that referenced this pull request Nov 15, 2024
ggnaegi added a commit that referenced this pull request Nov 17, 2024
* Adding support for placeholder matching between slashes.

* now the behavior is right, it can't be that {finalUrlPath} matches product/products/categories/ since the last slash is part of the template and not the catch-all placeholder

* Performance improvements for EscapeExceptBraces

* EOL: test/Ocelot.UnitTests/DownstreamRouteFinder/UrlMatcher/UrlPathPlaceholderNameAndValueFinderTests.cs
Recover old test for feat 89.
Remove BDDfy from new unit tests.
Apply AAA-pattern.

* Review user scenarios of feat #89 tests

* Refactor unit tests

* Refactor acceptance tests

* Adding documentation for embedded placeholders

* Adding acceptance tests

* Adding suggestions

* again...

* Final code review by @raman-m.
FindGroups method is private, better to return exact type.
Regex optimizations across net6, 7, 8.
XML dev-docs markup review.
Rename 'curly bracket' to 'brace'.

---------

Co-authored-by: Raman Maksimchuk <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
proposal Proposal for a new functionality in Ocelot Routing Ocelot feature: Routing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants