github.com/avenga/couper@v1.12.2/docs/website/content/2.configuration/6.functions.md (about) 1 --- 2 title: 'Functions' 3 description: 'Overview of usable function expressions' 4 indexTable: true 5 --- 6 7 # Functions 8 9 This functions can be used and combined as standalone call with all kind of hcl expressions. But some of them requires a `definitions` reference. 10 11 | Name | Type | Description | Arguments | Example | 12 |:---------------------------|:----------------|:--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|:----------------------------------------------------------------|:----------------------------------------------------------------------------------------------------| 13 | `base64_decode` | string | Decodes Base64 data, as specified in RFC 4648. | `encoded` (string) | `base64_decode("Zm9v")` | 14 | `base64_encode` | string | Encodes Base64 data, as specified in RFC 4648. | `decoded` (string) | `base64_encode("foo")` | 15 | `contains` | bool | Determines whether a given list contains a given single value as one of its elements. | `list` (tuple or list), `value` (various) | `contains([1,2,3], 2)` | 16 | `default` | string | Returns the first of the given arguments that is not null or an empty string. If no argument matches, the last argument is returned. | `arg...` (various) | `default(request.cookies.foo, "bar")` | 17 | `join` | string | Concatenates together the string elements of one or more lists with a given separator. | `sep` (string), `lists...` (tuples or lists) | `join("-", [0,1,2,3])` | 18 | `json_decode` | various | Parses the given JSON string and, if it is valid, returns the value it represents. | `encoded` (string) | `json_decode("{\"foo\": 1}")` | 19 | `json_encode` | string | Returns a JSON serialization of the given value. | `val` (various) | `json_encode(request.context.myJWT)` | 20 | `jwt_sign` | string | Creates and signs a JSON Web Token (JWT) from information from a referenced [JWT Signing Profile Block](/configuration/block/jwt_signing_profile) (or [JWT Block](/configuration/block/jwt) with `signing_ttl`) and additional claims provided as a function parameter. | `label` (string), `claims` (object) | `jwt_sign("myJWT")` | 21 | `keys` | list | Takes a map and returns a sorted list of the map keys. | `inputMap` (object or map) | `keys(request.headers)` | 22 | `length` | integer | Returns the number of elements in the given collection. | `collection` (tuple, list or map; **no object**) | `length([0,1,2,3])` | 23 | `lookup` | various | Performs a dynamic lookup into a map. The default (third argument) is returned if the key (second argument) is not found in the inputMap (first argument). | `inputMap` (object or map), `key` (string), `default` (various) | `lookup({a = 1}, "b", "def")` | 24 | `merge` | object or tuple | Deep-merges two or more of either objects or tuples. `null` arguments are ignored. An attribute value with a different type than the current value is set as the new value. `merge()` with no parameters returns `null`. | `arg...` (object or tuple) | `merge(request.headers, { x-additional = "myval" })` | 25 | `oauth2_authorization_url` | string | Creates an OAuth2 authorization URL from a referenced [OAuth2 AC (Beta) Block](/configuration/block/beta_oauth2) or [OIDC Block](/configuration/block/oidc). | `label` (string) | `oauth2_authorization_url("myOAuth2")` | 26 | `oauth2_verifier` | string | Creates a cryptographically random key as specified in RFC 7636, applicable for all verifier methods; e.g. to be set as a cookie and read into `verifier_value`. Multiple calls of this function in the same client request context return the same value. | | `oauth2_verifier()` | 27 | `relative_url` | string | Returns a relative URL by retaining `path`, `query` and `fragment` components. The input URL `s` must begin with `/<path>`, `//<authority>`, `http://` or `https://`, otherwise an error is thrown. | s (string) | `relative_url("https://httpbin.org/anything?query#fragment") // returns "/anything?query#fragment"` | 28 | `saml_sso_url` | string | Creates a SAML SingleSignOn URL (including the `SAMLRequest` parameter) from a referenced [SAML Block](/configuration/block/saml). | `label` (string) | `saml_sso_url("mySAML")` | 29 | `set_intersection` | list or tuple | Returns a new set containing the elements that exist in all of the given sets. | `sets...` (tuple or list) | `set_intersection(["A", "B", "C"], ["B", D"])` | 30 | `split` | tuple | Divides a given string by a given separator, returning a list of strings containing the characters between the separator sequences. | `sep` (string), `str` (string) | `split(" ", "foo bar qux")` | 31 | `substr` | string | Extracts a sequence of characters from another string and creates a new string. The "`offset`" index may be negative, in which case it is relative to the end of the given string. The "`length`" may be `-1`, in which case the remainder of the string after the given offset will be returned. | `str` (string), `offset` (integer), `length` (integer) | `substr("abcdef", 3, -1)` | 32 | `to_lower` | string | Converts a given string to lowercase. | `s` (string) | `to_lower(request.cookies.name)` | 33 | `to_number` | number | Converts its argument to a number value. Only numbers, `null`, and strings containing decimal representations of numbers can be converted to number. All other values will produce an error. | `num` (string or number) | `to_number("1,23")`, `to_number(env.PI)` | 34 | `to_upper` | string | Converts a given string to uppercase. | `s` (string) | `to_upper("CamelCase")` | 35 | `trim` | string | Removes any whitespace characters from the start and end of the given string. | `str` (string) | `trim(" foo ")` | 36 | `unixtime` | integer | Retrieves the current UNIX timestamp in seconds. | | `unixtime()` | 37 | `url_encode` | string | URL-encodes a given string according to RFC 3986. | `s` (string) | `url_encode("abc%&,123")` |