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
+21-24Lines changed: 21 additions & 24 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -119,7 +119,7 @@ Example:
119
119
"enable": true,
120
120
"handleErrors": true,
121
121
"errorStackInResponse": false,
122
-
"handleCustomRemote": false,
122
+
"handleCustomRemoteMethods": false,
123
123
"exclude": [
124
124
{"model": "comment"},
125
125
{"methods": "find"},
@@ -221,19 +221,19 @@ response. It will be stored under the `source.stack` key.
221
221
- Type: `boolean`
222
222
- Default: `false`
223
223
224
-
### handleCustomRemote
225
-
Allow all (custom) remotes to be serialized by default.
224
+
### handleCustomRemoteMethods
225
+
Allow all (custom) remote methods to be serialized by default.
226
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
227
+
This option can be overridden in any of the following ways:
228
+
1.Setting a jsonapi property to true or false in a remote method definition.
229
+
2.Globally adding the remote method to the component's exclude array.
230
+
3.Globally adding the remote method to the component's include array.
231
231
232
232
#### example
233
233
```js
234
234
{
235
235
...
236
-
"handleCustomRemote":true,
236
+
"handleCustomRemoteMethods":true,
237
237
...
238
238
}
239
239
```
@@ -409,20 +409,17 @@ Only expose foreign keys for the comment model findById method. eg. `GET /api/co
409
409
- Type: `boolean|array`
410
410
- Default: `false`
411
411
412
-
## Custom remote
412
+
## Custom remote methods
413
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.**
414
+
### `jsonapi` remote method options
415
+
Sometimes you need to be able to control when a custom remote method should be handled by the component. By default, `loopback-component-jsonapi` will not handle (serialize or deserialize) custom remote methods. In order to tell the component to handle a custom remote method, you have the following options (In priority order):
417
416
418
-
To enabled/disable JSONApi for specific remotes, you have multiple solutions:
417
+
1. Set `jsonapi` to `true` when defining a custom remote method.
418
+
2. Add the methods name to the component's `exclude` array setting. (see above)
419
+
3. Add the methods name to the component's `include` array setting. (see above)
420
+
4. Set `handleCustomRemoteMethods` to `true` in the component's settings. (see above)
419
421
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.
422
+
This option takes precedence and sets the component to handle or not handle the custom remote method.
Ensure the response of `Post.greet` will follow the JSONApi format.
431
+
Ensures that the response from Post.greet will follow JSONApi format.
435
432
436
433
```js
437
434
Post.remoteMethod('greet', {
438
435
jsonapi:false
439
436
returns: { arg:'greeting', type:'string' }
440
437
})
441
438
```
442
-
Ensure the response of `Post.greet` will not follow the JSONApi format.
439
+
Ensures that the response from Post.greet will never follow JSONApi format.
443
440
444
441
#### 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.
442
+
You must always pass `root: true` to the `returns` object when using `loopback-component-jsonapi`. This is especialy important when you expect the response to be an array.
446
443
447
-
### Override serialization type
448
-
You may want for a custom methodof 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.
444
+
### Overriding serialization type
445
+
When `loopback-component-jsonapi` serializes a custom remote method, by default it will assume that the data being serialized is of the same type as the model the custom remote method is being defined on. Eg. For a remote method on a `Comment`model, it will be assumed that the data being returned from the remote method will be a comment or an array of comments. When this is not the case, you will need to set the type property in the `returns` object in the remote method definition.
449
446
450
447
*If an unknown type or no type are given, the model name will be used.*
0 commit comments