You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+17-3Lines changed: 17 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -49,13 +49,14 @@ app.listen(3000);
49
49
50
50
Now you can send POST requests to `/js` endpoint with the body containing the script and an optional data instance that will be processed by JSONScript interpreter. For example, with this request:
51
51
52
-
```json
52
+
```javascript
53
53
{
54
54
"script": {
55
55
"res1": {
56
-
"$exec": "router",
57
-
"$method": "get",
56
+
"$exec":"router",// executor name can be changed in options
57
+
"$method":"get",// $method can be get/post/put/delete
58
58
"$args": { "path":"/resource/1" }
59
+
// method property in $args can be used instead of $method
59
60
},
60
61
"res2": {
61
62
"$exec":"router",
@@ -85,6 +86,15 @@ the response will be a combination of two responses (both requests are processed
85
86
}
86
87
```
87
88
89
+
If option `processResponse: "body"` were used the result would have been:
90
+
91
+
```javascript
92
+
{
93
+
"res1": { /* response body 1 */ },
94
+
"res2": { /* response body 2 */ }
95
+
}
96
+
```
97
+
88
98
JSONScript also supports sequential evaluation, conditionals, data manipulation etc. So you can implement an advanced logic in your script and it will be executed in the server without sending responses of individual requests to the client.
89
99
90
100
See [JSONScript Language](https://github.com/JSONScript/jsonscript/blob/master/LANGUAGE.md) for more information.
@@ -116,13 +126,17 @@ Defaults:
116
126
{
117
127
routerExecutor:'router',
118
128
basePath:'',
129
+
processResponse:undefined,
119
130
jsonscript: { strict:true },
120
131
Promise:undefined
121
132
}
122
133
```
123
134
124
135
-_routerExecutor_: the name of the executor (the value of "$exec" keyword in the instruction) used to access Express router, `"router"` is used by default.
125
136
-_basePath_: the path used as a prefix to paths in the script $exec instruction arguments.
137
+
-_processResponse_: possible values:
138
+
-`"body"` - return only response body if status code is < 300, throw an exception otherwise.
139
+
- function - custom function to process the response object, can throw an exception or return the object to be used as the result.
126
140
-_jsonscript_: options passed to JSONScript interpreter [jsonscript-js](https://github.com/JSONScript/jsonscript-js).
127
141
-_Promise_: an optional Promise class, the native Promise is used by default.
0 commit comments