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
+64
Original file line number
Diff line number
Diff line change
@@ -97,6 +97,70 @@ JSONScript also supports sequential evaluation, conditionals, data manipulation,
97
97
See [JSONScript Language](https://github.com/JSONScript/jsonscript/blob/master/LANGUAGE.md) for more information.
98
98
99
99
100
+
## API
101
+
102
+
##### jsonscriptProxy(Object options [, Object js]) -> Function
103
+
104
+
Create express route handling function to process JSONScript. The second optional parameter is the existing instance of JSONScript interpreter, if it is not passed a new one will be created.
105
+
106
+
Both the `script` and the `data` instance should be properties of the request body:
107
+
108
+
```javascript
109
+
{
110
+
"script": {
111
+
// JSONScript, can be an array
112
+
},
113
+
"data": {
114
+
// data instance that can be used from the script,
115
+
// can be array
116
+
}
117
+
}
118
+
```
119
+
120
+
121
+
## Options
122
+
123
+
See [options schema](https://github.com/JSONScript/jsonscript-proxy/blob/master/config_schema.json).
124
+
125
+
Defaults:
126
+
127
+
```javascript
128
+
{
129
+
services: {}, // must be specified and have at least one property
130
+
processResponse:undefined,
131
+
jsonscript: { strict:true },
132
+
Promise:undefined
133
+
}
134
+
```
135
+
136
+
-_services_: the required map of service definitions that are exposed to JSONScript as executors. Each property name will be used as an executor map. See [Service definitions](#service-definitions).
137
+
-_processResponse_: the default response processing function, can be overridden for a particular service. The 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.
140
+
-_jsonscript_: options passed to JSONScript interpreter [jsonscript-js](https://github.com/JSONScript/jsonscript-js).
141
+
-_Promise_: an optional Promise class, the native Promise is used by default.
142
+
143
+
144
+
## Service definitions
145
+
146
+
`services` properties in options object should contain a map of services:
147
+
148
+
```javascript
149
+
{
150
+
service1: {
151
+
basePath:'...',
152
+
processResponce:undefined
153
+
},
154
+
service2: {
155
+
// ...
156
+
},
157
+
// ...
158
+
}
159
+
```
160
+
161
+
`basePath` will be prepended for the path in the call to the service, `processResponse`, if specified, will be used to process responses from the service.
0 commit comments