/
response.ts
160 lines (146 loc) · 3.9 KB
/
response.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
import {ParamTypes} from "../../models/ParamTypes";
import {UseParam} from "./useParam";
/**
* Response service.
*
* @decorator
* @operation
* @input
* @response
*/
export function Response(): ParameterDecorator;
export function Response(): ParameterDecorator {
return Res();
}
/**
* Request service.
*
* @alias Response
* @decorator
* @operation
* @input
* @response
*/
export function Res(): ParameterDecorator;
export function Res(): ParameterDecorator {
return UseParam(ParamTypes.RESPONSE);
}
declare global {
namespace TsED {
export interface Response {
headersSent: boolean;
writableEnded: boolean;
writableFinished: boolean;
statusCode: number;
/**
* Set header `field` to `val`, or pass
* an object of header fields.
*
* Examples:
*
* res.set('Foo', ['bar', 'baz']);
* res.set('Accept', 'application/json');
* res.set({ Accept: 'text/plain', 'X-API-Key': 'tobi' });
*
* Aliased as `res.header()`.
*/
set(key: string, value: any): any;
set(headers: {[key: string]: any}): any;
/**
* Set status `code`.
*/
status(code: number): any;
pipe(pipe: any): any;
send(body?: any): any;
/**
* Send JSON response.
*
* Examples:
*
* res.json(null);
* res.json({ user: 'tj' });
* res.status(500).json('oh noes!');
* res.status(404).json('I dont have that');
*/
json(obj: any): any;
/**
* Set _Content-Type_ response header with `type` through `mime.lookup()`
* when it does not contain "/", or set the Content-Type to `type` otherwise.
*
* Examples:
*
* res.type('.html');
* res.type('html');
* res.type('json');
* res.type('application/json');
* res.type('png');
*/
contentType(type: string): this;
/**
* Set the location header to `url`.
*
* The given `url` can also be the name of a mapped url, for
* example by default express supports "back" which redirects
* to the _Referrer_ or _Referer_ headers or "/".
*
* Examples:
*
* res.location('/foo/bar').;
* res.location('http://example.com');
* res.location('../login'); // /blog/post/1 -> /blog/login
*
* Mounting:
*
* When an application is mounted and `res.location()`
* is given a path that does _not_ lead with "/" it becomes
* relative to the mount-point. For example if the application
* is mounted at "/blog", the following would become "/blog/login".
*
* res.location('login');
*
* While the leading slash would result in a location of "/login":
*
* res.location('/login');
*/
location(url: string): this;
/**
* Redirect to the given `url` with optional response `status`
* defaulting to 302.
*
* The resulting `url` is determined by `res.location()`, so
* it will play nicely with mounted apps, relative paths,
* `"back"` etc.
*
* Examples:
*
* res.redirect('/foo/bar');
* res.redirect('http://example.com');
* res.redirect(301, 'http://example.com');
* res.redirect('http://example.com', 301);
* res.redirect('../login'); // /blog/post/1 -> /blog/login
*/
redirect(url: string): void;
redirect(status: number, url: string): void;
redirect(url: string, status: number): void;
}
}
}
/**
* Response service.
*
* @decorator
* @operation
* @input
* @response
*/
export interface Response extends TsED.Response {}
/**
* Response service.
*
* @alias Response
* @decorator
* @operation
* @input
* @response
*/
export interface Res extends TsED.Response {}