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
+100-1Lines changed: 100 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,13 +9,15 @@ Simply run `npm install --save feathers-hooks-jsonapify` and you're good to go!
9
9
10
10
> **Important:** As of version 0.1.0, this hook is intended to use with Sequelize. Further versions will move the coupling code to hook configurations.
11
11
12
+
This hook is intended to use with `feathers-rest`, since it'll convert that provider's response to a JSON-API compliant document.
`feathers-hooks-jsonapify` will automatically detect metadata for relationships in the model. It'll create an `included` top-level array in the document when the hook is called via `find`.
47
+
48
+
#### Example document for a self-referencing model
49
+
50
+
```json
51
+
{
52
+
"data": {
53
+
"type": "topics",
54
+
"id": "sports-cars",
55
+
"attributes": {
56
+
"name": "Cars",
57
+
"created-at": "2017-04-14T22:22:03.000Z",
58
+
"updated-at": null
59
+
},
60
+
"relationships": {
61
+
"parent-topic": {
62
+
"data": {
63
+
"type": "topics",
64
+
"id": "sports"
65
+
}
66
+
}
67
+
},
68
+
"links": {
69
+
"self": "/topics/sports-cars",
70
+
"parent": "/topics"
71
+
}
72
+
},
73
+
"included": [
74
+
{
75
+
"type": "topics",
76
+
"id": "sports",
77
+
"attributes": {
78
+
"name": "Sports",
79
+
"parent-topic-id": null,
80
+
"created-at": "2017-04-14T22:22:03.000Z",
81
+
"updated-at": null
82
+
},
83
+
"links": {
84
+
"self": "/topics/sports"
85
+
}
86
+
}
87
+
]
88
+
}
89
+
```
90
+
91
+
### Pagination
92
+
93
+
The hook will also detect if `hook.result.skip`, `hook.result.limit` and `hook.result.total` are available as part of the `feathers-rest` provider. If available, it'll create `first`, `prev`, `next` and `last` links accordingly.
94
+
95
+
The raw pagination data is moved to a `meta` object.
96
+
97
+
#### Example document with pagination links
98
+
99
+
```json
100
+
{
101
+
"data": [
102
+
{
103
+
"type": "topics",
104
+
"id": "cinema",
105
+
"attributes": {
106
+
"name": "Cinema",
107
+
"show-role-title": null,
108
+
"created-at": "2017-04-14T22:22:03.000Z",
109
+
"updated-at": null
110
+
},
111
+
"links": {
112
+
"self": "/topics/cinema"
113
+
}
114
+
},
115
+
{
116
+
"type": "topics",
117
+
"id": "comedy",
118
+
"attributes": {
119
+
"name": "Comedy",
120
+
"show-role-title": null,
121
+
"created-at": "2017-04-14T22:22:03.000Z",
122
+
"updated-at": null
123
+
},
124
+
"links": {
125
+
"self": "/topics/comedy"
126
+
}
127
+
}
128
+
],
129
+
"links": {
130
+
"next": "/topics?$skip=2",
131
+
"last": "/topics?$skip=14"
132
+
},
133
+
"meta": {
134
+
"total": 15,
135
+
"limit": 2,
136
+
"skip": 0
137
+
}
138
+
}
139
+
```
140
+
42
141
## TODOs
43
142
44
143
Check out the [issues](https://github.com/joelalejandro/feathers-hooks-jsonapify/issues).
0 commit comments