1 |
|
2 | API
|
3 | ===
|
4 |
|
5 | Instead of/in addition to using Shunter as a proxy you can also send JSON in the body of an HTTP POST request to the `/template` endpoint and get back a response containing the rendered HTML.
|
6 |
|
7 | If our app had a template `hello.dust` containing:
|
8 |
|
9 | ```html
|
10 | <h1>{data.message}</h1>
|
11 | ```
|
12 |
|
13 | Then a POST request like this:
|
14 |
|
15 | ```
|
16 | curl -H 'Content-type: application/json' -X POST -d '{"data": {"message": "Hello!"}}' http://your-shunter-server/template/hello
|
17 | ```
|
18 |
|
19 | would return:
|
20 |
|
21 | ```html
|
22 | <h1>Hello!</h1>
|
23 | ```
|
24 |
|
25 | The template to render can also be specified as part of the JSON payload, so the following request would return the same result:
|
26 |
|
27 |
|
28 | ```
|
29 | curl -H 'Content-type: application/json' -X POST -d '{"layout": {"template": "hello"}, "data": {"message": "Hello!"}}' http://your-shunter-server/template
|
30 | ```
|
31 |
|
32 | The maximum size of the POST request can be controlled by setting the `max-post-size` option when starting your app.
|
33 |
|
34 |
|
35 | ---
|
36 |
|
37 | Related:
|
38 |
|
39 | - [Full API Documentation](index.md)
|