@modernpoacher/halacious 7.0.0 → 7.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -2
- package/examples/api-root.cjs +0 -89
- package/examples/array-of-links.cjs +0 -68
- package/examples/auto-namespace.cjs +0 -48
- package/examples/functional-href.cjs +0 -67
- package/examples/hello-world.cjs +0 -25
- package/examples/manual-namespace.cjs +0 -52
- package/examples/media-types.cjs +0 -44
- package/examples/paging.cjs +0 -88
- package/examples/programmatic-entity.cjs +0 -60
- package/examples/programmatic-route.cjs +0 -60
- package/examples/query-string.cjs +0 -53
- package/examples/rels/mycompany/boss.md +0 -1
- package/examples/rels/mycompany/user.md +0 -7
- package/examples/rels/mycompany/users.md +0 -1
- package/examples/simple-embed.cjs +0 -44
- package/examples/simple-link.cjs +0 -39
- package/test/plugin.spec.mjs +0 -2605
- package/test/rels/mycompany/boss.md +0 -2
- package/test/rels/mycompany/employee.md +0 -2
- package/test/representation.spec.mjs +0 -384
- package/tsconfig.json +0 -11
- package/views/namespaces.jade +0 -11
- package/views/rel.jade +0 -7
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@modernpoacher/halacious",
|
|
3
|
-
"version": "7.0.
|
|
3
|
+
"version": "7.0.2",
|
|
4
4
|
"description": "A HAL processor for Hapi",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"HAL",
|
|
@@ -53,6 +53,7 @@
|
|
|
53
53
|
"@babel/eslint-parser": "^7.23.3",
|
|
54
54
|
"@hapi/hapi": "^21.3.2",
|
|
55
55
|
"@hapi/vision": "^7.0.3",
|
|
56
|
+
"@modernpoacher/hooks": "^1.0.456",
|
|
56
57
|
"@sequencemedia/sinon-chai": "^0.0.6",
|
|
57
58
|
"@typescript-eslint/eslint-plugin": "^6.19.0",
|
|
58
59
|
"@typescript-eslint/parser": "^6.19.0",
|
|
@@ -60,7 +61,7 @@
|
|
|
60
61
|
"cross-env": "^7.0.3",
|
|
61
62
|
"eslint": "^8.56.0",
|
|
62
63
|
"eslint-config-standard": "^17.1.0",
|
|
63
|
-
"eslint-config-standard-with-typescript": "^43.0.
|
|
64
|
+
"eslint-config-standard-with-typescript": "^43.0.1",
|
|
64
65
|
"husky": "^8.0.3",
|
|
65
66
|
"mocha": "^10.2.0",
|
|
66
67
|
"sinon": "^17.0.1"
|
package/examples/api-root.cjs
DELETED
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
const hapi = require('@hapi/hapi')
|
|
2
|
-
const vision = require('@hapi/vision')
|
|
3
|
-
const halacious = require('#halacious')
|
|
4
|
-
|
|
5
|
-
const PLUGIN = 'halacious' // '@modernpoacher/halacious'
|
|
6
|
-
|
|
7
|
-
async function init () {
|
|
8
|
-
const server = hapi.server({ port: 8080 })
|
|
9
|
-
|
|
10
|
-
await server.register(vision)
|
|
11
|
-
|
|
12
|
-
await server.register({ plugin: halacious, options: { absolute: true } })
|
|
13
|
-
|
|
14
|
-
const namespace = server.plugins[PLUGIN].namespaces.add({
|
|
15
|
-
name: 'mycompany',
|
|
16
|
-
description: 'My Companys namespace',
|
|
17
|
-
prefix: 'mco'
|
|
18
|
-
})
|
|
19
|
-
namespace.rel({ name: 'users', description: 'a collection of users' })
|
|
20
|
-
namespace.rel({ name: 'user', description: 'a single user' })
|
|
21
|
-
namespace.rel({ name: 'widgets', description: 'a collection of widgets' })
|
|
22
|
-
namespace.rel({ name: 'widget', description: 'a single widget' })
|
|
23
|
-
|
|
24
|
-
server.route({
|
|
25
|
-
method: 'get',
|
|
26
|
-
path: '/users',
|
|
27
|
-
config: {
|
|
28
|
-
handler () {
|
|
29
|
-
return {}
|
|
30
|
-
},
|
|
31
|
-
plugins: {
|
|
32
|
-
hal: {
|
|
33
|
-
api: 'mco:users'
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
})
|
|
38
|
-
|
|
39
|
-
server.route({
|
|
40
|
-
method: 'get',
|
|
41
|
-
path: '/users/{userId}',
|
|
42
|
-
config: {
|
|
43
|
-
handler () {
|
|
44
|
-
return {}
|
|
45
|
-
},
|
|
46
|
-
plugins: {
|
|
47
|
-
hal: {
|
|
48
|
-
api: 'mco:user'
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
})
|
|
53
|
-
|
|
54
|
-
server.route({
|
|
55
|
-
method: 'get',
|
|
56
|
-
path: '/widgets',
|
|
57
|
-
config: {
|
|
58
|
-
handler () {
|
|
59
|
-
return {}
|
|
60
|
-
},
|
|
61
|
-
plugins: {
|
|
62
|
-
hal: {
|
|
63
|
-
api: 'mco:widgets'
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
})
|
|
68
|
-
|
|
69
|
-
server.route({
|
|
70
|
-
method: 'get',
|
|
71
|
-
path: '/widgets/{widgetId}',
|
|
72
|
-
config: {
|
|
73
|
-
handler () {
|
|
74
|
-
return {}
|
|
75
|
-
},
|
|
76
|
-
plugins: {
|
|
77
|
-
hal: {
|
|
78
|
-
api: 'mco:widget'
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
})
|
|
83
|
-
|
|
84
|
-
await server.start()
|
|
85
|
-
|
|
86
|
-
console.log('Server started at %s', server.info.uri)
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
init()
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
const hapi = require('@hapi/hapi')
|
|
2
|
-
const vision = require('@hapi/vision')
|
|
3
|
-
const halacious = require('#halacious')
|
|
4
|
-
|
|
5
|
-
async function init () {
|
|
6
|
-
const server = hapi.server({ port: 8080 })
|
|
7
|
-
|
|
8
|
-
await server.register(vision)
|
|
9
|
-
|
|
10
|
-
await server.register(halacious)
|
|
11
|
-
|
|
12
|
-
server.route({
|
|
13
|
-
method: 'get',
|
|
14
|
-
path: '/employees/{id}',
|
|
15
|
-
config: {
|
|
16
|
-
id: 'employee.lookup',
|
|
17
|
-
handler (req, next) {
|
|
18
|
-
next(req.params)
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
})
|
|
22
|
-
|
|
23
|
-
server.route({
|
|
24
|
-
method: 'get',
|
|
25
|
-
path: '/departments/{id}',
|
|
26
|
-
config: {
|
|
27
|
-
handler (req) {
|
|
28
|
-
return {
|
|
29
|
-
id: req.params.id,
|
|
30
|
-
employees: [
|
|
31
|
-
{ id: 100, name: 'Tom' },
|
|
32
|
-
{ id: 101, name: 'Dick' },
|
|
33
|
-
{ id: 102, name: 'Harry' }
|
|
34
|
-
]
|
|
35
|
-
}
|
|
36
|
-
},
|
|
37
|
-
plugins: {
|
|
38
|
-
hal: {
|
|
39
|
-
prepare (rep, next) {
|
|
40
|
-
const employees = rep.entity.employees
|
|
41
|
-
|
|
42
|
-
// adding multiple links with the same rel will create an array of links in the payload
|
|
43
|
-
|
|
44
|
-
// link by route id
|
|
45
|
-
rep.link(
|
|
46
|
-
'mco:employee',
|
|
47
|
-
rep.route('employee.lookup', employees[0])
|
|
48
|
-
)
|
|
49
|
-
|
|
50
|
-
// or by relative path
|
|
51
|
-
rep.link('mco:employee', `../../employees/${employees[1].id}`)
|
|
52
|
-
|
|
53
|
-
// or by absolute path
|
|
54
|
-
rep.link('mco:employee', `/employees/${employees[2].id}`)
|
|
55
|
-
|
|
56
|
-
next()
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
})
|
|
62
|
-
|
|
63
|
-
await server.start()
|
|
64
|
-
|
|
65
|
-
console.log('Server started at %s', server.info.uri)
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
init()
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
const path = require('path')
|
|
2
|
-
|
|
3
|
-
const hapi = require('@hapi/hapi')
|
|
4
|
-
const vision = require('@hapi/vision')
|
|
5
|
-
const halacious = require('#halacious')
|
|
6
|
-
|
|
7
|
-
const PLUGIN = 'halacious' // '@modernpoacher/halacious'
|
|
8
|
-
|
|
9
|
-
async function init () {
|
|
10
|
-
const server = hapi.server({ port: 8080 })
|
|
11
|
-
|
|
12
|
-
await server.register(vision)
|
|
13
|
-
|
|
14
|
-
await server.register(halacious)
|
|
15
|
-
|
|
16
|
-
server.plugins[PLUGIN].namespaces.add({
|
|
17
|
-
dir: path.resolve(__dirname, 'rels/mycompany'),
|
|
18
|
-
prefix: 'mco'
|
|
19
|
-
})
|
|
20
|
-
|
|
21
|
-
server.route({
|
|
22
|
-
method: 'GET',
|
|
23
|
-
path: '/users/{userId}',
|
|
24
|
-
handler (req) {
|
|
25
|
-
return {
|
|
26
|
-
id: req.params.userId,
|
|
27
|
-
name: `User ${req.params.userId}`,
|
|
28
|
-
bossId: 200
|
|
29
|
-
}
|
|
30
|
-
},
|
|
31
|
-
config: {
|
|
32
|
-
plugins: {
|
|
33
|
-
hal: {
|
|
34
|
-
links: {
|
|
35
|
-
'mco:boss': '../{bossId}'
|
|
36
|
-
},
|
|
37
|
-
ignore: 'bossId'
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
})
|
|
42
|
-
|
|
43
|
-
await server.start()
|
|
44
|
-
|
|
45
|
-
console.log('Server started at %s', server.info.uri)
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
init()
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
const hapi = require('@hapi/hapi')
|
|
2
|
-
const vision = require('@hapi/vision')
|
|
3
|
-
const halacious = require('#halacious')
|
|
4
|
-
|
|
5
|
-
async function init () {
|
|
6
|
-
const server = hapi.server({ port: 8080 })
|
|
7
|
-
|
|
8
|
-
await server.register(vision)
|
|
9
|
-
|
|
10
|
-
await server.register(halacious)
|
|
11
|
-
|
|
12
|
-
server.route({
|
|
13
|
-
method: 'get',
|
|
14
|
-
path: '/users/{id}',
|
|
15
|
-
handler (req) {
|
|
16
|
-
return { id: req.params.id, bossId: 101 }
|
|
17
|
-
},
|
|
18
|
-
config: {
|
|
19
|
-
id: 'user',
|
|
20
|
-
plugins: {
|
|
21
|
-
hal: {
|
|
22
|
-
links: {
|
|
23
|
-
boss (rep, entity) {
|
|
24
|
-
return rep.route('user', { id: entity.bossId })
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
})
|
|
31
|
-
|
|
32
|
-
server.route({
|
|
33
|
-
method: 'get',
|
|
34
|
-
path: '/users',
|
|
35
|
-
handler () {
|
|
36
|
-
return {
|
|
37
|
-
start: 0,
|
|
38
|
-
count: 2,
|
|
39
|
-
limit: 2,
|
|
40
|
-
items: [
|
|
41
|
-
{ id: 100, firstName: 'Brad', lastName: 'Leupen' },
|
|
42
|
-
{ id: 101, firstName: 'Barack', lastName: 'Obama' }
|
|
43
|
-
]
|
|
44
|
-
}
|
|
45
|
-
},
|
|
46
|
-
config: {
|
|
47
|
-
plugins: {
|
|
48
|
-
hal: {
|
|
49
|
-
embedded: {
|
|
50
|
-
item: {
|
|
51
|
-
path: 'items',
|
|
52
|
-
href (rep, ctx) {
|
|
53
|
-
return rep.route('user', { id: ctx.item.id })
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
})
|
|
61
|
-
|
|
62
|
-
await server.start()
|
|
63
|
-
|
|
64
|
-
console.log('Server started at %s', server.info.uri)
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
init()
|
package/examples/hello-world.cjs
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
const hapi = require('@hapi/hapi')
|
|
2
|
-
const vision = require('@hapi/vision')
|
|
3
|
-
const halacious = require('#halacious')
|
|
4
|
-
|
|
5
|
-
async function init () {
|
|
6
|
-
const server = hapi.server({ port: 8080 })
|
|
7
|
-
|
|
8
|
-
await server.register(vision)
|
|
9
|
-
|
|
10
|
-
await server.register(halacious)
|
|
11
|
-
|
|
12
|
-
server.route({
|
|
13
|
-
method: 'get',
|
|
14
|
-
path: '/hello/{name}',
|
|
15
|
-
handler (req) {
|
|
16
|
-
return { message: `Hello, ${req.params.name}` }
|
|
17
|
-
}
|
|
18
|
-
})
|
|
19
|
-
|
|
20
|
-
await server.start()
|
|
21
|
-
|
|
22
|
-
console.log('Server started at %s', server.info.uri)
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
init()
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
const hapi = require('@hapi/hapi')
|
|
2
|
-
const vision = require('@hapi/vision')
|
|
3
|
-
const halacious = require('#halacious')
|
|
4
|
-
|
|
5
|
-
const { name: PLUGIN } = require('#halacious/package')
|
|
6
|
-
|
|
7
|
-
async function init () {
|
|
8
|
-
const server = hapi.server({ port: 8080 })
|
|
9
|
-
|
|
10
|
-
await server.register(vision)
|
|
11
|
-
|
|
12
|
-
await server.register(halacious)
|
|
13
|
-
|
|
14
|
-
const namespace = server.plugins[PLUGIN].namespaces.add({
|
|
15
|
-
name: 'mycompany',
|
|
16
|
-
description: 'My Companys namespace',
|
|
17
|
-
prefix: 'mco'
|
|
18
|
-
})
|
|
19
|
-
namespace.rel({ name: 'users', description: 'a collection of users' })
|
|
20
|
-
namespace.rel({ name: 'user', description: 'a single user' })
|
|
21
|
-
namespace.rel({ name: 'boss', description: 'a users boss' })
|
|
22
|
-
|
|
23
|
-
server.route({
|
|
24
|
-
method: 'get',
|
|
25
|
-
path: '/users/{userId}',
|
|
26
|
-
|
|
27
|
-
handler (req) {
|
|
28
|
-
return {
|
|
29
|
-
id: req.params.userId,
|
|
30
|
-
name: `User ${req.params.userId}`,
|
|
31
|
-
bossId: 200
|
|
32
|
-
}
|
|
33
|
-
},
|
|
34
|
-
|
|
35
|
-
config: {
|
|
36
|
-
plugins: {
|
|
37
|
-
hal: {
|
|
38
|
-
links: {
|
|
39
|
-
'mco:boss': '../{bossId}'
|
|
40
|
-
},
|
|
41
|
-
ignore: 'bossId'
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
})
|
|
46
|
-
|
|
47
|
-
await server.start()
|
|
48
|
-
|
|
49
|
-
console.log('Server started at %s', server.info.uri)
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
init()
|
package/examples/media-types.cjs
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
const hapi = require('@hapi/hapi')
|
|
2
|
-
const vision = require('@hapi/vision')
|
|
3
|
-
const halacious = require('#halacious')
|
|
4
|
-
|
|
5
|
-
async function init () {
|
|
6
|
-
const server = hapi.server({ port: 8080 })
|
|
7
|
-
|
|
8
|
-
await server.register(vision)
|
|
9
|
-
|
|
10
|
-
await server.register({
|
|
11
|
-
plugin: halacious,
|
|
12
|
-
options: {
|
|
13
|
-
mediaTypes: ['application/json', 'application/hal+json']
|
|
14
|
-
}
|
|
15
|
-
})
|
|
16
|
-
|
|
17
|
-
server.route({
|
|
18
|
-
method: 'get',
|
|
19
|
-
path: '/users/{userId}',
|
|
20
|
-
handler (req) {
|
|
21
|
-
return {
|
|
22
|
-
id: req.params.userId,
|
|
23
|
-
name: `User ${req.params.userId}`,
|
|
24
|
-
googlePlusId: '107835557095464780852'
|
|
25
|
-
}
|
|
26
|
-
},
|
|
27
|
-
config: {
|
|
28
|
-
plugins: {
|
|
29
|
-
hal: {
|
|
30
|
-
links: {
|
|
31
|
-
home: 'http://plus.google.com/{googlePlusId}'
|
|
32
|
-
},
|
|
33
|
-
ignore: 'googlePlusId' // remove the id property from the response
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
})
|
|
38
|
-
|
|
39
|
-
await server.start()
|
|
40
|
-
|
|
41
|
-
console.log('Server started at %s', server.info.uri)
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
init()
|
package/examples/paging.cjs
DELETED
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
const hapi = require('@hapi/hapi')
|
|
2
|
-
const vision = require('@hapi/vision')
|
|
3
|
-
const hoek = require('@hapi/hoek')
|
|
4
|
-
const Uri = require('urijs')
|
|
5
|
-
const halacious = require('#halacious')
|
|
6
|
-
|
|
7
|
-
const { name: PLUGIN } = require('#halacious/package')
|
|
8
|
-
|
|
9
|
-
const users = []
|
|
10
|
-
|
|
11
|
-
for (let i = 0; i < 100; i++) {
|
|
12
|
-
users.push({ id: 1000 + i, firstName: 'Test', lastName: `User ${i}` })
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
function Collection (items, start, total) {
|
|
16
|
-
this.items = items || []
|
|
17
|
-
this.start = start || 0
|
|
18
|
-
this.count = this.items.length
|
|
19
|
-
this.total = total || this.items.count
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
Collection.prototype.toHal = function (rep, done) {
|
|
23
|
-
const limit = Number(rep.request.query.limit) || 10
|
|
24
|
-
const uri = new Uri(rep.self)
|
|
25
|
-
const prev = Math.max(0, this.start - limit)
|
|
26
|
-
const next = Math.min(this.total, this.start + limit)
|
|
27
|
-
|
|
28
|
-
const query = uri.search(true)
|
|
29
|
-
|
|
30
|
-
if (this.start > 0) {
|
|
31
|
-
rep.link(
|
|
32
|
-
'prev',
|
|
33
|
-
uri.search(hoek.applyToDefaults(query, { start: prev, limit })).toString()
|
|
34
|
-
)
|
|
35
|
-
}
|
|
36
|
-
if (this.start + this.count < this.total) {
|
|
37
|
-
rep.link(
|
|
38
|
-
'next',
|
|
39
|
-
uri.search(hoek.applyToDefaults(query, { start: next, limit })).toString()
|
|
40
|
-
)
|
|
41
|
-
}
|
|
42
|
-
done()
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
async function init () {
|
|
46
|
-
const server = hapi.server({ port: 8080 })
|
|
47
|
-
|
|
48
|
-
await server.register(vision)
|
|
49
|
-
|
|
50
|
-
await server.register({
|
|
51
|
-
plugin: halacious,
|
|
52
|
-
options: { mediaTypes: ['application/json', 'application/hal+json'] }
|
|
53
|
-
})
|
|
54
|
-
|
|
55
|
-
server.plugins[PLUGIN].namespaces
|
|
56
|
-
.add({ name: 'mycompay', prefix: 'mco' })
|
|
57
|
-
.rel('user')
|
|
58
|
-
|
|
59
|
-
server.route({
|
|
60
|
-
method: 'get',
|
|
61
|
-
path: '/users',
|
|
62
|
-
handler (req) {
|
|
63
|
-
const start = Number(req.query.start) || 0
|
|
64
|
-
const limit = Number(req.query.limit) || 10
|
|
65
|
-
const items = users.slice(start, start + limit)
|
|
66
|
-
return new Collection(items, start, users.length)
|
|
67
|
-
},
|
|
68
|
-
config: {
|
|
69
|
-
plugins: {
|
|
70
|
-
hal: {
|
|
71
|
-
query: '{?start,limit,q}',
|
|
72
|
-
embedded: {
|
|
73
|
-
'mco:item': {
|
|
74
|
-
path: 'items',
|
|
75
|
-
href: './{item.id}'
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
})
|
|
82
|
-
|
|
83
|
-
await server.start()
|
|
84
|
-
|
|
85
|
-
console.log('Server started at %s', server.info.uri)
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
init()
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
const hapi = require('@hapi/hapi')
|
|
2
|
-
const vision = require('@hapi/vision')
|
|
3
|
-
const halacious = require('#halacious')
|
|
4
|
-
|
|
5
|
-
function User (id, firstName, lastName, googlePlusId) {
|
|
6
|
-
this.id = id
|
|
7
|
-
this.firstName = firstName
|
|
8
|
-
this.lastName = lastName
|
|
9
|
-
this.googlePlusId = googlePlusId
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
User.prototype.toHal = function (rep, next) {
|
|
13
|
-
if (this.googlePlusId) {
|
|
14
|
-
rep.link('home', `http://plus.google.com/${this.googlePlusId}`)
|
|
15
|
-
rep.ignore('googlePlusId')
|
|
16
|
-
}
|
|
17
|
-
next()
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
async function init () {
|
|
21
|
-
const server = hapi.server({ port: 8080 })
|
|
22
|
-
|
|
23
|
-
await server.register(vision)
|
|
24
|
-
|
|
25
|
-
await server.register(halacious)
|
|
26
|
-
|
|
27
|
-
server.route({
|
|
28
|
-
method: 'get',
|
|
29
|
-
path: '/users',
|
|
30
|
-
handler () {
|
|
31
|
-
return {
|
|
32
|
-
start: 0,
|
|
33
|
-
count: 2,
|
|
34
|
-
limit: 2,
|
|
35
|
-
items: [
|
|
36
|
-
new User(100, 'Brad', 'Leupen', '107835557095464780852'),
|
|
37
|
-
new User(101, 'Mark', 'Zuckerberg')
|
|
38
|
-
]
|
|
39
|
-
}
|
|
40
|
-
},
|
|
41
|
-
config: {
|
|
42
|
-
plugins: {
|
|
43
|
-
hal: {
|
|
44
|
-
embedded: {
|
|
45
|
-
item: {
|
|
46
|
-
path: 'items',
|
|
47
|
-
href: './{item.id}'
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
})
|
|
54
|
-
|
|
55
|
-
await server.start()
|
|
56
|
-
|
|
57
|
-
console.log('Server started at %s', server.info.uri)
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
init()
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
const hapi = require('@hapi/hapi')
|
|
2
|
-
const vision = require('@hapi/vision')
|
|
3
|
-
const halacious = require('#halacious')
|
|
4
|
-
|
|
5
|
-
async function init () {
|
|
6
|
-
const server = hapi.server({ port: 8080 })
|
|
7
|
-
|
|
8
|
-
await server.register(vision)
|
|
9
|
-
|
|
10
|
-
await server.register(halacious)
|
|
11
|
-
|
|
12
|
-
server.route({
|
|
13
|
-
method: 'get',
|
|
14
|
-
path: '/users',
|
|
15
|
-
handler () {
|
|
16
|
-
return {
|
|
17
|
-
start: 0,
|
|
18
|
-
count: 2,
|
|
19
|
-
limit: 2,
|
|
20
|
-
items: [
|
|
21
|
-
{
|
|
22
|
-
id: 100,
|
|
23
|
-
firstName: 'Brad',
|
|
24
|
-
lastName: 'Leupen',
|
|
25
|
-
googlePlusId: '107835557095464780852'
|
|
26
|
-
},
|
|
27
|
-
{ id: 101, firstName: 'Mark', lastName: 'Zuckerberg' }
|
|
28
|
-
]
|
|
29
|
-
}
|
|
30
|
-
},
|
|
31
|
-
config: {
|
|
32
|
-
plugins: {
|
|
33
|
-
hal: {
|
|
34
|
-
// you can also assign this function directly to the hal property above as a shortcut
|
|
35
|
-
prepare (rep, next) {
|
|
36
|
-
rep.entity.items.forEach((item) => {
|
|
37
|
-
const embed = rep.embed('item', `./${item.id}`, item)
|
|
38
|
-
if (item.googlePlusId) {
|
|
39
|
-
embed.link(
|
|
40
|
-
'home',
|
|
41
|
-
`http://plus.google.com/${item.googlePlusId}`
|
|
42
|
-
)
|
|
43
|
-
embed.ignore('googlePlusId')
|
|
44
|
-
}
|
|
45
|
-
})
|
|
46
|
-
rep.ignore('items')
|
|
47
|
-
// dont forget to call next!
|
|
48
|
-
next()
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
})
|
|
54
|
-
|
|
55
|
-
await server.start()
|
|
56
|
-
|
|
57
|
-
console.log('Server started at %s', server.info.uri)
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
init()
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
const path = require('path')
|
|
2
|
-
|
|
3
|
-
const hapi = require('@hapi/hapi')
|
|
4
|
-
const vision = require('@hapi/vision')
|
|
5
|
-
const halacious = require('#halacious')
|
|
6
|
-
|
|
7
|
-
const { name: PLUGIN } = require('#halacious/package')
|
|
8
|
-
|
|
9
|
-
async function init () {
|
|
10
|
-
const server = hapi.server({ port: 8080 })
|
|
11
|
-
|
|
12
|
-
await server.register(vision)
|
|
13
|
-
|
|
14
|
-
await server.register({
|
|
15
|
-
plugin: halacious,
|
|
16
|
-
options: {
|
|
17
|
-
mediaTypes: ['application/json', 'application/hal+json']
|
|
18
|
-
}
|
|
19
|
-
})
|
|
20
|
-
|
|
21
|
-
server.plugins[PLUGIN].namespaces.add({
|
|
22
|
-
dir: path.resolve(__dirname, 'rels/mycompany'),
|
|
23
|
-
prefix: 'mco'
|
|
24
|
-
})
|
|
25
|
-
|
|
26
|
-
server.route({
|
|
27
|
-
method: 'get',
|
|
28
|
-
path: '/users',
|
|
29
|
-
handler () {
|
|
30
|
-
return { items: [{ id: 100, firstName: 'Louis', lastName: 'CK' }] }
|
|
31
|
-
},
|
|
32
|
-
config: {
|
|
33
|
-
plugins: {
|
|
34
|
-
hal: {
|
|
35
|
-
api: 'mco:users',
|
|
36
|
-
embedded: {
|
|
37
|
-
'mco:user': {
|
|
38
|
-
path: 'items',
|
|
39
|
-
href: './{item.id}'
|
|
40
|
-
}
|
|
41
|
-
},
|
|
42
|
-
query: '{?q*,start,limit}'
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
})
|
|
47
|
-
|
|
48
|
-
await server.start()
|
|
49
|
-
|
|
50
|
-
console.log('Server started at %s', server.info.uri)
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
init()
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
## A boss user
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
## a collection of users
|