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
[jsonapi.org](http://jsonapi.org/) support for loopback.
13
10
14
11
## Status
15
12
This project is a work in progress. Consider it beta software. For ember users, the component
16
13
should now be basically feature complete. Please test and report any issues.
17
-
The functionality that is present is pretty well tested. 130+ integration tests and counting!
14
+
The functionality that is present is pretty well tested. 140+ integration tests and counting!
18
15
19
16
Currently supported:
20
17
- Find all records via GET
@@ -44,24 +41,26 @@ Not yet supported:
44
41
We have created a sample project using [EmberJS](http://emberjs.com), [Loopback](http://loopback.io) and this compoment. It's called [emberloop](https://github.com/tsteuwer/emberloop).
45
42
46
43
## Helping out
47
-
We are VERY interested in help. See the [issue tracker](https://github.com/digitalsadhu/loopback-component-jsonapi/issues)
44
+
We are VERY interested in help. Get in touch via the [issue tracker](https://github.com/digitalsadhu/loopback-component-jsonapi/issues)
48
45
49
46
## Usage
50
47
In your loopback project:
51
48
52
49
1.`npm install --save loopback-component-jsonapi`
53
50
2. Create a `component-config.json` file in your server folder (if you don't already have one)
54
51
3. Add the following config to `component-config.json`
52
+
55
53
```json
56
54
{
57
55
"loopback-component-jsonapi": {}
58
56
}
59
57
```
60
58
61
59
## Advanced usage:
62
-
In a fairly limited way, you can configure a how the component behaves.
60
+
We are aiming to make the component as configureable as possible. You can configure a how the component behaves with the options shown and listed below. If there is something else you would like to see be configureable, please submit an issue on the repository.
Url prefix to be used in conjunction with host and resource paths.
83
-
eg. http://127.0.0.1:3214/api/people
84
-
Default: `/api`
84
+
Url prefix to be used in conjunction with host and resource paths. eg. http://127.0.0.1:3214/api/people
85
+
86
+
#### example
87
+
```js
88
+
{
89
+
...
90
+
"restApiRoot":"/api",
91
+
...
92
+
}
93
+
```
94
+
95
+
- Type: `string`
96
+
- Default: `/api`
85
97
86
98
### enable
87
-
Whether the component should be enabled or disabled.
88
-
Default: true
99
+
Whether the component should be enabled or disabled. Defaults to `false`, flip it to `true` if you need to turn the component off without removing the configuration for some reason.
100
+
101
+
#### example
102
+
```js
103
+
{
104
+
...
105
+
"enable":true,
106
+
...
107
+
}
108
+
```
109
+
110
+
- Type: `boolean`
111
+
- Default: `true`
89
112
90
113
### handleErrors
91
114
When true, the component will unregister all other error handling and
92
115
register a custom error handler which always returns errors in jsonapi compliant
93
116
format. Validation errors include the correct properties in order to work
94
117
out of the box with ember.
95
-
Default: true
118
+
119
+
#### example
120
+
```js
121
+
{
122
+
...
123
+
"handleErrors":true,
124
+
...
125
+
}
126
+
```
127
+
128
+
- Type: `boolean`
129
+
- Default: `true`
96
130
97
131
### exclude
98
-
Allows blacklisting of models and methods. (See example above)
132
+
Allows blacklisting of models and methods.
99
133
Define an array of blacklist objects. Blacklist objects can contain "model" key
100
134
"methods" key or both. If just "model" is defined then all methods for the
101
-
specified model will not use jsonapi. If just the "methods" key is defined then
102
-
all methods specified on all models will be not use jsonapi. If a combination of
135
+
specified model will not be serialized of deserialized using jsonapi. If just the "methods" key is defined then
136
+
all methods specified on all models will be serialized or deserialized using jsonapi. If a combination of
103
137
"model" and "methods" keys are used then the specific combination of model and methods
104
-
specified will not use jsonapi.
105
-
106
-
#### Please note
107
-
The default component behavior currently is to only modify the output of the following
108
-
methods on all models to be json api compliant:
109
-
- find
110
-
- create
111
-
- updateAttributes
112
-
- deleteById
113
-
- findById
114
-
-__get__.*
115
-
-__findRelationships__.*
116
-
117
-
And the default current behavior for modifying input only applies to the following methods on
118
-
all models:
119
-
- create
120
-
- updateAttributes
121
-
122
-
Type: array
123
-
Default: null
138
+
specified will not be serialized or deserialized using jsonapi.
139
+
140
+
#### example
141
+
```js
142
+
{
143
+
...
144
+
"exclude": [
145
+
{"model":"comment"},
146
+
{"methods":"find"},
147
+
{"model":"post", "methods":"find"},
148
+
{"model":"person", "methods": ["find", "create"]}
149
+
],
150
+
...
151
+
}
152
+
```
153
+
154
+
- Type: `array`
155
+
- Default: `null`
156
+
157
+
#### Note
158
+
The default component behavior is to modify the output of the following CRUD model methods
159
+
methods on all models:
160
+
-`find`
161
+
-`create`
162
+
-`updateAttributes`
163
+
-`deleteById`
164
+
-`findById`
165
+
166
+
In addition the following wild card method names are matched and the output is modified in order to handle relationships eg. `/api/posts/1/comments`
167
+
-`__get__.*`
168
+
-`__findRelationships__.*`
169
+
170
+
The default behavior for modifying input only applies to the following methods on all models:
171
+
-`create`
172
+
-`updateAttributes`
124
173
125
174
### hideIrrelevantMethods
126
-
By default, loopback-component-jsonapi disables a number of methods from each endpoint
175
+
By default, `loopback-component-jsonapi` disables a number of methods from each endpoint
127
176
that are not jsonapi relevant. These methods are:
128
-
- upsert
129
-
- exists
130
-
- findOne
131
-
- count
132
-
- createChangeStream
133
-
- updateAll
134
-
You can use this option to reenable these methods.
135
-
Please note, these methods will not be modified by the component and so their output
177
+
-`upsert`
178
+
-`exists`
179
+
-`findOne`
180
+
-`count`
181
+
-`createChangeStream`
182
+
-`updateAll`
183
+
184
+
You can use this option to prevent `loopback-component-jsonapi` from doing so. These methods are not modified by the component. Their output
136
185
will not be in a jsonapi compliant format.
137
-
Type: boolean
138
-
Default: true
186
+
187
+
#### example
188
+
```js
189
+
{
190
+
...
191
+
"hideIrrelevantMethods":true,
192
+
...
193
+
}
194
+
```
195
+
196
+
- Type: `boolean`
197
+
- Default: `true`
198
+
199
+
### attributes
200
+
By default, model properties will be converted to attributes in jsonapi terms.
201
+
All model properties except the primary key and any foreign keys will be copied into
202
+
the attributes object before output. If you wish to limit which properties will
203
+
be output as attributes you can specify a whitelist of attributes for each type.
204
+
205
+
#### example
206
+
```js
207
+
{
208
+
...
209
+
"attributes": {
210
+
"posts": ["title", "content"],
211
+
"comments": ["createdAt", "updatedAt", "comment"]
212
+
}
213
+
...
214
+
}
215
+
```
216
+
217
+
- Type: `object`
218
+
- Default: `null`
219
+
220
+
#### note
221
+
The attributes arrays are keyed by type not by model name. Type is the term used by json api to describe the resource type in question and while not required by json api it is usually plural. In `loopback-component-jsonapi` it is whatever the models `plural` is set to in `model.json`. So in our example above we defined: `"posts": ["title", "content"]` as the resource type for the `post` model is `posts`
139
222
140
223
## Debugging
141
224
You can enable debug logging by setting an environment variable:
0 commit comments