@athenna/http 4.22.0 → 4.24.0
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 +8 -7
- package/src/commands/RouteListCommand.js +1 -1
- package/src/context/Request.d.ts +134 -30
- package/src/context/Request.js +143 -39
- package/src/context/Response.d.ts +155 -10
- package/src/context/Response.js +142 -11
- package/src/handlers/FastifyHandler.d.ts +1 -1
- package/src/handlers/FastifyHandler.js +17 -28
- package/src/kernels/HttpKernel.d.ts +4 -0
- package/src/kernels/HttpKernel.js +16 -1
- package/src/server/ServerImpl.js +14 -9
- package/src/types/contexts/Context.d.ts +0 -4
- package/src/types/contexts/ErrorContext.d.ts +2 -10
- package/src/types/contexts/ErrorContext.js +1 -2
- package/src/types/contexts/InterceptContext.d.ts +2 -10
- package/src/types/contexts/InterceptContext.js +1 -2
- package/src/types/contexts/TerminateContext.d.ts +2 -10
- package/src/types/contexts/TerminateContext.js +1 -2
- package/templates/controller.edge +2 -2
- package/templates/interceptor.edge +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@athenna/http",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.24.0",
|
|
4
4
|
"description": "The Athenna Http server. Built on top of fastify.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "João Lenon <lenon@athenna.io>",
|
|
@@ -72,17 +72,18 @@
|
|
|
72
72
|
"#tests": "./tests/index.js"
|
|
73
73
|
},
|
|
74
74
|
"devDependencies": {
|
|
75
|
-
"@athenna/artisan": "^4.
|
|
76
|
-
"@athenna/common": "^4.
|
|
77
|
-
"@athenna/config": "^4.
|
|
78
|
-
"@athenna/ioc": "^4.
|
|
79
|
-
"@athenna/logger": "^4.
|
|
75
|
+
"@athenna/artisan": "^4.38.0",
|
|
76
|
+
"@athenna/common": "^4.35.0",
|
|
77
|
+
"@athenna/config": "^4.18.0",
|
|
78
|
+
"@athenna/ioc": "^4.18.0",
|
|
79
|
+
"@athenna/logger": "^4.18.0",
|
|
80
80
|
"@athenna/test": "^4.22.0",
|
|
81
81
|
"@athenna/tsconfig": "^4.12.0",
|
|
82
|
-
"@athenna/view": "^4.
|
|
82
|
+
"@athenna/view": "^4.20.0",
|
|
83
83
|
"@fastify/cors": "^8.4.2",
|
|
84
84
|
"@fastify/helmet": "^11.1.1",
|
|
85
85
|
"@fastify/rate-limit": "^8.1.1",
|
|
86
|
+
"@fastify/static": "^7.0.1",
|
|
86
87
|
"@fastify/swagger": "^8.12.2",
|
|
87
88
|
"@fastify/swagger-ui": "^3.0.0",
|
|
88
89
|
"@typescript-eslint/eslint-plugin": "^6.7.4",
|
|
@@ -8,8 +8,8 @@
|
|
|
8
8
|
*/
|
|
9
9
|
import { sep } from 'node:path';
|
|
10
10
|
import { Config } from '@athenna/config';
|
|
11
|
-
import { Module } from '@athenna/common';
|
|
12
11
|
import { BaseCommand } from '@athenna/artisan';
|
|
12
|
+
import { Path, Module } from '@athenna/common';
|
|
13
13
|
import { Route, HttpKernel, HttpRouteProvider, HttpServerProvider } from '#src';
|
|
14
14
|
export class RouteListCommand extends BaseCommand {
|
|
15
15
|
static signature() {
|
package/src/context/Request.d.ts
CHANGED
|
@@ -16,121 +16,225 @@ export declare class Request {
|
|
|
16
16
|
/**
|
|
17
17
|
* Get the request id.
|
|
18
18
|
*
|
|
19
|
-
* @example
|
|
19
|
+
* @example
|
|
20
|
+
* ```ts
|
|
21
|
+
* console.log(request.id) // '12345'
|
|
22
|
+
* ```
|
|
20
23
|
*/
|
|
21
24
|
get id(): string;
|
|
22
25
|
/**
|
|
23
26
|
* Get the request ip.
|
|
24
27
|
*
|
|
25
|
-
* @example
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* console.log(request.ip) // '192.168.0.1'
|
|
31
|
+
* ```
|
|
26
32
|
*/
|
|
27
33
|
get ip(): string;
|
|
28
34
|
/**
|
|
29
35
|
* Get the request hostname.
|
|
30
36
|
*
|
|
31
|
-
* @example
|
|
37
|
+
* @example
|
|
38
|
+
* ```ts
|
|
39
|
+
* console.log(request.hostname) // 'localhost'
|
|
40
|
+
* ```
|
|
32
41
|
*/
|
|
33
42
|
get hostname(): string;
|
|
43
|
+
/**
|
|
44
|
+
* Get the server port.
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```ts
|
|
48
|
+
* console.log(request.port) // 3000
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
get port(): number;
|
|
52
|
+
/**
|
|
53
|
+
* Get the http version.
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```ts
|
|
57
|
+
* console.log(request.version) // 1
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
get version(): string;
|
|
34
61
|
/**
|
|
35
62
|
* Get the request protocol.
|
|
36
63
|
*
|
|
37
|
-
* @example
|
|
64
|
+
* @example
|
|
65
|
+
* ```ts
|
|
66
|
+
* console.log(request.protocol) // 'http'
|
|
67
|
+
* ```
|
|
38
68
|
*/
|
|
39
69
|
get protocol(): 'http' | 'https';
|
|
40
70
|
/**
|
|
41
71
|
* Get the request method.
|
|
42
72
|
*
|
|
43
|
-
* @example
|
|
73
|
+
* @example
|
|
74
|
+
* ```ts
|
|
75
|
+
* console.log(request.method) // 'GET'
|
|
76
|
+
* ```
|
|
44
77
|
*/
|
|
45
78
|
get method(): string;
|
|
46
79
|
/**
|
|
47
80
|
* Get the base url from request.
|
|
48
81
|
*
|
|
49
|
-
* @example
|
|
82
|
+
* @example
|
|
83
|
+
* ```ts
|
|
84
|
+
* console.log(request.baseUrl) // '/users/1'
|
|
85
|
+
* ```
|
|
50
86
|
*/
|
|
51
87
|
get baseUrl(): string;
|
|
52
88
|
/**
|
|
53
89
|
* Get the base url with host and port info from request.
|
|
54
90
|
*
|
|
55
|
-
* @example
|
|
91
|
+
* @example
|
|
92
|
+
* ```ts
|
|
93
|
+
* console.log(request.baseHostUrl) // 'http://localhost:3030/users/1'
|
|
94
|
+
* ```
|
|
56
95
|
*/
|
|
57
96
|
get baseHostUrl(): string;
|
|
58
97
|
/**
|
|
59
98
|
* Get the route url from request.
|
|
60
99
|
*
|
|
61
|
-
* @example
|
|
100
|
+
* @example
|
|
101
|
+
* ```ts
|
|
102
|
+
* console.log(request.routeUrl) // '/users/:id'
|
|
103
|
+
* ```
|
|
62
104
|
*/
|
|
63
105
|
get routeUrl(): string;
|
|
64
106
|
/**
|
|
65
107
|
* Get the route url with host and port info from request.
|
|
66
108
|
*
|
|
67
|
-
* @example
|
|
109
|
+
* @example
|
|
110
|
+
* ```ts
|
|
111
|
+
* console.log(request.routeHostUrl) // 'http://localhost:3030/users/:id'
|
|
112
|
+
* ```
|
|
68
113
|
*/
|
|
69
114
|
get routeHostUrl(): string;
|
|
70
115
|
/**
|
|
71
116
|
* Get the original url from request.
|
|
72
117
|
*
|
|
73
|
-
* @example
|
|
118
|
+
* @example
|
|
119
|
+
* ```ts
|
|
120
|
+
* console.log(request.originalUrl) // '/users/1?query=true'
|
|
121
|
+
* ```
|
|
74
122
|
*/
|
|
75
123
|
get originalUrl(): string;
|
|
76
124
|
/**
|
|
77
125
|
* Get the original url with host and port info from request.
|
|
78
126
|
*
|
|
79
|
-
* @example
|
|
127
|
+
* @example
|
|
128
|
+
* ```ts
|
|
129
|
+
* console.log(request.originalHostUrl) // 'http://localhost:3000/users/1?query=true'
|
|
130
|
+
* ```
|
|
80
131
|
*/
|
|
81
132
|
get originalHostUrl(): string;
|
|
82
133
|
/**
|
|
83
134
|
* Get all body from request.
|
|
135
|
+
*
|
|
136
|
+
* @example
|
|
137
|
+
* ```ts
|
|
138
|
+
* const { name, email } = request.body
|
|
139
|
+
* ```
|
|
84
140
|
*/
|
|
85
141
|
get body(): any | any[];
|
|
86
142
|
/**
|
|
87
143
|
* Get all params from request.
|
|
144
|
+
*
|
|
145
|
+
* @example
|
|
146
|
+
* ```ts
|
|
147
|
+
* const { id } = request.params
|
|
148
|
+
* ```
|
|
88
149
|
*/
|
|
89
150
|
get params(): any;
|
|
90
151
|
/**
|
|
91
152
|
* Get all queries from request.
|
|
153
|
+
*
|
|
154
|
+
* @example
|
|
155
|
+
* ```ts
|
|
156
|
+
* const { page, limit } = request.queries
|
|
157
|
+
* ```
|
|
92
158
|
*/
|
|
93
159
|
get queries(): any;
|
|
94
160
|
/**
|
|
95
161
|
* Get all headers from request.
|
|
162
|
+
*
|
|
163
|
+
* @example
|
|
164
|
+
* ```ts
|
|
165
|
+
* const { accept } = request.headers
|
|
166
|
+
* ```
|
|
96
167
|
*/
|
|
97
168
|
get headers(): any;
|
|
98
169
|
/**
|
|
99
|
-
* Get the
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
*
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
/**
|
|
107
|
-
* Get a value from the request params or the default value.
|
|
170
|
+
* Get a value from the request params or return
|
|
171
|
+
* the default value.
|
|
172
|
+
*
|
|
173
|
+
* @example
|
|
174
|
+
* ```ts
|
|
175
|
+
* const id = request.param('id', '1')
|
|
176
|
+
* ```
|
|
108
177
|
*/
|
|
109
178
|
param(param: string, defaultValue?: any): any;
|
|
110
179
|
/**
|
|
111
|
-
* Get a value from the request query param or
|
|
180
|
+
* Get a value from the request query param or return
|
|
181
|
+
* the default value.
|
|
182
|
+
*
|
|
183
|
+
* @example
|
|
184
|
+
* ```ts
|
|
185
|
+
* const page = request.query('page', '1')
|
|
186
|
+
* ```
|
|
112
187
|
*/
|
|
113
188
|
query(query: string, defaultValue?: any): any;
|
|
114
189
|
/**
|
|
115
|
-
* Get a value from the request header or
|
|
190
|
+
* Get a value from the request header or return
|
|
191
|
+
* the default value.
|
|
192
|
+
*
|
|
193
|
+
* @example
|
|
194
|
+
* ```ts
|
|
195
|
+
* const accept = request.header('accept', 'application/json')
|
|
196
|
+
* ```
|
|
116
197
|
*/
|
|
117
198
|
header(header: string, defaultValue?: any): any;
|
|
118
199
|
/**
|
|
119
|
-
* Get
|
|
200
|
+
* Get a value from the request body or return
|
|
201
|
+
* the default value.
|
|
202
|
+
*
|
|
203
|
+
* @example
|
|
204
|
+
* ```ts
|
|
205
|
+
* const name = request.input('name', 'lenon')
|
|
206
|
+
* ```
|
|
120
207
|
*/
|
|
121
|
-
|
|
208
|
+
input(key: string, defaultValue?: any): any;
|
|
122
209
|
/**
|
|
123
|
-
* Get
|
|
210
|
+
* Get a value from the request body or return
|
|
211
|
+
* the default value.
|
|
212
|
+
*
|
|
213
|
+
* @example
|
|
214
|
+
* ```ts
|
|
215
|
+
* const name = request.payload('name', 'lenon')
|
|
216
|
+
* ```
|
|
124
217
|
*/
|
|
125
|
-
|
|
218
|
+
payload(key: string, defaultValue?: any): any;
|
|
126
219
|
/**
|
|
127
|
-
* Get
|
|
220
|
+
* Get only the selected values from the request body.
|
|
221
|
+
*
|
|
222
|
+
* @example
|
|
223
|
+
* ```ts
|
|
224
|
+
* const body = request.only(['name', 'email'])
|
|
225
|
+
* ```
|
|
128
226
|
*/
|
|
129
|
-
|
|
227
|
+
only(keys: string[]): any;
|
|
130
228
|
/**
|
|
131
|
-
* Get
|
|
229
|
+
* Get all the values from the request body except the
|
|
230
|
+
* selected ones.
|
|
231
|
+
*
|
|
232
|
+
* @example
|
|
233
|
+
* ```ts
|
|
234
|
+
* const body = request.except(['name'])
|
|
235
|
+
* ```
|
|
132
236
|
*/
|
|
133
|
-
|
|
237
|
+
except(keys: string[]): any;
|
|
134
238
|
/**
|
|
135
239
|
* Add the hostname and port to the url.
|
|
136
240
|
*/
|
package/src/context/Request.js
CHANGED
|
@@ -14,7 +14,10 @@ export class Request {
|
|
|
14
14
|
/**
|
|
15
15
|
* Get the request id.
|
|
16
16
|
*
|
|
17
|
-
* @example
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* console.log(request.id) // '12345'
|
|
20
|
+
* ```
|
|
18
21
|
*/
|
|
19
22
|
get id() {
|
|
20
23
|
return this.request.id;
|
|
@@ -22,7 +25,10 @@ export class Request {
|
|
|
22
25
|
/**
|
|
23
26
|
* Get the request ip.
|
|
24
27
|
*
|
|
25
|
-
* @example
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* console.log(request.ip) // '192.168.0.1'
|
|
31
|
+
* ```
|
|
26
32
|
*/
|
|
27
33
|
get ip() {
|
|
28
34
|
return this.request.ip;
|
|
@@ -30,15 +36,43 @@ export class Request {
|
|
|
30
36
|
/**
|
|
31
37
|
* Get the request hostname.
|
|
32
38
|
*
|
|
33
|
-
* @example
|
|
39
|
+
* @example
|
|
40
|
+
* ```ts
|
|
41
|
+
* console.log(request.hostname) // 'localhost'
|
|
42
|
+
* ```
|
|
34
43
|
*/
|
|
35
44
|
get hostname() {
|
|
36
45
|
return this.request.hostname;
|
|
37
46
|
}
|
|
47
|
+
/**
|
|
48
|
+
* Get the server port.
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```ts
|
|
52
|
+
* console.log(request.port) // 3000
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
get port() {
|
|
56
|
+
return this.getAddressInfo().port;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Get the http version.
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```ts
|
|
63
|
+
* console.log(request.version) // 1
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
get version() {
|
|
67
|
+
return this.request.raw.httpVersion;
|
|
68
|
+
}
|
|
38
69
|
/**
|
|
39
70
|
* Get the request protocol.
|
|
40
71
|
*
|
|
41
|
-
* @example
|
|
72
|
+
* @example
|
|
73
|
+
* ```ts
|
|
74
|
+
* console.log(request.protocol) // 'http'
|
|
75
|
+
* ```
|
|
42
76
|
*/
|
|
43
77
|
get protocol() {
|
|
44
78
|
return this.request.protocol;
|
|
@@ -46,7 +80,10 @@ export class Request {
|
|
|
46
80
|
/**
|
|
47
81
|
* Get the request method.
|
|
48
82
|
*
|
|
49
|
-
* @example
|
|
83
|
+
* @example
|
|
84
|
+
* ```ts
|
|
85
|
+
* console.log(request.method) // 'GET'
|
|
86
|
+
* ```
|
|
50
87
|
*/
|
|
51
88
|
get method() {
|
|
52
89
|
return this.request.method;
|
|
@@ -54,7 +91,10 @@ export class Request {
|
|
|
54
91
|
/**
|
|
55
92
|
* Get the base url from request.
|
|
56
93
|
*
|
|
57
|
-
* @example
|
|
94
|
+
* @example
|
|
95
|
+
* ```ts
|
|
96
|
+
* console.log(request.baseUrl) // '/users/1'
|
|
97
|
+
* ```
|
|
58
98
|
*/
|
|
59
99
|
get baseUrl() {
|
|
60
100
|
return this.request.url.split('?')[0];
|
|
@@ -62,7 +102,10 @@ export class Request {
|
|
|
62
102
|
/**
|
|
63
103
|
* Get the base url with host and port info from request.
|
|
64
104
|
*
|
|
65
|
-
* @example
|
|
105
|
+
* @example
|
|
106
|
+
* ```ts
|
|
107
|
+
* console.log(request.baseHostUrl) // 'http://localhost:3030/users/1'
|
|
108
|
+
* ```
|
|
66
109
|
*/
|
|
67
110
|
get baseHostUrl() {
|
|
68
111
|
return this.getHostUrlFor(this.baseUrl);
|
|
@@ -70,7 +113,10 @@ export class Request {
|
|
|
70
113
|
/**
|
|
71
114
|
* Get the route url from request.
|
|
72
115
|
*
|
|
73
|
-
* @example
|
|
116
|
+
* @example
|
|
117
|
+
* ```ts
|
|
118
|
+
* console.log(request.routeUrl) // '/users/:id'
|
|
119
|
+
* ```
|
|
74
120
|
*/
|
|
75
121
|
get routeUrl() {
|
|
76
122
|
return this.request.routeOptions.url;
|
|
@@ -78,7 +124,10 @@ export class Request {
|
|
|
78
124
|
/**
|
|
79
125
|
* Get the route url with host and port info from request.
|
|
80
126
|
*
|
|
81
|
-
* @example
|
|
127
|
+
* @example
|
|
128
|
+
* ```ts
|
|
129
|
+
* console.log(request.routeHostUrl) // 'http://localhost:3030/users/:id'
|
|
130
|
+
* ```
|
|
82
131
|
*/
|
|
83
132
|
get routeHostUrl() {
|
|
84
133
|
return this.getHostUrlFor(this.routeUrl);
|
|
@@ -86,7 +135,10 @@ export class Request {
|
|
|
86
135
|
/**
|
|
87
136
|
* Get the original url from request.
|
|
88
137
|
*
|
|
89
|
-
* @example
|
|
138
|
+
* @example
|
|
139
|
+
* ```ts
|
|
140
|
+
* console.log(request.originalUrl) // '/users/1?query=true'
|
|
141
|
+
* ```
|
|
90
142
|
*/
|
|
91
143
|
get originalUrl() {
|
|
92
144
|
return this.request.url;
|
|
@@ -94,67 +146,125 @@ export class Request {
|
|
|
94
146
|
/**
|
|
95
147
|
* Get the original url with host and port info from request.
|
|
96
148
|
*
|
|
97
|
-
* @example
|
|
149
|
+
* @example
|
|
150
|
+
* ```ts
|
|
151
|
+
* console.log(request.originalHostUrl) // 'http://localhost:3000/users/1?query=true'
|
|
152
|
+
* ```
|
|
98
153
|
*/
|
|
99
154
|
get originalHostUrl() {
|
|
100
155
|
return this.getHostUrlFor(this.originalUrl);
|
|
101
156
|
}
|
|
102
157
|
/**
|
|
103
158
|
* Get all body from request.
|
|
159
|
+
*
|
|
160
|
+
* @example
|
|
161
|
+
* ```ts
|
|
162
|
+
* const { name, email } = request.body
|
|
163
|
+
* ```
|
|
104
164
|
*/
|
|
105
165
|
get body() {
|
|
106
166
|
return this.request.body || {};
|
|
107
167
|
}
|
|
108
168
|
/**
|
|
109
169
|
* Get all params from request.
|
|
170
|
+
*
|
|
171
|
+
* @example
|
|
172
|
+
* ```ts
|
|
173
|
+
* const { id } = request.params
|
|
174
|
+
* ```
|
|
110
175
|
*/
|
|
111
176
|
get params() {
|
|
112
177
|
return this.request.params || {};
|
|
113
178
|
}
|
|
114
179
|
/**
|
|
115
180
|
* Get all queries from request.
|
|
181
|
+
*
|
|
182
|
+
* @example
|
|
183
|
+
* ```ts
|
|
184
|
+
* const { page, limit } = request.queries
|
|
185
|
+
* ```
|
|
116
186
|
*/
|
|
117
187
|
get queries() {
|
|
118
188
|
return this.request.query || {};
|
|
119
189
|
}
|
|
120
190
|
/**
|
|
121
191
|
* Get all headers from request.
|
|
192
|
+
*
|
|
193
|
+
* @example
|
|
194
|
+
* ```ts
|
|
195
|
+
* const { accept } = request.headers
|
|
196
|
+
* ```
|
|
122
197
|
*/
|
|
123
198
|
get headers() {
|
|
124
199
|
return this.request.headers || {};
|
|
125
200
|
}
|
|
126
201
|
/**
|
|
127
|
-
* Get the
|
|
202
|
+
* Get a value from the request params or return
|
|
203
|
+
* the default value.
|
|
204
|
+
*
|
|
205
|
+
* @example
|
|
206
|
+
* ```ts
|
|
207
|
+
* const id = request.param('id', '1')
|
|
208
|
+
* ```
|
|
128
209
|
*/
|
|
129
|
-
|
|
130
|
-
return this.
|
|
210
|
+
param(param, defaultValue) {
|
|
211
|
+
return Json.get(this.params, param, defaultValue);
|
|
131
212
|
}
|
|
132
213
|
/**
|
|
133
|
-
* Get the
|
|
214
|
+
* Get a value from the request query param or return
|
|
215
|
+
* the default value.
|
|
216
|
+
*
|
|
217
|
+
* @example
|
|
218
|
+
* ```ts
|
|
219
|
+
* const page = request.query('page', '1')
|
|
220
|
+
* ```
|
|
134
221
|
*/
|
|
135
|
-
|
|
136
|
-
return this.
|
|
222
|
+
query(query, defaultValue) {
|
|
223
|
+
return Json.get(this.queries, query, defaultValue);
|
|
137
224
|
}
|
|
138
225
|
/**
|
|
139
|
-
* Get a value from the request
|
|
226
|
+
* Get a value from the request header or return
|
|
227
|
+
* the default value.
|
|
228
|
+
*
|
|
229
|
+
* @example
|
|
230
|
+
* ```ts
|
|
231
|
+
* const accept = request.header('accept', 'application/json')
|
|
232
|
+
* ```
|
|
140
233
|
*/
|
|
141
|
-
|
|
142
|
-
return this.
|
|
234
|
+
header(header, defaultValue) {
|
|
235
|
+
return Json.get(this.headers, header, defaultValue);
|
|
143
236
|
}
|
|
144
237
|
/**
|
|
145
|
-
* Get a value from the request
|
|
238
|
+
* Get a value from the request body or return
|
|
239
|
+
* the default value.
|
|
240
|
+
*
|
|
241
|
+
* @example
|
|
242
|
+
* ```ts
|
|
243
|
+
* const name = request.input('name', 'lenon')
|
|
244
|
+
* ```
|
|
146
245
|
*/
|
|
147
|
-
|
|
148
|
-
return this.
|
|
246
|
+
input(key, defaultValue) {
|
|
247
|
+
return this.payload(key, defaultValue);
|
|
149
248
|
}
|
|
150
249
|
/**
|
|
151
|
-
* Get a value from the request
|
|
250
|
+
* Get a value from the request body or return
|
|
251
|
+
* the default value.
|
|
252
|
+
*
|
|
253
|
+
* @example
|
|
254
|
+
* ```ts
|
|
255
|
+
* const name = request.payload('name', 'lenon')
|
|
256
|
+
* ```
|
|
152
257
|
*/
|
|
153
|
-
|
|
154
|
-
return this.
|
|
258
|
+
payload(key, defaultValue) {
|
|
259
|
+
return Json.get(this.body, key, defaultValue);
|
|
155
260
|
}
|
|
156
261
|
/**
|
|
157
262
|
* Get only the selected values from the request body.
|
|
263
|
+
*
|
|
264
|
+
* @example
|
|
265
|
+
* ```ts
|
|
266
|
+
* const body = request.only(['name', 'email'])
|
|
267
|
+
* ```
|
|
158
268
|
*/
|
|
159
269
|
only(keys) {
|
|
160
270
|
const body = {};
|
|
@@ -167,7 +277,13 @@ export class Request {
|
|
|
167
277
|
return body;
|
|
168
278
|
}
|
|
169
279
|
/**
|
|
170
|
-
* Get all the values from the request body except the
|
|
280
|
+
* Get all the values from the request body except the
|
|
281
|
+
* selected ones.
|
|
282
|
+
*
|
|
283
|
+
* @example
|
|
284
|
+
* ```ts
|
|
285
|
+
* const body = request.except(['name'])
|
|
286
|
+
* ```
|
|
171
287
|
*/
|
|
172
288
|
except(keys) {
|
|
173
289
|
const body = {};
|
|
@@ -179,18 +295,6 @@ export class Request {
|
|
|
179
295
|
});
|
|
180
296
|
return body;
|
|
181
297
|
}
|
|
182
|
-
/**
|
|
183
|
-
* Get a value from the request body or the default value.
|
|
184
|
-
*/
|
|
185
|
-
input(key, defaultValue) {
|
|
186
|
-
return this.payload(key, defaultValue);
|
|
187
|
-
}
|
|
188
|
-
/**
|
|
189
|
-
* Get a value from the request body or the default value.
|
|
190
|
-
*/
|
|
191
|
-
payload(key, defaultValue) {
|
|
192
|
-
return Json.get(this.body, key, defaultValue);
|
|
193
|
-
}
|
|
194
298
|
/**
|
|
195
299
|
* Add the hostname and port to the url.
|
|
196
300
|
*/
|