UNPKG

1.92 kBTypeScriptView Raw
1import { FastifyLoggerInstance } from './logger'
2import { RawServerBase, RawServerDefault, RawRequestDefaultExpression, RequestBodyDefault, RequestQuerystringDefault, RequestParamsDefault, RequestHeadersDefault } from './utils'
3import { RouteGenericInterface } from './route'
4
5export interface RequestGenericInterface {
6 Body?: RequestBodyDefault;
7 Querystring?: RequestQuerystringDefault;
8 Params?: RequestParamsDefault;
9 Headers?: RequestHeadersDefault;
10}
11
12/**
13 * FastifyRequest is an instance of the standard http or http2 request objects.
14 * It defaults to http.IncomingMessage, and it also extends the relative request object.
15 */
16export interface FastifyRequest<
17 RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
18 RawServer extends RawServerBase = RawServerDefault,
19 RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>,
20> {
21 id: any;
22 params: RouteGeneric['Params'];
23 raw: RawRequest;
24 query: RouteGeneric['Querystring'];
25 log: FastifyLoggerInstance;
26 body: RouteGeneric['Body'];
27
28 /** in order for this to be used the user should ensure they have set the attachValidation option. */
29 validationError?: Error & { validation: any; validationContext: string };
30
31 /**
32 * @deprecated Use `raw` property
33 */
34 readonly req: RawRequest;
35 readonly headers: RawRequest['headers'] & RouteGeneric['Headers']; // this enables the developer to extend the existing http(s|2) headers list
36 readonly ip: string;
37 readonly ips?: string[];
38 readonly hostname: string;
39 readonly url: string;
40 readonly protocol: 'http' | 'https';
41 readonly method: string;
42 readonly routerPath: string;
43 readonly routerMethod: string;
44 readonly is404: boolean;
45 readonly socket: RawRequest['socket'];
46
47 // Prefer `socket` over deprecated `connection` property in node 13.0.0 or higher
48 // @deprecated
49 readonly connection: RawRequest['socket'];
50}