This repository has been archived by the owner on May 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalues.ts
67 lines (62 loc) · 1.43 KB
/
values.ts
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import { json, Request, Response } from 'express';
import { ControllerBase, DELETE, GET, POST, PUT } from '@egodigital/express-controllers';
/**
* /controllers/api/values.ts
*
* Base path: '/api/values'
*/
export class Controller extends ControllerBase {
/**
* [GET] /api/values
*/
@GET()
public async index(req: Request, res: Response) {
return res.send(
JSON.stringify(
[ "value1", "value2" ]
)
);
}
/**
* [GET] /api/values/:id
*/
@GET('/:id')
public async get_value(req: Request, res: Response) {
return res.send(
"value." + req.params['id']
);
}
/**
* [POST] /api/values
*/
@POST({
path: '/',
use: json(),
})
public async post_value(req: Request, res: Response) {
return res.send(
'POST: ' + JSON.stringify(req.body, null, 2)
);
}
/**
* [PUT] /api/values/:id
*/
@PUT({
path: '/:id',
use: json(),
})
public async put_value(req: Request, res: Response) {
return res.send(
'PUT (' + req.params['id'] + '): ' + JSON.stringify(req.body, null, 2)
);
}
/**
* [DELETE] /api/values/:id
*/
@DELETE('/:id')
public async delete_value(req: Request, res: Response) {
return res.send(
'DELETE: ' + req.params['id']
);
}
}