Skip to content

Commit acd2591

Browse files
committed
updated documentation
1 parent 1cd1d52 commit acd2591

File tree

1 file changed

+100
-1
lines changed

1 file changed

+100
-1
lines changed

README.md

Lines changed: 100 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@ Simply run `npm install --save feathers-hooks-jsonapify` and you're good to go!
99

1010
> **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.
1111
12+
This hook is intended to use with `feathers-rest`, since it'll convert that provider's response to a JSON-API compliant document.
13+
1214
Require the hook:
1315

1416
```js
1517
const jsonapify = require('feathers-hooks-jsonapify');
1618
```
1719

18-
Thee choose how to implement it.
20+
Then choose how to implement it.
1921

2022
### Tied up to a service
2123

@@ -39,6 +41,103 @@ app.hooks({
3941
});
4042
```
4143

44+
### Relationships
45+
46+
`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+
42141
## TODOs
43142

44143
Check out the [issues](https://github.com/joelalejandro/feathers-hooks-jsonapify/issues).

0 commit comments

Comments
 (0)