Skip to content

Commit c366488

Browse files
committed
document Bicep CLI jsonrpc
1 parent 45e6232 commit c366488

File tree

1 file changed

+100
-7
lines changed

1 file changed

+100
-7
lines changed

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

Lines changed: 100 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: Bicep CLI commands and overview
33
description: Describes the commands that you can use in the Bicep CLI. These commands include building Azure Resource Manager templates from Bicep.
44
ms.topic: reference
55
ms.custom: devx-track-azurecli, devx-track-bicep, devx-track-arm-template
6-
ms.date: 10/23/2024
6+
ms.date: 10/30/2024
77
---
88

99
# Bicep CLI commands
@@ -140,6 +140,99 @@ To install a specific version:
140140
az bicep install --version v0.3.255
141141
```
142142

143+
## jsonrpc
144+
145+
The `jsonrpc` command enables running the Bicep CLI with a JSON-RPC interface, allowing for programmatic interaction with structured output and avoiding cold-start delays when compiling multiple files. This setup also supports building libraries to interact with Bicep files programmatically in non-.NET languages.
146+
147+
The wire format for sending and receiving input/output is header-delimited, using the following structure, where `\r` and `\n` represent carriage return and line feed characters:
148+
149+
```
150+
Content-Length: <length>\r\n\r\n<message>\r\n\r\n
151+
```
152+
153+
* `<length>` is the length of the `<message>` string, including the trailing `\r\n\r\n`.
154+
* `<message>` is the raw JSON message.
155+
156+
For example:
157+
158+
```
159+
Content-Length: 72\r\n\r\n{"jsonrpc": "2.0", "id": 0, "method": "bicep/version", "params": {}}\r\n\r\n
160+
```
161+
162+
The following message shows an example for Bicep version.
163+
164+
* The input:
165+
166+
```json
167+
{
168+
"jsonrpc": "2.0",
169+
"id": 0,
170+
"method": "bicep/version",
171+
"params": {}
172+
}
173+
```
174+
175+
* The output:
176+
177+
```json
178+
{
179+
"jsonrpc": "2.0",
180+
"id": 0,
181+
"result": {
182+
"version": "0.24.211"
183+
}
184+
}
185+
```
186+
187+
For the available methods & request/response bodies, see [`ICliJsonRpcProtocol.cs`](../../src/Bicep.Cli/Rpc/ICliJsonRpcProtocol.cs).
188+
For an example establinging a JSONRPC connection and interacting with Bicep files programmatically using Node, see [`jsonrpc.test.ts`](../../src/Bicep.Cli.E2eTests/src/jsonrpc.test.ts).
189+
190+
### Usage for named pipe
191+
192+
Use the following syntax to connect to an existing named pipe as a JSONRPC client.
193+
194+
```bicep cli
195+
bicep jsonrpc --pipe <named_pipe>`
196+
```
197+
198+
`<named_pipe>` is an existing named pipe to connect the JSONRPC client to.
199+
200+
To connect to a named pipe (OSX/Linux) :
201+
202+
```bicep cli
203+
bicep jsonrpc --pipe /tmp/bicep-81375a8084b474fa2eaedda1702a7aa40e2eaa24b3.sock
204+
```
205+
206+
To connect to a named pipe (Windows) :
207+
208+
```bicep cli
209+
bicep jsonrpc --pipe \\.\pipe\\bicep-81375a8084b474fa2eaedda1702a7aa40e2eaa24b3.sock`
210+
```
211+
212+
For more examples, see [C#](https://github.com/Azure/bicep/blob/096c32f9d5c42bfb85dff550f72f3fe16f8142c7/src/Bicep.Cli.IntegrationTests/JsonRpcCommandTests.cs#L24-L50) and [node.js](https://github.com/anthony-c-martin/bicep-node/blob/4769e402f2d2c1da8d27df86cb3d62677e7a7456/src/utils/jsonrpc.ts#L117-L151).
213+
214+
### Usage for TCP socket
215+
216+
Use the following syntax to connect to an existing TCP socket as a JSONRPC client.
217+
218+
```bicep cli
219+
bicep jsonrpc --socket <tcp_socket>
220+
```
221+
222+
`<tcp_socket>` is a a socket number to connect the JSONRPC client to.
223+
224+
To connect to a TCP socket
225+
226+
`bicep jsonrpc --socket 12345`
227+
228+
### Usage for stdin and stdout
229+
230+
Use the following syntax to run the JSONRPC interface using stdin & stdout for messages.
231+
232+
```bicep cli
233+
bicep jsonrpc --stdio
234+
```
235+
143236
## lint
144237

145238
The `lint` command returns the errors and the [linter rule](./linter.md) violations of a Bicep file.
@@ -264,19 +357,19 @@ module stgModule 'br:exampleregistry.azurecr.io/bicep/modules/storage:v1' = {
264357

265358
The local cache is found in:
266359

267-
- On Windows
360+
* On Windows
268361

269362
```path
270363
%USERPROFILE%\.bicep\br\<registry-name>.azurecr.io\<module-path\<tag>
271364
```
272365
273-
- On Linux
366+
* On Linux
274367
275368
```path
276369
/home/<username>/.bicep
277370
```
278371
279-
- On Mac
372+
* On Mac
280373
281374
```path
282375
~/.bicep
@@ -318,6 +411,6 @@ If the Bicep CLI hasn't been installed, you'll encounter an error message statin
318411

319412
To learn about deploying a Bicep file, see:
320413

321-
- [Azure CLI](deploy-cli.md)
322-
- [Cloud Shell](deploy-cloud-shell.md)
323-
- [PowerShell](deploy-powershell.md)
414+
* [Azure CLI](deploy-cli.md)
415+
* [Cloud Shell](deploy-cloud-shell.md)
416+
* [PowerShell](deploy-powershell.md)

0 commit comments

Comments
 (0)