Skip to content

Commit dfdfb81

Browse files
committed
Fix json samples to escape {{ blocks }}
1 parent d34df37 commit dfdfb81

12 files changed

+27
-0
lines changed

http/access-http-request-headers.md

+2
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@ node to access the headers.
1616

1717
![](/images/http/http-flow-004.png)
1818

19+
{% raw %}
1920
~~~json
2021
[{"id":"c1460268.3eba","type":"http in","z":"3045204d.cfbae","name":"","url":"/hello-headers","method":"get","swaggerDoc":"","x":130,"y":380,"wires":[["24199456.dbe66c"]]},{"id":"24199456.dbe66c","type":"template","z":"3045204d.cfbae","name":"page","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"<html>\n <head></head>\n <body>\n <h1>User agent: {{req.headers.user-agent}}</h1>\n </body>\n</html>","x":310,"y":380,"wires":[["b3531892.4cace8"]]},{"id":"b3531892.4cace8","type":"http response","z":"3045204d.cfbae","name":"","x":450,"y":380,"wires":[]}]
2122
~~~
2223
{: .flow}
24+
{% endraw %}
2325

2426
~~~text
2527
[~]$ curl http://localhost:1880/hello-headers

http/create-an-http-endpoint.md

+2
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@ Use the <code class="node">HTTP In</code> node to listen for requests, a
1818

1919
![](/images/http/http-flow-001.png)
2020

21+
{% raw %}
2122
~~~json
2223
[{"id":"59ff2a1.fa600d4","type":"http in","z":"3045204d.cfbae","name":"","url":"/hello","method":"get","swaggerDoc":"","x":100,"y":80,"wires":[["54c1e70d.ab3e18"]]},{"id":"54c1e70d.ab3e18","type":"template","z":"3045204d.cfbae","name":"page","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"<html>\n <head></head>\n <body>\n <h1>Hello World!</h1>\n </body>\n</html>","x":250,"y":80,"wires":[["266c286f.d993d8"]]},{"id":"266c286f.d993d8","type":"http response","z":"3045204d.cfbae","name":"","x":390,"y":80,"wires":[]}]
2324
~~~
2425
{: .flow}
26+
{% endraw %}
2527

2628
~~~text
2729
[~]$ curl http://localhost:1880/hello

http/handle-query-parameters.md

+2
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@ node to access the parameters.
1818

1919
![](/images/http/http-flow-002.png)
2020

21+
{% raw %}
2122
~~~json
2223
[{"id":"b34dd1af.4cb23","type":"template","z":"3045204d.cfbae","name":"page","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"<html>\n <head></head>\n <body>\n <h1>Hello {{req.query.name}}!</h1>\n </body>\n</html>","x":290,"y":180,"wires":[["b828f6a6.47d708"]]},{"id":"1052941d.efad6c","type":"http in","z":"3045204d.cfbae","name":"","url":"/hello-query","method":"get","swaggerDoc":"","x":120,"y":180,"wires":[["b34dd1af.4cb23"]]},{"id":"b828f6a6.47d708","type":"http response","z":"3045204d.cfbae","name":"","x":430,"y":180,"wires":[]}]
2324
~~~
2425
{: .flow}
26+
{% endraw %}
2527

2628
~~~text
2729
[~]$ curl http://localhost:1880/hello-query?name=Nick

http/handle-url-parameters.md

+2
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,12 @@ property and then access the specific value provided in a request using the
2424

2525
![](/images/http/http-flow-003.png)
2626

27+
{% raw %}
2728
~~~json
2829
[{"id":"ce53954b.31ac68","type":"http response","z":"3045204d.cfbae","name":"","x":490,"y":280,"wires":[]},{"id":"288a7c0.fd77584","type":"template","z":"3045204d.cfbae","name":"page","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"<html>\n <head></head>\n <body>\n <h1>Hello {{req.params.name}}!</h1>\n </body>\n</html>","x":350,"y":280,"wires":[["ce53954b.31ac68"]]},{"id":"7665c67d.899a38","type":"http in","z":"3045204d.cfbae","name":"","url":"/hello-param/:name","method":"get","swaggerDoc":"","x":150,"y":280,"wires":[["288a7c0.fd77584"]]}]
2930
~~~
3031
{: .flow}
32+
{% endraw %}
3133

3234
#### Example
3335
~~~text

http/include-data-from-another-flow.md

+2
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@ Store data using `flow context` so that it can be retrieved within the HTTP flow
1515

1616
![](/images/http/http-flow-005.png)
1717

18+
{% raw %}
1819
~~~json
1920
[{"id":"92eaf6c0.6d1508","type":"inject","z":"3045204d.cfbae","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":100,"y":480,"wires":[["8055b557.7faa48"]]},{"id":"8055b557.7faa48","type":"change","z":"3045204d.cfbae","name":"Store time","rules":[{"t":"set","p":"timestamp","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":270,"y":480,"wires":[[]]},{"id":"93bf2335.6c40e","type":"http in","z":"3045204d.cfbae","name":"","url":"/hello-data","method":"get","swaggerDoc":"","x":120,"y":520,"wires":[["9e3aa25e.61c56"]]},{"id":"9e3aa25e.61c56","type":"change","z":"3045204d.cfbae","name":"Copy time","rules":[{"t":"set","p":"timestamp","pt":"msg","to":"timestamp","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":310,"y":520,"wires":[["f2c385a.f0d3c78"]]},{"id":"f2c385a.f0d3c78","type":"template","z":"3045204d.cfbae","name":"page","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"<html>\n <head></head>\n <body>\n <h1>Time: {{ timestamp }}</h1>\n </body>\n</html>","x":470,"y":520,"wires":[["def756a1.2108a8"]]},{"id":"def756a1.2108a8","type":"http response","z":"3045204d.cfbae","name":"","x":610,"y":520,"wires":[]}]
2021
~~~
2122
{: .flow}
23+
{% endraw %}
2224

2325
~~~text
2426
[~]$ curl http://localhost:1880/hello-data

http/post-form-data-to-a-flow.md

+2
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@ the form data as properties of `msg.payload`.
1717

1818
![](/images/http/http-flow-008.png)
1919

20+
{% raw %}
2021
~~~json
2122
[{"id":"5b98a8ac.a46758","type":"http in","z":"3045204d.cfbae","name":"","url":"/hello-form","method":"post","swaggerDoc":"","x":120,"y":820,"wires":[["bba61009.4459f"]]},{"id":"bba61009.4459f","type":"template","z":"3045204d.cfbae","name":"page","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"<html>\n <head></head>\n <body>\n <h1>Hello {{ payload.name }}!</h1>\n </body>\n</html>","x":290,"y":820,"wires":[["6ceb930a.93146c"]]},{"id":"6ceb930a.93146c","type":"http response","z":"3045204d.cfbae","name":"","x":430,"y":820,"wires":[]}]
2223
~~~
2324
{: .flow}
25+
{% endraw %}
2426

2527
~~~text
2628
[~]$ curl -X POST -d "name=Nick" http://localhost:1880/hello-form

http/post-json-data-to-a-flow.md

+2
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@ properties of `msg.payload`.
1717

1818
![](/images/http/http-flow-008.png)
1919

20+
{% raw %}
2021
~~~json
2122
[{"id":"5b98a8ac.a46758","type":"http in","z":"3045204d.cfbae","name":"","url":"/hello-form","method":"post","swaggerDoc":"","x":120,"y":820,"wires":[["bba61009.4459f"]]},{"id":"bba61009.4459f","type":"template","z":"3045204d.cfbae","name":"page","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"<html>\n <head></head>\n <body>\n <h1>Hello {{ payload.name }}!</h1>\n </body>\n</html>","x":290,"y":820,"wires":[["6ceb930a.93146c"]]},{"id":"6ceb930a.93146c","type":"http response","z":"3045204d.cfbae","name":"","x":430,"y":820,"wires":[]}]
2223
~~~
2324
{: .flow}
25+
{% endraw %}
2426

2527
~~~text
2628
[~]$ curl -X POST -d '{"name":"Nick"}' -H "Content-type: application/json" http://localhost:1880/hello-form

http/post-raw-data-to-a-flow.md

+2
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@ have their `Content-Type` set to `text/plain` and access the posted data as `msg
1616

1717
![](/images/http/http-flow-009.png)
1818

19+
{% raw %}
1920
~~~json
2021
[{"id":"3e1c5107.c1e3ae","type":"http in","z":"3045204d.cfbae","name":"","url":"/hello-raw","method":"post","swaggerDoc":"","x":120,"y":920,"wires":[["cf679478.309868"]]},{"id":"cf679478.309868","type":"template","z":"3045204d.cfbae","name":"page","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"<html>\n <head></head>\n <body>\n <h1>Hello {{ payload }}!</h1>\n </body>\n</html>","x":290,"y":920,"wires":[["f3c1a3f0.0c3e6"]]},{"id":"f3c1a3f0.0c3e6","type":"http response","z":"3045204d.cfbae","name":"","x":430,"y":920,"wires":[]}]
2122
~~~
2223
{: .flow}
24+
{% endraw %}
2325

2426
~~~text
2527
[~]$ curl -X POST -d 'Nick' -H "Content-type: text/plain" http://localhost:1880/hello-raw

http/serve-a-local-file.md

+2
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@ set the `Content-Type` to the appropriate value for the file type being returned
1717

1818
![](/images/http/http-flow-007.png)
1919

20+
{% raw %}
2021
~~~json
2122
[{"id":"c7e341a0.381cc","type":"http in","z":"3045204d.cfbae","name":"","url":"/hello-file","method":"get","swaggerDoc":"","x":110,"y":720,"wires":[["2fb1c354.d04e3c"]]},{"id":"2fb1c354.d04e3c","type":"file in","z":"3045204d.cfbae","name":"","filename":"/tmp/node-red.png","format":"","x":290,"y":720,"wires":[["c9e28681.361d78"]]},{"id":"c9e28681.361d78","type":"change","z":"3045204d.cfbae","name":"Set Headers","rules":[{"t":"set","p":"headers","pt":"msg","to":"{}","tot":"json"},{"t":"set","p":"headers.content-type","pt":"msg","to":"image/png","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":470,"y":720,"wires":[["88974243.7768c"]]},{"id":"88974243.7768c","type":"http response","z":"3045204d.cfbae","name":"","x":610,"y":720,"wires":[]}]
2223
~~~
2324
{: .flow}
25+
{% endraw %}
2426

2527
~~~text
2628
[~]$ curl http://localhost:1880/hello-file > file.png

http/serve-json-content.md

+2
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@ object.
1616

1717
![](/images/http/http-flow-006.png)
1818

19+
{% raw %}
1920
~~~json
2021
[{"id":"c8107088.37ef9","type":"http in","z":"3045204d.cfbae","name":"","url":"/hello-json","method":"get","swaggerDoc":"","x":120,"y":620,"wires":[["4e8237da.b17dc8"]]},{"id":"4e8237da.b17dc8","type":"template","z":"3045204d.cfbae","name":"page","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{ \"Hello\": \"World\" }","x":290,"y":620,"wires":[["65401623.9abfe8"]]},{"id":"65401623.9abfe8","type":"change","z":"3045204d.cfbae","name":"Set Headers","rules":[{"t":"set","p":"headers","pt":"msg","to":"{}","tot":"json"},{"t":"set","p":"headers.content-type","pt":"msg","to":"application/json","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":450,"y":620,"wires":[["f7d3e35a.082c2"]]},{"id":"f7d3e35a.082c2","type":"http response","z":"3045204d.cfbae","name":"","x":610,"y":620,"wires":[]}]
2122
~~~
2223
{: .flow}
24+
{% endraw %}
2325

2426
~~~text
2527
[~]$ curl -i http://localhost:1880/hello-json

http/work-with-cookies.md

+2
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,12 @@ in order to set or clear cookies.
1919

2020
![](/images/http/http-flow-010.png)
2121

22+
{% raw %}
2223
~~~json
2324
[{"id":"c362b989.954ae8","type":"http in","z":"3045204d.cfbae","name":"","url":"/hello-cookie","method":"get","swaggerDoc":"","x":130,"y":1020,"wires":[["21ddf71f.d00518"]]},{"id":"21ddf71f.d00518","type":"function","z":"3045204d.cfbae","name":"Format cookies","func":"msg.payload = JSON.stringify(msg.req.cookies,null,4);\nreturn msg;","outputs":1,"noerr":0,"x":340,"y":1020,"wires":[["f3aa98c1.befc18"]]},{"id":"f3aa98c1.befc18","type":"template","z":"3045204d.cfbae","name":"page","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"<html>\n <head></head>\n <body>\n <h1>Cookies</h1>\n <p></p><a href=\"hello-cookie/add\">Add a cookie</a> &bull; <a href=\"hello-cookie/clear\">Clear cookies</a></p>\n <pre>{{ payload }}</pre>\n </body>\n</html>","x":530,"y":1020,"wires":[["f52e2880.180968"]]},{"id":"f52e2880.180968","type":"http response","z":"3045204d.cfbae","name":"","x":750,"y":1020,"wires":[]},{"id":"9a2a9a4.0fc0768","type":"change","z":"3045204d.cfbae","name":"Redirect to /hello-cookie","rules":[{"t":"set","p":"statusCode","pt":"msg","to":"302","tot":"num"},{"t":"set","p":"headers","pt":"msg","to":"{}","tot":"json"},{"t":"set","p":"headers.location","pt":"msg","to":"/hello-cookie","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":550,"y":1080,"wires":[["f52e2880.180968"]]},{"id":"afefb90.53dcf48","type":"function","z":"3045204d.cfbae","name":"Add a cookie","func":"msg.cookies = { };\nmsg.cookies[\"demo-\"+(Math.floor(Math.random()*1000))] = Date.now();\nreturn msg;","outputs":1,"noerr":0,"x":330,"y":1060,"wires":[["9a2a9a4.0fc0768"]]},{"id":"d5205a2c.db9018","type":"function","z":"3045204d.cfbae","name":"Clear cookies","func":"// Find demo cookies and clear them\nvar cookieNames = Object.keys(msg.req.cookies).filter(function(cookieName) { return /^demo-/.test(cookieName);});\nmsg.cookies = {};\n\ncookieNames.forEach(function(cookieName) {\n msg.cookies[cookieName] = null;\n});\n\nreturn msg;","outputs":1,"noerr":0,"x":340,"y":1100,"wires":[["9a2a9a4.0fc0768"]]},{"id":"fda60c66.04975","type":"http in","z":"3045204d.cfbae","name":"","url":"/hello-cookie/add","method":"get","swaggerDoc":"","x":140,"y":1060,"wires":[["afefb90.53dcf48"]]},{"id":"35285a76.1f8636","type":"http in","z":"3045204d.cfbae","name":"","url":"/hello-cookie/clear","method":"get","swaggerDoc":"","x":140,"y":1100,"wires":[["d5205a2c.db9018"]]}]
2425
~~~
2526
{: .flow}
27+
{% endraw %}
2628

2729
This example provides three HTTP endpoints:
2830

styleguide.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
---
22
layout: default
33
title: Cookbook Style Guide
4+
lcb: "{"
45
---
56

67
The cookbook recipes are intended to be task-focused guides to solving specific
@@ -29,10 +30,12 @@ Use the <code class="node">Inject</code> node to do X.
2930
![](/images/flow-image.png)
3031

3132
> Paste a sample flow json that can be imported by the reader
33+
{{ page.lcb }}% raw %}
3234
~~~json
3335
[{"id":"7c87b536.83784c","type":"inject","z":"55635136.aa9cb","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":100,"y":80,"wires":[["7de918a6.8216e8"]]}]
3436
~~~
3537
{: .flow}
38+
{{ page.lcb }}% endraw %}
3639

3740
> If the recipe can be meaningfully demonstrated in action via static text, add it here.
3841

@@ -65,10 +68,12 @@ Use the <code class="node">HTTP In</code> node to ...
6568
#### Example flows
6669

6770
~~~~~markdown
71+
{{ page.lcb }}% raw %}
6872
~~~json
6973
> insert flow json here. It should be minified and on a single line.
7074
~~~
7175
{: .flow}
76+
{{ page.lcb }}% endraw %}
7277
~~~~~
7378

7479
#### Terminal output

0 commit comments

Comments
 (0)