-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcustomRepository.js
41 lines (31 loc) · 921 Bytes
/
customRepository.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
var simpleRestful = require('simple-restful');
class ConsoleRepository {
constructor(options) {}
getAll() {
console.log('getAll method called')
}
get(id) {
console.log(`get(${id} called`)
}
add(newData) {
console.log('add called')
}
update(id, newData) {
console.log(`update(${id} called`)
}
delete(id) {
console.log(`delete(${id} called`)
}
}
var server = simpleRestful.createServer({port:8081});
// Register the custom repository
server.addRepository("Console", ConsoleRepository);
// And finally create a resource that use this repository class
var testRepositoryInfo = {
name: "example",
repository: "Console", // Use it like this
repositoryOptions: {} // constructor options
};
server.addResource(testRepositoryInfo);
server.run();
// Each time you use this resource, it will only log stuff and not store anything, according to this repository