1 |
|
2 | Sample Data
|
3 | ===========
|
4 |
|
5 | Shunter includes a tool to serve sample JSON data to which Shunter can proxy. This is helpful for mocking up and testing templates without a functioning back end in place.
|
6 |
|
7 | This JSON-serving tool can be useful for the negotiation of data contracts between the back end and front end of an application. A format for data can be decided upon at an early stage of a feature allowing independent work to be carried out before integration. This means both parties can begin work independently with a recognition of what is expected.
|
8 |
|
9 | The example JSON sits in a `data` directory within the root of your Shunter project and contains dummy data that replicates the response expected from a back end app to load appropriate layouts and templates. This may negate the need to run a full back end locally to work on the front end of your project.
|
10 |
|
11 | If you are dealing with large and complicated JSON files you may want to reduce repetition in your sample data by including a template of repeated JSON and then expand upon and modify it. For example This example javascript file requires a template.JSON and then modifies it:
|
12 |
|
13 | ```js
|
14 | var json = JSON.parse(JSON.stringify(require('./template')));
|
15 | json.header.title = 'article';
|
16 | module.exports = json;
|
17 | ```
|
18 |
|
19 | To use the `shunter-serve` command line tool, run the following:
|
20 |
|
21 | ```
|
22 | ./node_modules/.bin/shunter-serve
|
23 | ```
|
24 |
|
25 | you may specify the port on which `shunter-serve` should run by using the option `-p`, this should match the port specified in the Shunter routing configuration, set in the Shunter config file or at run-time with the `-o` option. For example to listen on port 9000, run the following:
|
26 |
|
27 | ```
|
28 | ./node_modules/.bin/shunter-serve -p 9000
|
29 | ```
|
30 |
|
31 | You may also set a number of milliseconds of latency for the response using the `-l` option. This can be useful for performance-related testing.
|
32 |
|
33 |
|
34 | ---
|
35 |
|
36 | Related:
|
37 |
|
38 | - [Full API Documentation](index.md)
|