Skip to content

Commit 5214635

Browse files
Merge pull request #299597 from mumian/0509-uri-functions
Add new URI functions
2 parents b26f041 + aac00a2 commit 5214635

File tree

2 files changed

+145
-1
lines changed

2 files changed

+145
-1
lines changed

articles/azure-resource-manager/bicep/bicep-functions-string.md

Lines changed: 143 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: Bicep functions - string
33
description: Describes the functions to use in a Bicep file to work with strings.
44
ms.topic: reference
55
ms.custom: devx-track-bicep
6-
ms.date: 02/14/2025
6+
ms.date: 06/19/2025
77
---
88

99
# String functions for Bicep
@@ -139,6 +139,74 @@ The output from the preceding example with the default values is:
139139
| toStringOutput | String | one, two, three |
140140
| toJsonOutput | Object | {"one": "a", "two": "b"} |
141141

142+
## buildUri
143+
144+
`buildUri(uriComponent)`
145+
146+
Constructs a URI by combining the provided scheme, host, port, path, and query component object into a single URI string. To parse a URI, see [parseUri](#parseuri).
147+
148+
Namespace: [sys](bicep-functions.md#namespaces-for-functions).
149+
150+
### Parameters
151+
152+
| Parameter | Required | Type | Description |
153+
|:--- |:--- |:--- |:--- |
154+
| scheme | Yes | String | The protocol of the URI (e.g., `http`, `https`, `ftp`). |
155+
| host | Yes | String | The domain or hostname (e.g., `example.com`). |
156+
| port | No | Int or Null | The port number (e.g., `443`). If not specified, defaults to `null`, which means the default port for the scheme is used. |
157+
| path | Yes | String | The path component (e.g., `/path/to/resource`). |
158+
| query | No | String | The query string, including the leading `?` if present (e.g., `?key=value`). Defaults to an empty string if not provided. |
159+
160+
### Return Value
161+
162+
A string representing the absolute URI constructed from the provided components.
163+
164+
### Examples
165+
166+
The following example shows how to use `buildUri` to construct a URI from individual components:
167+
168+
```bicep
169+
param uriComponents object = {
170+
scheme: 'https'
171+
host: 'mystorage.blob.core.windows.net'
172+
port: 8080
173+
path: '/templates/nestedTemplate.json'
174+
query: '?st=2025-05-09'
175+
}
176+
177+
output constructedUri string = buildUri((uriComponents))
178+
```
179+
180+
The output from the preceding example is:
181+
182+
| Name | Type | Value |
183+
| ---- | ---- | ----- |
184+
| constructedUri | String | `https://mystorage.blob.core.windows.net:8080/templates/nestedTemplate.json?st=2025-05-09` |
185+
186+
The following example shows how to use `parseUri` to extract components from an existing URI, modify them, and then use `buildUri` to reconstruct a new URI:
187+
188+
```bicep
189+
param uriComponents object = parseUri('https://mystorage.blob.core.windows.net:8080/templates/nestedTemplate.json?st=2025-05-09')
190+
param newQuery string = 'st-2025-06-19'
191+
192+
var updatedUriComponents object = {
193+
scheme: uriComponents.schema
194+
host: uriComponents.host
195+
port: uriComponents.port
196+
path: uriComponents.path
197+
query: newQuery
198+
}
199+
200+
// Reconstruct the URI using buildUri
201+
output reconstructedUri string = buildUri(updatedUriComponents)
202+
```
203+
204+
The output from the preceding example is:
205+
206+
| Name | Type | Value |
207+
| ---- | ---- | ----- |
208+
| reconstrcutedUri | String | `https://mystorage.blob.core.windows.net/newdata/newfile.json?newParam=value` |
209+
142210
## concat
143211

144212
`concat(arg1, arg2, arg3, ...)`
@@ -894,6 +962,80 @@ The output from the preceding example with the default values is:
894962
| ---- | ---- | ----- |
895963
| stringOutput | String | 0000000123 |
896964

965+
## parseUri
966+
967+
`parseUri(uriString)`
968+
969+
Parses a URI string into its constituent components, such as scheme, host, port, path, and query. To build a URI string, see [buildUri](#builduri).
970+
971+
Namespace: [sys](bicep-functions.md#namespaces-for-functions).
972+
973+
### Parameters
974+
975+
| Parameter | Required | Type | Description |
976+
|:--- |:--- |:--- |:--- |
977+
| uriString | Yes | string | The URI string to parse. Must be a valid URI as per RFC 3986. |
978+
979+
### Return Value
980+
981+
An object containing the parsed URI components with the following properties:
982+
983+
| Property | Type | Description |
984+
|:--- |:--- |:--- |
985+
| scheme | String | The protocol of the URI (e.g., `http`, `https`, `ftp`). |
986+
| host | String | The domain or hostname (e.g., `example.com`). |
987+
| port | Int or null | The port number (e.g., `443`), or `null` if not specified. |
988+
| path | String | The path component (e.g., `/path/to/resource`). |
989+
| query | String | The query string, including the leading `?` (e.g., `?key=value`), or empty string if not present. |
990+
991+
For complete details, the URI is parsed as specified in [RFC 3986, section 3](https://tools.ietf.org/html/rfc3986#section-3).
992+
993+
### Examples
994+
995+
The following example shows how to use `parseUri` to extract components from a URI:
996+
997+
```bicep
998+
param inputUri string = 'https://mystorage.blob.core.windows.net:8080/templates/nestedTemplate.json?st=2025-05-09'
999+
1000+
var parsedUri = parseUri(inputUri)
1001+
1002+
output scheme string = parsedUri.scheme
1003+
output host string = parsedUri.host
1004+
output port int = parsedUri.port
1005+
output path string = parsedUri.path
1006+
output query string = parsedUri.query
1007+
```
1008+
1009+
The output from the preceding example with the default values is:
1010+
1011+
| Name | Type | Value |
1012+
| ---- | ---- | ----- |
1013+
| scheme | String | `https` |
1014+
| host | String | `mystorage.blob.core.windows.net` |
1015+
| port | Int | `8080` |
1016+
| path | String | `/templates/nestedTemplate.json` |
1017+
| query | String | `?st=2025-05-09` |
1018+
1019+
The following example shows how to use `parseUri` to extract the host and scheme, then reconstruct a new URI with a different path using the `uri` function:
1020+
1021+
```bicep
1022+
param originalUri string = 'https://mystorage.blob.core.windows.net/data/file.json?st=2025-05-09'
1023+
1024+
var parsedUri = parseUri(originalUri)
1025+
var newPath = '/newdata/newfile.json'
1026+
var modifiedUri = uri('${parsedUri.scheme}://${parsedUri.host}', newPath)
1027+
1028+
output originalHost string = parsedUri.host
1029+
output newUri string = modifiedUri
1030+
```
1031+
1032+
The output from the preceding example is:
1033+
1034+
| Name | Type | Value |
1035+
| ---- | ---- | ----- |
1036+
| originalHost | String | `mystorage.blob.core.windows.net` |
1037+
| newUri | String | `https://mystorage.blob.core.windows.net/newdata/newfile.json` |
1038+
8971039
## replace
8981040

8991041
`replace(originalString, oldString, newString)`

articles/azure-resource-manager/bicep/bicep-functions.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ Bicep provides the following functions for working with strings. All of these fu
180180
* [base64](./bicep-functions-string.md#base64)
181181
* [base64ToJson](./bicep-functions-string.md#base64tojson)
182182
* [base64ToString](./bicep-functions-string.md#base64tostring)
183+
* [buildUri](./bicep-functions-string.md#builduri)
183184
* [concat](./bicep-functions-string.md#concat)
184185
* [contains](./bicep-functions-string.md#contains)
185186
* [dataUri](./bicep-functions-string.md#datauri)
@@ -196,6 +197,7 @@ Bicep provides the following functions for working with strings. All of these fu
196197
* [length](./bicep-functions-string.md#length)
197198
* [newGuid](./bicep-functions-string.md#newguid)
198199
* [padLeft](./bicep-functions-string.md#padleft)
200+
* [parseUri](./bicep-functions-string.md#parseuri)
199201
* [replace](./bicep-functions-string.md#replace)
200202
* [skip](./bicep-functions-string.md#skip)
201203
* [split](./bicep-functions-string.md#split)

0 commit comments

Comments
 (0)