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
+70Lines changed: 70 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -119,6 +119,7 @@ Example:
119
119
"enable": true,
120
120
"handleErrors": true,
121
121
"errorStackInResponse": false,
122
+
"handleCustomRemote": false,
122
123
"exclude": [
123
124
{"model": "comment"},
124
125
{"methods": "find"},
@@ -220,6 +221,26 @@ response. It will be stored under the `source.stack` key.
220
221
- Type: `boolean`
221
222
- Default: `false`
222
223
224
+
### handleCustomRemote
225
+
Allow all (custom) remotes to be serialized by default.
226
+
227
+
This option can be overrided with:
228
+
1.`jsonapi` remote option (have highest priority)
229
+
2.`exclude` component option
230
+
3.`include` component option
231
+
232
+
#### example
233
+
```js
234
+
{
235
+
...
236
+
"handleCustomRemote":true,
237
+
...
238
+
}
239
+
```
240
+
241
+
- Type: `boolean`
242
+
- Default: `false`
243
+
223
244
### exclude
224
245
Allows blacklisting of models and methods.
225
246
Define an array of blacklist objects. Blacklist objects can contain "model" key
@@ -388,6 +409,55 @@ Only expose foreign keys for the comment model findById method. eg. `GET /api/co
388
409
- Type: `boolean|array`
389
410
- Default: `false`
390
411
412
+
## Custom remote
413
+
414
+
### `jsonapi` remote options
415
+
Sometime you need to control if custom remote should be serialized or not.
416
+
**By default a custom remote will NOT be handled by JSONApi.**
417
+
418
+
To enabled/disable JSONApi for specific remotes, you have multiple solutions:
419
+
420
+
1. Use `jsonapi` remote option
421
+
2. Use `exlude` on component options (see above)
422
+
3. Use `include` on component options (see above)
423
+
4. Use `handleCustomRemote` on component options (see above)
424
+
425
+
**This option has precedence** and it forces the remote to BE or to NOT BE deserialized/serialized by JSONApi.
426
+
427
+
#### examples
428
+
```js
429
+
Post.remoteMethod('greet', {
430
+
jsonapi:true
431
+
returns: { root:true }
432
+
})
433
+
```
434
+
Ensure the response of `Post.greet` will follow the JSONApi format.
435
+
436
+
```js
437
+
Post.remoteMethod('greet', {
438
+
jsonapi:false
439
+
returns: { arg:'greeting', type:'string' }
440
+
})
441
+
```
442
+
Ensure the response of `Post.greet` will not follow the JSONApi format.
443
+
444
+
#### Note
445
+
You should always pass `root: true` to the `returns` object when you use JSONApi, especialy when you expect to respond with an array.
446
+
447
+
### Override serialization type
448
+
You may want for a custom method of a given model to return instance(s) from another model. When you do so, you need to enforce the return `type` of this other model in the definition of the remote method.
449
+
450
+
*If an unknown type or no type are given, the model name will be used.*
451
+
452
+
#### example
453
+
454
+
```js
455
+
Post.remoteMethod('prototype.ownComments', {
456
+
jsonapi:true
457
+
returns: { root:true, type:'comment' }
458
+
})
459
+
```
460
+
391
461
## Custom Serialization
392
462
For occasions where you need greater control over the serialization process, you can implement a custom serialization function for each model as needed. This function will be used instead of the regular serialization process.
0 commit comments