创建服务kong api时如何传递参数

时间:2018-10-09 22:20:18

标签: api microservices kong

我正在尝试在kong中创建一个服务,该服务的url接收路径变量“ example / {id} / example”,但是kong抛出以下异常

卷曲以创建服务

curl -i -X POST --url http://localhost:8001/services/ -H "Cache-Control: no-cache" -H "Content-Type: application/x-www-form-urlencoded" -d "protocol=http&host=localhost&port=8090&path=/v1/{folio}/ejemplo&name=name-services"
创建此内容时

例外

{"strategy":"postgres","message":"schema violation (path: invalid path: '\/v1\/{folio}\/ejemplo' (characters outside of the reserved list of RFC 3986 found))","name":"schema violation","fields":{"path":"invalid path: '\/v1\/{folio}\/ejemplo' (characters outside of the reserved list of RFC 3986 found)"},"code":2}

请帮助

2 个答案:

答案 0 :(得分:1)

这是因为您的路径未编码

来自validate_path

local function validate_path(path)
  if not string.match(path, "^/[%w%.%-%_~%/%%]*$") then
    return nil,
           "invalid path: '" .. path ..
           "' (characters outside of the reserved list of RFC 3986 found)",
           "rfc3986"
  end

您可以在curl中使用--data-urlencode选项而不是-d来对数据进行url编码。或者,只需将路径设置为/v1/%7Bfolio%7D/ejemplo%26name%3Dname-services

答案 1 :(得分:0)

我在 this konghq 中找到讨论您可以在 URI 中使用正则表达式。

将路线映射为 /example/\d+/example 对我有用。