github.com/avenga/couper@v1.12.2/server/testdata/integration/functions/01_couper.hcl (about)

     1  server "api" {
     2    api {
     3      base_path = "/v1"
     4  
     5      endpoint "/merge" {
     6        response {
     7          headers = {
     8            x-merged-1 = json_encode(merge({"foo": [1]}, {"foo": [2]}))
     9            x-merged-2 = json_encode(merge({bar = [3]}, {bar = [4]}))
    10            x-merged-3 = json_encode(merge(["a"], ["b"]))
    11          }
    12        }
    13      }
    14  
    15      endpoint "/coalesce" {
    16        response {
    17          headers = {
    18            x-coalesce-1 = coalesce(request.path, "default")
    19            x-coalesce-2 = coalesce(request.cookies.undef, "default")
    20            x-coalesce-3 = coalesce(request.query.q[1], "default")
    21            x-coalesce-4 = coalesce(request.cookies.undef, request.query.q[1], "default", request.path)
    22          }
    23        }
    24      }
    25  
    26      endpoint "/default" {
    27        response {
    28          headers = {
    29            x-default-1 = default(request.path, "default")
    30            x-default-2 = default(request.cookies.undef, "default")
    31            x-default-3 = default(request.query.q[1], "default")
    32            x-default-4 = default(request.cookies.undef, request.query.q[1], "default", request.path)
    33            x-default-5 = "prefix-${default(request.cookies.undef, "default")}" # template expr
    34            x-default-6 = "${default(request.cookies.undef, "default")}" # template wrap expr
    35            x-default-7 = default(env.MY_UNSET_ENV, "default")
    36            x-default-8 = default(request.query.r, ["default-8"])[0]
    37            x-default-9 = default(request.cookies.undef, "")
    38            x-default-10 = default(request.cookies.undef, request.cookies.undef)
    39            x-default-11 = default(request.cookies.undef, 0)
    40            x-default-12 = default(request.cookies.undef, false)
    41            x-default-13 = json_encode(default({a = 1}, {}))
    42            x-default-14 = json_encode(default({a = 1}, {b = 2}))
    43            x-default-15 = json_encode(default([1, 2], []))
    44          }
    45        }
    46      }
    47  
    48      endpoint "/to_number" {
    49        response {
    50          json_body = {
    51  		  float-2_34 = to_number("2.34")
    52  		  float-_3 = to_number(".3")
    53  		  int = to_number("34")
    54  		  int-3_ = to_number("3.")
    55  		  int-3_0 = to_number("3.0")
    56  		  null = to_number(null)
    57  		  from-env = to_number(env.PI)
    58          }
    59        }
    60      }
    61  
    62      endpoint "/to_number/string" {
    63        response {
    64          json_body = {
    65  		  error = to_number("two")
    66          }
    67        }
    68      }
    69  
    70      endpoint "/to_number/bool" {
    71        response {
    72          json_body = {
    73  		  error = to_number(true)
    74          }
    75        }
    76      }
    77  
    78      endpoint "/to_number/tuple" {
    79        response {
    80          json_body = {
    81  		  error = to_number([1])
    82          }
    83        }
    84      }
    85  
    86      endpoint "/to_number/object" {
    87        response {
    88          json_body = {
    89  		  error = to_number({a = 1})
    90          }
    91        }
    92      }
    93  
    94      endpoint "/contains" {
    95        response {
    96          headers = {
    97            x-contains-1 = contains(["a", "b"], "a") ? "yes" : "no"
    98            x-contains-2 = contains(["a", "b"], "c") ? "yes" : "no"
    99            x-contains-3 = contains([0, 1], 0) ? "yes" : "no"
   100            x-contains-4 = contains([0, 1], 2) ? "yes" : "no"
   101            x-contains-5 = contains([0.1, 1.1], 0.1) ? "yes" : "no"
   102            x-contains-6 = contains([0.1, 1.1], 0.10000000001) ? "yes" : "no"
   103            x-contains-7 = contains([{a = 1, aa = {aaa = 1}}, {b = 2}], {a = 1, aa = {aaa = 1}}) ? "yes" : "no"
   104            x-contains-8 = contains([{a = 1}, {b = 2}], {c = 3}) ? "yes" : "no"
   105            x-contains-9 = contains([[1,2], [3,4]], [1,2]) ? "yes" : "no"
   106            x-contains-10 = contains([[1,2], [3,4]], [5,6]) ? "yes" : "no"
   107            x-contains-11 = contains(["3.14159", "42"], env.PI) ? "yes" : "no"
   108          }
   109        }
   110      }
   111  
   112      endpoint "/length" {
   113        response {
   114          headers = {
   115            x-length-1 = length([0, 1]) # tuple
   116            x-length-2 = length([])
   117            x-length-3 = length(split(",", "0,1,2,3,4")) # list
   118            x-length-4 = length(request.headers) # map
   119          }
   120        }
   121      }
   122  
   123      endpoint "/length/object" {
   124        response {
   125          headers = {
   126            error = length({a = 1})
   127          }
   128        }
   129      }
   130  
   131      endpoint "/length/string" {
   132        response {
   133          headers = {
   134            error = length("abcde")
   135          }
   136        }
   137      }
   138  
   139      endpoint "/length/null" {
   140        response {
   141          headers = {
   142            error = length(null)
   143          }
   144        }
   145      }
   146  
   147      endpoint "/join" {
   148        response {
   149          headers = {
   150            x-join-1 = join("-",[0, 1],["a","b"],[3,"c"],[1.234],[true,false])
   151            x-join-2 = "|${join("-",[])}|"
   152            x-join-3 = join("-", split(",", "0,1,2,3,4"))
   153          }
   154        }
   155      }
   156  
   157      endpoint "/keys" {
   158        response {
   159          headers = {
   160            x-keys-1 = json_encode(keys({a = 1, c = 2, b = {d = 3}}))
   161            x-keys-2 = json_encode(keys({}))
   162            x-keys-3 = json_encode(keys(request.headers))
   163          }
   164        }
   165      }
   166  
   167      endpoint "/set_intersection" {
   168        response {
   169          headers = {
   170            x-set_intersection-1 = json_encode((set_intersection([1,3])))
   171            x-set_intersection-2 = json_encode(set_intersection([0,1,2,3], [1,3]))
   172            x-set_intersection-3 = json_encode(set_intersection([1,3],[0,1,2,3]))
   173            x-set_intersection-4 = json_encode(set_intersection([1,3],[1,3]))
   174            x-set_intersection-5 = json_encode(set_intersection([0,1,2,3], [1,3], [3,5]))
   175            x-set_intersection-6 = json_encode(set_intersection([0,1,2,3], [3,4,5]))
   176            x-set_intersection-7 = json_encode(set_intersection([0,1,2,3],[4,5]))
   177            x-set_intersection-8 = json_encode(set_intersection([0,1,2,3],[]))
   178            x-set_intersection-9 = json_encode(set_intersection([],[1,3]))
   179            x-set_intersection-10 = json_encode(set_intersection([0,1,2,3], [1,4], [3,5]))
   180            x-set_intersection-11 = json_encode(set_intersection([1.1,2.2,3.3], [2.2,4.4]))
   181            x-set_intersection-12 = json_encode(set_intersection(["a","b","c","d"], ["b","d","e"]))
   182            x-set_intersection-13 = json_encode(set_intersection([true,false], [true]))
   183            x-set_intersection-14 = json_encode(set_intersection([{a=1},{b=2}], [{a=1},{c=3}]))
   184            x-set_intersection-15 = json_encode(set_intersection([[1,2],[3,4]], [[1,2],[5,6]]))
   185          }
   186        }
   187      }
   188  
   189      endpoint "/lookup" {
   190        response {
   191          headers = {
   192            x-lookup-1 = lookup({a = "1"}, "a", "default")
   193            x-lookup-2 = lookup({a = "1"}, "b", "default")
   194            x-lookup-3 = lookup(request.headers, "user-agent", "default")
   195            x-lookup-4 = lookup(request.headers, "content-type", "default")
   196          }
   197        }
   198      }
   199  
   200      endpoint "/lookup/inputMap-null" {
   201        response {
   202          headers = {
   203            error = lookup(null, "a", "default")
   204          }
   205        }
   206      }
   207  
   208      endpoint "/trim" {
   209        response {
   210          headers = {
   211            x-trim = trim(" \tfoo \tbar \t")
   212          }
   213        }
   214      }
   215    }
   216  }
   217  
   218  defaults {
   219    environment_variables = {
   220      PI = "3.14159"
   221    }
   222  }