Thiago Freitas
Thiago Freitas

Reputation: 419

ask about writing krakend config.json

we are starting with krakend as API Gateway. My question is: We have backend app that have 100 more endpoints. We need write a json with all 100+ endpoints? It's possible use something like wildcard?

Upvotes: 2

Views: 1100

Answers (2)

Math.Random
Math.Random

Reputation: 152

Sadly in Community Edition no, i made this:

{
      "endpoint": "/",
      "input_headers":[
        "*"
      ],
      "input_query_strings":[
        "*"
      ],
      "method": "GET",
      "output_encoding": "no-op",
      "extra_config": {},
      "backend": [{
        "url_pattern": "",
        "encoding": "no-op",
        "sd": "static",
        "method": "GET",
        "extra_config": {
        },
        "host": [
          "{{ env "HOST" }}"
        ],
        "disable_host_sanitize": false
    }]
},{
      "endpoint": "/{level1}",
      "input_headers":[
        "*"
      ],
      "input_query_strings":[
        "*"
      ],
      "method": "GET",
      "output_encoding": "no-op",
      "extra_config": {
      },
      "backend": [{
        "url_pattern": "/{level1}",
        "encoding": "no-op",
        "sd": "static",
        "method": "GET",
        "extra_config": {
        },
        "host": [
          "{{ env "HOST" }}"
        ],
        "disable_host_sanitize": false
    }]
},{
      "endpoint": "/{level1}/{level2}",
      "input_headers":[
        "*"
      ],
      "input_query_strings":[
        "*"
      ],
      "method": "GET",
      "output_encoding": "no-op",
      "extra_config": {
      },
      "backend": [{
        "url_pattern": "/{level1}/{level2}",
        "encoding": "no-op",
        "sd": "static",
        "method": "GET",
        "extra_config": {
        },
        "host": [
          "{{ env "HOST" }}"
        ],
        "disable_host_sanitize": false
    }]
},{
      "endpoint": "/{level1}/{level2}/{level3}",
      "input_headers":[
        "*"
      ],
      "input_query_strings":[
        "*"
      ],
      "method": "GET",
      "output_encoding": "no-op",
      "extra_config": {
      },
      "backend": [{
        "url_pattern": "/{level1}/{level2}/{level3}",
        "encoding": "no-op",
        "sd": "static",
        "method": "GET",
        "extra_config": {
        },
        "host": [
          "{{ env "HOST" }}"
        ],
        "disable_host_sanitize": false
    }]
},{
      "endpoint": "/{level1}/{level2}/{level3}/{level4}",
      "input_headers":[
        "*"
      ],
      "input_query_strings":[
        "*"
      ],
      "method": "GET",
      "output_encoding": "no-op",
      "extra_config": {
      },
      "backend": [{
        "url_pattern": "/{level1}/{level2}/{level3}/{level4}",
        "encoding": "no-op",
        "sd": "static",
        "method": "GET",
        "extra_config": {
        },
        "host": [
          "{{ env "HOST" }}"
        ],
        "disable_host_sanitize": false
    }]
}

And you can add as much levels as you need. It is not a good solution, and is better to have your routes well documented, but in my case that was imposible because we are handeling with a weird coupled monolith.

This has nothing to do with your question but at the same time if you want to make a "catch it all" endpoint be aware that you cannot set an evaluation order. Krakend uses a radix tree to order the routes taking the constants first in order of precendece and then the variables, so naturally an endpoint like : /racoons is gonna be evaluated first than /{level1}

Upvotes: 0

alo
alo

Reputation: 1440

Yes, there is a wildcard feature, it is available on the Enterprise Edition.

If you want to stick with the Community Edition, then you can declare a list of 100+ endpoints in a json file and loop them in the template (so you actually write one configuration) using Flexible Configuration

Upvotes: 0

Related Questions