fastify
- Version 5.3.2
- Published
- 2.6 MB
- 15 dependencies
- MIT license
Install
npm i fastify
yarn add fastify
pnpm add fastify
Overview
Fast and low overhead web framework, for Node.js
Index
Variables
Functions
Interfaces
FastifyInstance
- [Symbol.asyncDispose]()
- addConstraintStrategy()
- addresses()
- addSchema()
- after()
- close()
- decorate
- decorateReply
- decorateRequest
- getDecorator()
- getSchema()
- getSchemas()
- hasConstraintStrategy()
- hasDecorator()
- hasPlugin()
- hasReplyDecorator()
- hasRequestDecorator()
- inject()
- listen()
- listeningOrigin
- log
- pluginName
- prefix
- ready()
- register
- route()
- routing()
- server
- version
- withTypeProvider()
FastifyReply
- callNotFound()
- code()
- compileSerializationSchema()
- elapsedTime
- getDecorator()
- getHeader()
- getHeaders()
- getSerializationFunction()
- hasHeader()
- hasTrailer()
- header()
- headers()
- hijack()
- log
- raw
- redirect()
- removeHeader()
- removeTrailer()
- request
- routeOptions
- send()
- sent
- serialize()
- serializeInput()
- serializer()
- server
- status()
- statusCode
- then()
- trailer
- type()
- writeEarlyHints()
Type Aliases
- ConstructorAction
- ContextConfigDefault
- FastifyBodyParser
- FastifyContentTypeParser
- FastifyErrorCodes
- FastifyHttp2Options
- FastifyHttp2SecureOptions
- FastifyHttpOptions
- FastifyHttpsOptions
- FastifyLogFn
- FastifyLoggerInstance
- FastifyPlugin
- FastifyPluginAsync
- FastifyPluginCallback
- FastifyPluginOptions
- FastifyRegisterOptions
- FastifySchemaCompiler
- FastifyServerFactoryHandler
- FastifyServerOptions
- getDefaultJsonParser
- hasContentTypeParser
- HookHandlerDoneFunction
- HTTPMethods
- LogLevel
- ProtoAction
- RawReplyDefaultExpression
- RawRequestDefaultExpression
- RawServerBase
- RawServerDefault
- RequestBodyDefault
- RequestHeadersDefault
- RequestParamsDefault
- RequestQuerystringDefault
- RouteHandler
- RouteHandlerMethod
- SafePromiseLike
- ValidationResult
Variables
variable errorCodes
const errorCodes: FastifyErrorCodes;
variable fastify
const fastify: typeof import('/fastify.d.ts');
Functions
function fastify
fastify: typeof import('/fastify.d.ts');
Fastify factory function for the standard fastify http, https, or http2 server instance.
The default function utilizes http
Parameter opts
Fastify server options
Returns
Fastify server instance
Interfaces
interface AddContentTypeParser
interface AddContentTypeParser< RawServer extends RawServerBase = RawServerDefault, RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>, RouteGeneric extends RouteGenericInterface = RouteGenericInterface, SchemaCompiler extends FastifySchema = FastifySchema, TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault> {}
Natively, Fastify only supports 'application/json' and 'text/plain' content types. The default charset is utf-8. If you need to support different content types, you can use the addContentTypeParser API. The default JSON and/or plain text parser can be changed.
call signature
( contentType: string | string[] | RegExp, opts: { bodyLimit?: number; }, parser: FastifyContentTypeParser< RawServer, RawRequest, RouteGeneric, SchemaCompiler, TypeProvider >): void;
call signature
( contentType: string | string[] | RegExp, parser: FastifyContentTypeParser< RawServer, RawRequest, RouteGeneric, SchemaCompiler, TypeProvider >): void;
call signature
<parseAs extends string | Buffer>( contentType: string | string[] | RegExp, opts: { parseAs: parseAs extends Buffer ? 'buffer' : 'string'; bodyLimit?: number; }, parser: FastifyBodyParser< parseAs, RawServer, RawRequest, RouteGeneric, SchemaCompiler, TypeProvider >): void;
interface ConnectionError
interface ConnectionError extends Error {}
property bytesParsed
bytesParsed: number;
property code
code: string;
property rawPacket
rawPacket: { type: string; data: number[];};
interface DoneFuncWithErrOrRes
interface DoneFuncWithErrOrRes {}
call signature
(): void;
call signature
<TError extends Error = FastifyError>(err: TError): void;
call signature
(err: null, res: unknown): void;
interface FastifyBaseLogger
interface FastifyBaseLogger extends pino.BaseLogger {}
method child
child: ( bindings: pino.Bindings, options?: pino.ChildLoggerOptions) => FastifyBaseLogger;
interface FastifyContextConfig
interface FastifyContextConfig {}
interface FastifyContextConfig
interface FastifyContextConfig {}
interface FastifyInstance
interface FastifyInstance< RawServer extends RawServerBase = RawServerDefault, RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>, RawReply extends RawReplyDefaultExpression<RawServer> = RawReplyDefaultExpression<RawServer>, Logger extends FastifyBaseLogger = FastifyBaseLogger, TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault> {}
Fastify server instance. Returned by the core
fastify()
method.
property decorate
decorate: DecorationMethod< FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>>;
property decorateReply
decorateReply: DecorationMethod< FastifyReply, FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>>;
property decorateRequest
decorateRequest: DecorationMethod< FastifyRequest, FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>>;
property listeningOrigin
listeningOrigin: string;
property log
log: Logger;
property pluginName
pluginName: string;
property prefix
prefix: string;
property register
register: FastifyRegister< FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider> & SafePromiseLike<undefined>>;
property server
server: RawServer;
property version
version: string;
method [Symbol.asyncDispose]
[Symbol.asyncDispose]: () => Promise<undefined>;
Alias for
method addConstraintStrategy
addConstraintStrategy: ( strategy: ConstraintStrategy<FindMyWayVersion<RawServer>, unknown>) => void;
method addresses
addresses: () => AddressInfo[];
method addSchema
addSchema: ( schema: unknown) => FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
method after
after: { (): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider> & SafePromiseLike<undefined>; (afterListener: (err: Error) => void): FastifyInstance< RawServer, RawRequest, RawReply, Logger, TypeProvider >;};
method close
close: { (): Promise<undefined>; (closeListener: () => void): undefined };
method getDecorator
getDecorator: <T>(name: string | symbol) => T;
method getSchema
getSchema: (schemaId: string) => unknown;
method getSchemas
getSchemas: () => Record<string, unknown>;
method hasConstraintStrategy
hasConstraintStrategy: (strategyName: string) => boolean;
method hasDecorator
hasDecorator: (decorator: string | symbol) => boolean;
method hasPlugin
hasPlugin: (name: string) => boolean;
method hasReplyDecorator
hasReplyDecorator: (decorator: string | symbol) => boolean;
method hasRequestDecorator
hasRequestDecorator: (decorator: string | symbol) => boolean;
method inject
inject: { (opts: InjectOptions | string, cb: LightMyRequestCallback): void; (opts: any): Promise<LightMyRequestResponse>; (): LightMyRequestChain;};
method listen
listen: { ( opts: FastifyListenOptions, callback: (err: Error | null, address: string) => void ): void; (opts?: FastifyListenOptions): Promise<string>; (callback: (err: Error, address: string) => void): void;};
method ready
ready: { (): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider> & SafePromiseLike<undefined>; (readyListener: (err: Error) => void | Promise<void>): FastifyInstance< RawServer, RawRequest, RawReply, Logger, TypeProvider >;};
method route
route: < RouteGeneric extends RouteGenericInterface = RouteGenericInterface, ContextConfig = unknown>() => any;
method routing
routing: (req: RawRequest, res: RawReply) => void;
method withTypeProvider
withTypeProvider: <Provider extends FastifyTypeProvider>() => FastifyInstance< RawServer, RawRequest, RawReply, Logger, Provider>;
interface FastifyInstance
interface FastifyInstance {}
property typedTestProperty
typedTestProperty: boolean;
property typedTestPropertyGetterSetter
typedTestPropertyGetterSetter: string;
method typedTestMethod
typedTestMethod: (x: string) => string;
interface FastifyListenOptions
interface FastifyListenOptions {}
property backlog
backlog?: number;
Specify the maximum length of the queue of pending connections. The actual length will be determined by the OS through sysctl settings such as
tcp_max_syn_backlog
andsomaxconn
on Linux. Default to511
.
property exclusive
exclusive?: boolean;
Default to
false
.
property host
host?: string;
Default to
localhost
.
property ipv6Only
ipv6Only?: boolean;
For TCP servers, setting
ipv6Only
totrue
will disable dual-stack support, i.e., binding to host::
won't make0.0.0.0
be bound. Default tofalse
.
property listenTextResolver
listenTextResolver?: (address: string) => string;
Function that resolves text to log after server has been successfully started
Parameter address
property path
path?: string;
Will be ignored if
port
is specified.See Also
[Identifying paths for IPC connections](https://nodejs.org/api/net.html#identifying-paths-for-ipc-connections).
property port
port?: number;
Default to
0
(picks the first available open port).
property readableAll
readableAll?: boolean;
For IPC servers makes the pipe readable for all users. Default to
false
.
property signal
signal?: AbortSignal;
An AbortSignal that may be used to close a listening server. This option is available only in Node.js v15.6.0 and greater
property writableAll
writableAll?: boolean;
For IPC servers makes the pipe writable for all users. Default to
false
.
interface FastifyLoggerOptions
interface FastifyLoggerOptions< RawServer extends RawServerBase = RawServerDefault, RawRequest extends FastifyRequest< RouteGenericInterface, RawServer, RawRequestDefaultExpression<RawServer>, FastifySchema, FastifyTypeProvider > = FastifyRequest< RouteGenericInterface, RawServer, RawRequestDefaultExpression<RawServer>, FastifySchema, FastifyTypeProviderDefault >, RawReply extends FastifyReply< RouteGenericInterface, RawServer, RawRequestDefaultExpression<RawServer>, RawReplyDefaultExpression<RawServer>, ContextConfigDefault, FastifySchema, FastifyTypeProvider > = FastifyReply< RouteGenericInterface, RawServer, RawRequestDefaultExpression<RawServer>, RawReplyDefaultExpression<RawServer>, ContextConfigDefault, FastifySchema, FastifyTypeProviderDefault >> {}
Fastify Custom Logger options.
property file
file?: string;
property genReqId
genReqId?: (req: RawRequest) => string;
property level
level?: string;
property serializers
serializers?: { req?: (req: RawRequest) => { method?: string; url?: string; version?: string; host?: string; remoteAddress?: string; remotePort?: number; [key: string]: unknown; }; err?: (err: FastifyError) => { type: string; message: string; stack: string; [key: string]: unknown; }; res?: (res: ResSerializerReply<RawServer, RawReply>) => { statusCode?: string | number; [key: string]: unknown; };};
property stream
stream?: FastifyLoggerStreamDestination;
interface FastifyRegister
interface FastifyRegister< T = void, RawServer extends RawServerBase = RawServerDefault, TypeProviderDefault extends FastifyTypeProvider = FastifyTypeProvider, LoggerDefault extends FastifyBaseLogger = FastifyBaseLogger> {}
FastifyRegister
Function for adding a plugin to fastify. The options are inferred from the passed in FastifyPlugin parameter.
call signature
< Server extends RawServerBase = RawServer, TypeProvider extends FastifyTypeProvider = TypeProviderDefault, Logger extends FastifyBaseLogger = LoggerDefault>( plugin: FastifyPluginCallback< FastifyPluginOptions, Server, TypeProvider, Logger >): T;
call signature
< Options extends FastifyPluginOptions, Server extends RawServerBase = RawServer, TypeProvider extends FastifyTypeProvider = TypeProviderDefault, Logger extends FastifyBaseLogger = LoggerDefault>( plugin: FastifyPluginCallback<Options, Server, TypeProvider, Logger>, opts: FastifyRegisterOptions<Options>): T;
call signature
< Server extends RawServerBase = RawServer, TypeProvider extends FastifyTypeProvider = TypeProviderDefault, Logger extends FastifyBaseLogger = LoggerDefault>( plugin: FastifyPluginAsync< FastifyPluginOptions, Server, TypeProvider, Logger >): T;
call signature
< Options extends FastifyPluginOptions, Server extends RawServerBase = RawServer, TypeProvider extends FastifyTypeProvider = TypeProviderDefault, Logger extends FastifyBaseLogger = LoggerDefault>( plugin: FastifyPluginAsync<Options, Server, TypeProvider, Logger>, opts: FastifyRegisterOptions<Options>): T;
call signature
< Server extends RawServerBase = RawServer, TypeProvider extends FastifyTypeProvider = TypeProviderDefault, Logger extends FastifyBaseLogger = LoggerDefault>( plugin: | FastifyPluginCallback< FastifyPluginOptions, Server, TypeProvider, Logger > | FastifyPluginAsync<FastifyPluginOptions, Server, TypeProvider, Logger> | Promise<{ default: FastifyPluginCallback< FastifyPluginOptions, Server, TypeProvider, Logger >; }> | Promise<{ default: FastifyPluginAsync< FastifyPluginOptions, Server, TypeProvider, Logger >; }>): T;
call signature
< Options extends FastifyPluginOptions, Server extends RawServerBase = RawServer, TypeProvider extends FastifyTypeProvider = TypeProviderDefault, Logger extends FastifyBaseLogger = LoggerDefault>( plugin: | FastifyPluginCallback<Options, Server, TypeProvider, Logger> | FastifyPluginAsync<Options, Server, TypeProvider, Logger> | Promise<{ default: FastifyPluginCallback< Options, Server, TypeProvider, Logger >; }> | Promise<{ default: FastifyPluginAsync<Options, Server, TypeProvider, Logger>; }>, opts: FastifyRegisterOptions<Options>): T;
interface FastifyReply
interface FastifyReply< RouteGeneric extends RouteGenericInterface = RouteGenericInterface, RawServer extends RawServerBase = RawServerDefault, RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>, RawReply extends RawReplyDefaultExpression<RawServer> = RawReplyDefaultExpression<RawServer>, ContextConfig = ContextConfigDefault, SchemaCompiler extends FastifySchema = FastifySchema, TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault, ReplyType extends FastifyReplyType = ResolveFastifyReplyType< TypeProvider, SchemaCompiler, RouteGeneric >> {}
FastifyReply is an instance of the standard http or http2 reply types. It defaults to http.ServerResponse, and it also extends the relative reply object.
property elapsedTime
elapsedTime: number;
property log
log: FastifyBaseLogger;
property raw
raw: RawReply;
property request
request: FastifyRequest< RouteGeneric, RawServer, RawRequest, SchemaCompiler, TypeProvider>;
property routeOptions
readonly routeOptions: Readonly< RequestRouteOptions<ContextConfig, SchemaCompiler>>;
property sent
sent: boolean;
property server
server: FastifyInstance;
property statusCode
statusCode: number;
property trailer
trailer: ( key: string, fn: | (( reply: FastifyReply< RouteGeneric, RawServer, RawRequest, RawReply, ContextConfig, SchemaCompiler, TypeProvider >, payload: string | Buffer | null ) => Promise<string>) | (( reply: FastifyReply< RouteGeneric, RawServer, RawRequest, RawReply, ContextConfig, SchemaCompiler, TypeProvider >, payload: string | Buffer | null, done: (err: Error | null, value?: string) => void ) => void)) => FastifyReply< RouteGeneric, RawServer, RawRequest, RawReply, ContextConfig, SchemaCompiler, TypeProvider>;
method callNotFound
callNotFound: () => void;
method code
code: <Code extends ReplyKeysToCodes<keyof RouteGeneric['Reply']>>( statusCode: Code) => FastifyReply< RouteGeneric, RawServer, RawRequest, RawReply, ContextConfig, SchemaCompiler, TypeProvider, ResolveReplyTypeWithRouteGeneric< RouteGeneric['Reply'], Code, SchemaCompiler, TypeProvider >>;
method compileSerializationSchema
compileSerializationSchema: ( schema: { [key: string]: unknown }, httpStatus?: string, contentType?: string) => (payload: { [key: string]: unknown }) => string;
method getDecorator
getDecorator: <T>(name: string | symbol) => T;
method getHeader
getHeader: (key: HttpHeader) => number | string | string[] | undefined;
method getHeaders
getHeaders: () => Record<HttpHeader, number | string | string[] | undefined>;
method getSerializationFunction
getSerializationFunction: { (httpStatus: string, contentType?: string): (payload: { [key: string]: unknown; }) => string; (schema: { [key: string]: unknown }): (payload: { [key: string]: unknown; }) => string;};
method hasHeader
hasHeader: (key: HttpHeader) => boolean;
method hasTrailer
hasTrailer: (key: string) => boolean;
method header
header: ( key: HttpHeader, value: any) => FastifyReply< RouteGeneric, RawServer, RawRequest, RawReply, ContextConfig, SchemaCompiler, TypeProvider>;
method headers
headers: ( values: Partial<Record<HttpHeader, number | string | string[] | undefined>>) => FastifyReply< RouteGeneric, RawServer, RawRequest, RawReply, ContextConfig, SchemaCompiler, TypeProvider>;
method hijack
hijack: () => FastifyReply< RouteGeneric, RawServer, RawRequest, RawReply, ContextConfig, SchemaCompiler, TypeProvider>;
method redirect
redirect: ( url: string, statusCode?: number) => FastifyReply< RouteGeneric, RawServer, RawRequest, RawReply, ContextConfig, SchemaCompiler, TypeProvider>;
method removeHeader
removeHeader: ( key: HttpHeader) => FastifyReply< RouteGeneric, RawServer, RawRequest, RawReply, ContextConfig, SchemaCompiler, TypeProvider>;
method removeTrailer
removeTrailer: ( key: string) => FastifyReply< RouteGeneric, RawServer, RawRequest, RawReply, ContextConfig, SchemaCompiler, TypeProvider>;
method send
send: ( payload?: ReplyType) => FastifyReply< RouteGeneric, RawServer, RawRequest, RawReply, ContextConfig, SchemaCompiler, TypeProvider>;
method serialize
serialize: (payload: any) => string | ArrayBuffer | Buffer;
method serializeInput
serializeInput: { ( input: { [key: string]: unknown }, schema: { [key: string]: unknown }, httpStatus?: string, contentType?: string ): string; ( input: { [key: string]: unknown }, httpStatus: string, contentType?: string ): unknown;};
method serializer
serializer: ( fn: (payload: any) => string) => FastifyReply< RouteGeneric, RawServer, RawRequest, RawReply, ContextConfig, SchemaCompiler, TypeProvider>;
method status
status: <Code extends ReplyKeysToCodes<keyof RouteGeneric['Reply']>>( statusCode: Code) => FastifyReply< RouteGeneric, RawServer, RawRequest, RawReply, ContextConfig, SchemaCompiler, TypeProvider, ResolveReplyTypeWithRouteGeneric< RouteGeneric['Reply'], Code, SchemaCompiler, TypeProvider >>;
method then
then: (fulfilled: () => void, rejected: (err: Error) => void) => void;
method type
type: ( contentType: string) => FastifyReply< RouteGeneric, RawServer, RawRequest, RawReply, ContextConfig, SchemaCompiler, TypeProvider>;
method writeEarlyHints
writeEarlyHints: ( hints: Record<string, string | string[]>, callback?: () => void) => void;
interface FastifyReply
interface FastifyReply {}
property testProp
testProp: TestType;
interface FastifyReply
interface FastifyReply {}
property typedTestReplyProperty
typedTestReplyProperty: boolean;
property typedTestReplyPropertyGetterSetter
typedTestReplyPropertyGetterSetter: string;
method typedTestReplyMethod
typedTestReplyMethod: (x: string) => string;
interface FastifyReplyContext
interface FastifyReplyContext<ContextConfig = ContextConfigDefault> {}
property config
config: FastifyContextConfig & FastifyRouteConfig & ContextConfig;
Deprecated
Use Reply#routeOptions#config or Reply#routeOptions#schema instead
interface FastifyRequest
interface FastifyRequest< RouteGeneric extends RouteGenericInterface = RouteGenericInterface, RawServer extends RawServerBase = RawServerDefault, RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>, SchemaCompiler extends FastifySchema = FastifySchema, TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault, ContextConfig = ContextConfigDefault, Logger extends FastifyBaseLogger = FastifyBaseLogger, RequestType extends FastifyRequestType = ResolveFastifyRequestType< TypeProvider, SchemaCompiler, RouteGeneric >> {}
FastifyRequest is an instance of the standard http or http2 request objects. It defaults to http.IncomingMessage, and it also extends the relative request object.
property body
body: RequestType['body'];
property headers
headers: RawRequest['headers'] & RequestType['headers'];
property host
readonly host: string;
property hostname
readonly hostname: string;
property id
id: string;
property ip
readonly ip: string;
property ips
readonly ips?: string[];
property is404
readonly is404: boolean;
property log
log: Logger;
property method
readonly method: string;
property originalUrl
readonly originalUrl: string;
property params
params: RequestType['params'];
property port
readonly port: number;
property protocol
readonly protocol: 'http' | 'https';
property query
query: RequestType['query'];
property raw
raw: RawRequest;
property req
readonly req: RawRequest & RouteGeneric['Headers'];
Deprecated
Use
raw
property
property routeOptions
readonly routeOptions: Readonly< RequestRouteOptions<ContextConfig, SchemaCompiler>>;
property server
server: FastifyInstance;
property socket
readonly socket: RawRequest['socket'];
property url
readonly url: string;
property validationError
validationError?: Error & { validation: any; validationContext: string };
in order for this to be used the user should ensure they have set the attachValidation option.
method compileValidationSchema
compileValidationSchema: ( schema: { [key: string]: any }, httpPart?: HTTPRequestPart) => ValidationFunction;
method getDecorator
getDecorator: <T>(name: string | symbol) => T;
method getValidationFunction
getValidationFunction: { (httpPart: HTTPRequestPart): ValidationFunction; (schema: { [key: string]: any }): ValidationFunction;};
method setDecorator
setDecorator: <T = unknown>(name: string | symbol, value: T) => void;
method validateInput
validateInput: { ( input: any, schema: { [key: string]: any }, httpPart?: HTTPRequestPart ): boolean; (input: any, httpPart?: HTTPRequestPart): boolean;};
interface FastifyRequest
interface FastifyRequest {}
property testProp
testProp: TestType;
interface FastifyRequest
interface FastifyRequest {}
property typedTestRequestProperty
typedTestRequestProperty: boolean;
property typedTestRequestPropertyGetterSetter
typedTestRequestPropertyGetterSetter: string;
method typedTestRequestMethod
typedTestRequestMethod: (x: string) => string;
interface FastifyRequest
interface FastifyRequest< RouteGeneric, RawServer, RawRequest, SchemaCompiler, TypeProvider, ContextConfig, Logger, RequestType> {}
property message
message: ContextConfig extends { includeMessage: true } ? string : null;
interface FastifyRequestContext
interface FastifyRequestContext<ContextConfig = ContextConfigDefault> {}
Route context object. Properties defined here will be available in the route's handler
property config
config: FastifyContextConfig & FastifyRouteConfig & ContextConfig;
Deprecated
Use Request#routeOptions#config or Request#routeOptions#schema instead
interface FastifySchema
interface FastifySchema {}
Schemas in Fastify follow the JSON-Schema standard. For this reason we have opted to not ship strict schema based types. Instead we provide an example in our documentation on how to solve this problem. Check it out here: https://github.com/fastify/fastify/blob/main/docs/Reference/TypeScript.md#json-schema
property body
body?: unknown;
property headers
headers?: unknown;
property params
params?: unknown;
property querystring
querystring?: unknown;
property response
response?: unknown;
interface FastifyServerFactory
interface FastifyServerFactory<RawServer extends RawServerBase = RawServerDefault> {}
call signature
( handler: FastifyServerFactoryHandler<RawServer>, opts: Record<string, unknown>): RawServer;
interface FastifyTypeProvider
interface FastifyTypeProvider {}
property schema
readonly schema: unknown;
property serializer
readonly serializer: unknown;
property validator
readonly validator: unknown;
interface FastifyTypeProviderDefault
interface FastifyTypeProviderDefault extends FastifyTypeProvider {}
interface onCloseAsyncHookHandler
interface onCloseAsyncHookHandler< RawServer extends RawServerBase = RawServerDefault, RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>, RawReply extends RawReplyDefaultExpression<RawServer> = RawReplyDefaultExpression<RawServer>, Logger extends FastifyBaseLogger = FastifyBaseLogger, TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault> {}
call signature
( this: FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>, instance: FastifyInstance< RawServer, RawRequest, RawReply, Logger, TypeProvider >): Promise<unknown>;
interface onCloseHookHandler
interface onCloseHookHandler< RawServer extends RawServerBase = RawServerDefault, RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>, RawReply extends RawReplyDefaultExpression<RawServer> = RawReplyDefaultExpression<RawServer>, Logger extends FastifyBaseLogger = FastifyBaseLogger, TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault> {}
Triggered when fastify.close() is invoked to stop the server. It is useful when plugins need a "shutdown" event, for example to close an open connection to a database.
call signature
( this: FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>, instance: FastifyInstance< RawServer, RawRequest, RawReply, Logger, TypeProvider >, done: HookHandlerDoneFunction): void;
interface onErrorAsyncHookHandler
interface onErrorAsyncHookHandler< RawServer extends RawServerBase = RawServerDefault, RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>, RawReply extends RawReplyDefaultExpression<RawServer> = RawReplyDefaultExpression<RawServer>, RouteGeneric extends RouteGenericInterface = RouteGenericInterface, ContextConfig = ContextConfigDefault, TError extends Error = FastifyError, SchemaCompiler extends FastifySchema = FastifySchema, TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault, Logger extends FastifyBaseLogger = FastifyBaseLogger> {}
call signature
( this: FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>, request: FastifyRequest< RouteGeneric, RawServer, RawRequest, SchemaCompiler, TypeProvider, ContextConfig, Logger >, reply: FastifyReply< RouteGeneric, RawServer, RawRequest, RawReply, ContextConfig, SchemaCompiler, TypeProvider >, error: TError): Promise<unknown>;
interface onErrorHookHandler
interface onErrorHookHandler< RawServer extends RawServerBase = RawServerDefault, RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>, RawReply extends RawReplyDefaultExpression<RawServer> = RawReplyDefaultExpression<RawServer>, RouteGeneric extends RouteGenericInterface = RouteGenericInterface, ContextConfig = ContextConfigDefault, TError extends Error = FastifyError, SchemaCompiler extends FastifySchema = FastifySchema, TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault, Logger extends FastifyBaseLogger = FastifyBaseLogger> {}
This hook is useful if you need to do some custom error logging or add some specific header in case of error. It is not intended for changing the error, and calling reply.send will throw an exception. This hook will be executed only after the customErrorHandler has been executed, and only if the customErrorHandler sends an error back to the user (Note that the default customErrorHandler always sends the error back to the user). Notice: unlike the other hooks, pass an error to the done function is not supported.
call signature
( this: FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>, request: FastifyRequest< RouteGeneric, RawServer, RawRequest, SchemaCompiler, TypeProvider, ContextConfig, Logger >, reply: FastifyReply< RouteGeneric, RawServer, RawRequest, RawReply, ContextConfig, SchemaCompiler, TypeProvider >, error: TError, done: () => void): void;
interface onListenAsyncHookHandler
interface onListenAsyncHookHandler< RawServer extends RawServerBase = RawServerDefault, RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>, RawReply extends RawReplyDefaultExpression<RawServer> = RawReplyDefaultExpression<RawServer>, Logger extends FastifyBaseLogger = FastifyBaseLogger, TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault> {}
call signature
( this: FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>): Promise<unknown>;
interface onListenHookHandler
interface onListenHookHandler< RawServer extends RawServerBase = RawServerDefault, RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>, RawReply extends RawReplyDefaultExpression<RawServer> = RawReplyDefaultExpression<RawServer>, Logger extends FastifyBaseLogger = FastifyBaseLogger, TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault> {}
Triggered when fastify.listen() is invoked to start the server. It is useful when plugins need a "onListen" event, for example to run logics after the server start listening for requests.
call signature
( this: FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>, done: HookHandlerDoneFunction): void;
interface onReadyAsyncHookHandler
interface onReadyAsyncHookHandler< RawServer extends RawServerBase = RawServerDefault, RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>, RawReply extends RawReplyDefaultExpression<RawServer> = RawReplyDefaultExpression<RawServer>, Logger extends FastifyBaseLogger = FastifyBaseLogger, TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault> {}
call signature
( this: FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>): Promise<unknown>;
interface onReadyHookHandler
interface onReadyHookHandler< RawServer extends RawServerBase = RawServerDefault, RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>, RawReply extends RawReplyDefaultExpression<RawServer> = RawReplyDefaultExpression<RawServer>, Logger extends FastifyBaseLogger = FastifyBaseLogger, TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault> {}
Triggered when fastify.listen() or fastify.ready() is invoked to start the server. It is useful when plugins need a "ready" event, for example to load data before the server start listening for requests.
call signature
( this: FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>, done: HookHandlerDoneFunction): void;
interface onRegisterHookHandler
interface onRegisterHookHandler< RawServer extends RawServerBase = RawServerDefault, RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>, RawReply extends RawReplyDefaultExpression<RawServer> = RawReplyDefaultExpression<RawServer>, Logger extends FastifyBaseLogger = FastifyBaseLogger, TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault, Options extends FastifyPluginOptions = FastifyPluginOptions> {}
Triggered when a new plugin is registered and a new encapsulation context is created. The hook will be executed before the registered code. This hook can be useful if you are developing a plugin that needs to know when a plugin context is formed, and you want to operate in that specific context. Note: This hook will not be called if a plugin is wrapped inside fastify-plugin.
call signature
( this: FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>, instance: FastifyInstance< RawServer, RawRequest, RawReply, Logger, TypeProvider >, opts: RegisterOptions & Options): Promise<unknown> | void;
interface onRequestAbortAsyncHookHandler
interface onRequestAbortAsyncHookHandler< RawServer extends RawServerBase = RawServerDefault, RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>, RawReply extends RawReplyDefaultExpression<RawServer> = RawReplyDefaultExpression<RawServer>, RouteGeneric extends RouteGenericInterface = RouteGenericInterface, ContextConfig = ContextConfigDefault, SchemaCompiler extends FastifySchema = FastifySchema, TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault, Logger extends FastifyBaseLogger = FastifyBaseLogger> {}
call signature
( this: FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>, request: FastifyRequest< RouteGeneric, RawServer, RawRequest, SchemaCompiler, TypeProvider, ContextConfig, Logger >): Promise<unknown>;
interface onRequestAbortHookHandler
interface onRequestAbortHookHandler< RawServer extends RawServerBase = RawServerDefault, RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>, RawReply extends RawReplyDefaultExpression<RawServer> = RawReplyDefaultExpression<RawServer>, RouteGeneric extends RouteGenericInterface = RouteGenericInterface, ContextConfig = ContextConfigDefault, SchemaCompiler extends FastifySchema = FastifySchema, TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault, Logger extends FastifyBaseLogger = FastifyBaseLogger> {}
onRequestAbort
is useful if you need to monitor the if the client aborts the request (if therequest.raw.aborted
property is set totrue
). TheonRequestAbort
hook is executed when a client closes the connection before the entire request has been received. Therefore, you will not be able to send data to the client. Notice: client abort detection is not completely reliable. See: https://github.com/fastify/fastify/blob/main/docs/Guides/Detecting-When-Clients-Abort.md
call signature
( this: FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>, request: FastifyRequest< RouteGeneric, RawServer, RawRequest, SchemaCompiler, TypeProvider, ContextConfig, Logger >, done: HookHandlerDoneFunction): void;
interface onRequestAsyncHookHandler
interface onRequestAsyncHookHandler< RawServer extends RawServerBase = RawServerDefault, RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>, RawReply extends RawReplyDefaultExpression<RawServer> = RawReplyDefaultExpression<RawServer>, RouteGeneric extends RouteGenericInterface = RouteGenericInterface, ContextConfig = ContextConfigDefault, SchemaCompiler extends FastifySchema = FastifySchema, TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault, Logger extends FastifyBaseLogger = FastifyBaseLogger> {}
call signature
( this: FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>, request: FastifyRequest< RouteGeneric, RawServer, RawRequest, SchemaCompiler, TypeProvider, ContextConfig, Logger >, reply: FastifyReply< RouteGeneric, RawServer, RawRequest, RawReply, ContextConfig, SchemaCompiler, TypeProvider >): Promise<unknown>;
interface onRequestHookHandler
interface onRequestHookHandler< RawServer extends RawServerBase = RawServerDefault, RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>, RawReply extends RawReplyDefaultExpression<RawServer> = RawReplyDefaultExpression<RawServer>, RouteGeneric extends RouteGenericInterface = RouteGenericInterface, ContextConfig = ContextConfigDefault, SchemaCompiler extends FastifySchema = FastifySchema, TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault, Logger extends FastifyBaseLogger = FastifyBaseLogger> {}
onRequest
is the first hook to be executed in the request lifecycle. There was no previous hook, the next hook will bepreParsing
. Notice: in theonRequest
hook, request.body will always be null, because the body parsing happens before thepreHandler
hook.
call signature
( this: FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>, request: FastifyRequest< RouteGeneric, RawServer, RawRequest, SchemaCompiler, TypeProvider, ContextConfig, Logger >, reply: FastifyReply< RouteGeneric, RawServer, RawRequest, RawReply, ContextConfig, SchemaCompiler, TypeProvider >, done: HookHandlerDoneFunction): void;
interface onResponseAsyncHookHandler
interface onResponseAsyncHookHandler< RawServer extends RawServerBase = RawServerDefault, RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>, RawReply extends RawReplyDefaultExpression<RawServer> = RawReplyDefaultExpression<RawServer>, RouteGeneric extends RouteGenericInterface = RouteGenericInterface, ContextConfig = ContextConfigDefault, SchemaCompiler extends FastifySchema = FastifySchema, TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault, Logger extends FastifyBaseLogger = FastifyBaseLogger> {}
call signature
( this: FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>, request: FastifyRequest< RouteGeneric, RawServer, RawRequest, SchemaCompiler, TypeProvider, ContextConfig, Logger >, reply: FastifyReply< RouteGeneric, RawServer, RawRequest, RawReply, ContextConfig, SchemaCompiler, TypeProvider >): Promise<unknown>;
interface onResponseHookHandler
interface onResponseHookHandler< RawServer extends RawServerBase = RawServerDefault, RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>, RawReply extends RawReplyDefaultExpression<RawServer> = RawReplyDefaultExpression<RawServer>, RouteGeneric extends RouteGenericInterface = RouteGenericInterface, ContextConfig = ContextConfigDefault, SchemaCompiler extends FastifySchema = FastifySchema, TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault, Logger extends FastifyBaseLogger = FastifyBaseLogger> {}
onResponse
is the seventh and last hook in the request hook lifecycle. The previous hook wasonSend
, there is no next hook. The onResponse hook is executed when a response has been sent, so you will not be able to send more data to the client. It can however be useful for sending data to external services, for example to gather statistics.
call signature
( this: FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>, request: FastifyRequest< RouteGeneric, RawServer, RawRequest, SchemaCompiler, TypeProvider, ContextConfig, Logger >, reply: FastifyReply< RouteGeneric, RawServer, RawRequest, RawReply, ContextConfig, SchemaCompiler, TypeProvider >, done: HookHandlerDoneFunction): void;
interface onRouteHookHandler
interface onRouteHookHandler< RawServer extends RawServerBase = RawServerDefault, RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>, RawReply extends RawReplyDefaultExpression<RawServer> = RawReplyDefaultExpression<RawServer>, RouteGeneric extends RouteGenericInterface = RouteGenericInterface, ContextConfig = ContextConfigDefault, SchemaCompiler extends FastifySchema = FastifySchema, TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault, Logger extends FastifyBaseLogger = FastifyBaseLogger> {}
Triggered when a new route is registered. Listeners are passed a routeOptions object as the sole parameter. The interface is synchronous, and, as such, the listener does not get passed a callback
call signature
( this: FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>, opts: RouteOptions< RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider > & { routePath: string; path: string; prefix: string }): Promise<unknown> | void;
interface onSendAsyncHookHandler
interface onSendAsyncHookHandler< OnSendPayload = unknown, RawServer extends RawServerBase = RawServerDefault, RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>, RawReply extends RawReplyDefaultExpression<RawServer> = RawReplyDefaultExpression<RawServer>, RouteGeneric extends RouteGenericInterface = RouteGenericInterface, ContextConfig = ContextConfigDefault, SchemaCompiler extends FastifySchema = FastifySchema, TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault, Logger extends FastifyBaseLogger = FastifyBaseLogger> {}
call signature
( this: FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>, request: FastifyRequest< RouteGeneric, RawServer, RawRequest, SchemaCompiler, TypeProvider, ContextConfig, Logger >, reply: FastifyReply< RouteGeneric, RawServer, RawRequest, RawReply, ContextConfig, SchemaCompiler, TypeProvider >, payload: OnSendPayload): Promise<unknown>;
interface onSendHookHandler
interface onSendHookHandler< OnSendPayload = unknown, RawServer extends RawServerBase = RawServerDefault, RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>, RawReply extends RawReplyDefaultExpression<RawServer> = RawReplyDefaultExpression<RawServer>, RouteGeneric extends RouteGenericInterface = RouteGenericInterface, ContextConfig = ContextConfigDefault, SchemaCompiler extends FastifySchema = FastifySchema, TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault, Logger extends FastifyBaseLogger = FastifyBaseLogger> {}
You can change the payload with the
onSend
hook. It is the sixth hook to be executed in the request lifecycle. The previous hook waspreSerialization
, the next hook will beonResponse
. Note: If you change the payload, you may only change it to a string, a Buffer, a stream, or null.
call signature
( this: FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>, request: FastifyRequest< RouteGeneric, RawServer, RawRequest, SchemaCompiler, TypeProvider, ContextConfig, Logger >, reply: FastifyReply< RouteGeneric, RawServer, RawRequest, RawReply, ContextConfig, SchemaCompiler, TypeProvider >, payload: OnSendPayload, done: DoneFuncWithErrOrRes): void;
interface onTimeoutAsyncHookHandler
interface onTimeoutAsyncHookHandler< RawServer extends RawServerBase = RawServerDefault, RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>, RawReply extends RawReplyDefaultExpression<RawServer> = RawReplyDefaultExpression<RawServer>, RouteGeneric extends RouteGenericInterface = RouteGenericInterface, ContextConfig = ContextConfigDefault, SchemaCompiler extends FastifySchema = FastifySchema, TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault, Logger extends FastifyBaseLogger = FastifyBaseLogger> {}
call signature
( this: FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>, request: FastifyRequest< RouteGeneric, RawServer, RawRequest, SchemaCompiler, TypeProvider, ContextConfig, Logger >, reply: FastifyReply< RouteGeneric, RawServer, RawRequest, RawReply, ContextConfig, SchemaCompiler, TypeProvider >): Promise<unknown>;
interface onTimeoutHookHandler
interface onTimeoutHookHandler< RawServer extends RawServerBase = RawServerDefault, RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>, RawReply extends RawReplyDefaultExpression<RawServer> = RawReplyDefaultExpression<RawServer>, RouteGeneric extends RouteGenericInterface = RouteGenericInterface, ContextConfig = ContextConfigDefault, SchemaCompiler extends FastifySchema = FastifySchema, TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault, Logger extends FastifyBaseLogger = FastifyBaseLogger> {}
onTimeout
is useful if you need to monitor the request timed out in your service. (if theconnectionTimeout
property is set on the fastify instance) The onTimeout hook is executed when a request is timed out and the http socket has been hanged up. Therefore you will not be able to send data to the client.
call signature
( this: FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>, request: FastifyRequest< RouteGeneric, RawServer, RawRequest, SchemaCompiler, TypeProvider, ContextConfig, Logger >, reply: FastifyReply< RouteGeneric, RawServer, RawRequest, RawReply, ContextConfig, SchemaCompiler, TypeProvider >, done: HookHandlerDoneFunction): void;
interface preCloseAsyncHookHandler
interface preCloseAsyncHookHandler< RawServer extends RawServerBase = RawServerDefault, RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>, RawReply extends RawReplyDefaultExpression<RawServer> = RawReplyDefaultExpression<RawServer>, Logger extends FastifyBaseLogger = FastifyBaseLogger, TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault> {}
call signature
( this: FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>): Promise<unknown>;
interface preCloseHookHandler
interface preCloseHookHandler< RawServer extends RawServerBase = RawServerDefault, RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>, RawReply extends RawReplyDefaultExpression<RawServer> = RawReplyDefaultExpression<RawServer>, Logger extends FastifyBaseLogger = FastifyBaseLogger, TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault> {}
Triggered when fastify.close() is invoked to stop the server. It is useful when plugins need to cancel some state to allow the server to close successfully.
call signature
( this: FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>, done: HookHandlerDoneFunction): void;
interface preHandlerAsyncHookHandler
interface preHandlerAsyncHookHandler< RawServer extends RawServerBase = RawServerDefault, RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>, RawReply extends RawReplyDefaultExpression<RawServer> = RawReplyDefaultExpression<RawServer>, RouteGeneric extends RouteGenericInterface = RouteGenericInterface, ContextConfig = ContextConfigDefault, SchemaCompiler extends FastifySchema = FastifySchema, TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault, Logger extends FastifyBaseLogger = FastifyBaseLogger> {}
call signature
( this: FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>, request: FastifyRequest< RouteGeneric, RawServer, RawRequest, SchemaCompiler, TypeProvider, ContextConfig, Logger >, reply: FastifyReply< RouteGeneric, RawServer, RawRequest, RawReply, ContextConfig, SchemaCompiler, TypeProvider >): Promise<unknown>;
interface preHandlerHookHandler
interface preHandlerHookHandler< RawServer extends RawServerBase = RawServerDefault, RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>, RawReply extends RawReplyDefaultExpression<RawServer> = RawReplyDefaultExpression<RawServer>, RouteGeneric extends RouteGenericInterface = RouteGenericInterface, ContextConfig = ContextConfigDefault, SchemaCompiler extends FastifySchema = FastifySchema, TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault, Logger extends FastifyBaseLogger = FastifyBaseLogger> {}
preHandler
is the fourth hook to be executed in the request lifecycle. The previous hook waspreValidation
, the next hook will bepreSerialization
.
call signature
( this: FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>, request: FastifyRequest< RouteGeneric, RawServer, RawRequest, SchemaCompiler, TypeProvider, ContextConfig, Logger >, reply: FastifyReply< RouteGeneric, RawServer, RawRequest, RawReply, ContextConfig, SchemaCompiler, TypeProvider >, done: HookHandlerDoneFunction): void;
interface preParsingAsyncHookHandler
interface preParsingAsyncHookHandler< RawServer extends RawServerBase = RawServerDefault, RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>, RawReply extends RawReplyDefaultExpression<RawServer> = RawReplyDefaultExpression<RawServer>, RouteGeneric extends RouteGenericInterface = RouteGenericInterface, ContextConfig = ContextConfigDefault, SchemaCompiler extends FastifySchema = FastifySchema, TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault, Logger extends FastifyBaseLogger = FastifyBaseLogger> {}
call signature
( this: FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>, request: FastifyRequest< RouteGeneric, RawServer, RawRequest, SchemaCompiler, TypeProvider, ContextConfig, Logger >, reply: FastifyReply< RouteGeneric, RawServer, RawRequest, RawReply, ContextConfig, SchemaCompiler, TypeProvider >, payload: RequestPayload): Promise<RequestPayload | unknown>;
interface preParsingHookHandler
interface preParsingHookHandler< RawServer extends RawServerBase = RawServerDefault, RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>, RawReply extends RawReplyDefaultExpression<RawServer> = RawReplyDefaultExpression<RawServer>, RouteGeneric extends RouteGenericInterface = RouteGenericInterface, ContextConfig = ContextConfigDefault, SchemaCompiler extends FastifySchema = FastifySchema, TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault, Logger extends FastifyBaseLogger = FastifyBaseLogger> {}
preParsing
is the second hook to be executed in the request lifecycle. The previous hook wasonRequest
, the next hook will bepreValidation
. Notice: in thepreParsing
hook, request.body will always be null, because the body parsing happens before thepreHandler
hook.
call signature
( this: FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>, request: FastifyRequest< RouteGeneric, RawServer, RawRequest, SchemaCompiler, TypeProvider, ContextConfig, Logger >, reply: FastifyReply< RouteGeneric, RawServer, RawRequest, RawReply, ContextConfig, SchemaCompiler, TypeProvider >, payload: RequestPayload, done: <TError extends Error = FastifyError>( err?: TError | null, res?: RequestPayload ) => void): void;
interface preSerializationAsyncHookHandler
interface preSerializationAsyncHookHandler< PreSerializationPayload = unknown, RawServer extends RawServerBase = RawServerDefault, RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>, RawReply extends RawReplyDefaultExpression<RawServer> = RawReplyDefaultExpression<RawServer>, RouteGeneric extends RouteGenericInterface = RouteGenericInterface, ContextConfig = ContextConfigDefault, SchemaCompiler extends FastifySchema = FastifySchema, TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault, Logger extends FastifyBaseLogger = FastifyBaseLogger> {}
call signature
( this: FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>, request: FastifyRequest< RouteGeneric, RawServer, RawRequest, SchemaCompiler, TypeProvider, ContextConfig, Logger >, reply: FastifyReply< RouteGeneric, RawServer, RawRequest, RawReply, ContextConfig, SchemaCompiler, TypeProvider >, payload: PreSerializationPayload): Promise<unknown>;
interface preSerializationHookHandler
interface preSerializationHookHandler< PreSerializationPayload = unknown, RawServer extends RawServerBase = RawServerDefault, RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>, RawReply extends RawReplyDefaultExpression<RawServer> = RawReplyDefaultExpression<RawServer>, RouteGeneric extends RouteGenericInterface = RouteGenericInterface, ContextConfig = ContextConfigDefault, SchemaCompiler extends FastifySchema = FastifySchema, TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault, Logger extends FastifyBaseLogger = FastifyBaseLogger> {}
preSerialization
is the fifth hook to be executed in the request lifecycle. The previous hook waspreHandler
, the next hook will beonSend
. Note: the hook is NOT called if the payload is a string, a Buffer, a stream or null.
call signature
( this: FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>, request: FastifyRequest< RouteGeneric, RawServer, RawRequest, SchemaCompiler, TypeProvider, ContextConfig, Logger >, reply: FastifyReply< RouteGeneric, RawServer, RawRequest, RawReply, ContextConfig, SchemaCompiler, TypeProvider >, payload: PreSerializationPayload, done: DoneFuncWithErrOrRes): void;
interface preValidationAsyncHookHandler
interface preValidationAsyncHookHandler< RawServer extends RawServerBase = RawServerDefault, RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>, RawReply extends RawReplyDefaultExpression<RawServer> = RawReplyDefaultExpression<RawServer>, RouteGeneric extends RouteGenericInterface = RouteGenericInterface, ContextConfig = ContextConfigDefault, SchemaCompiler extends FastifySchema = FastifySchema, TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault, Logger extends FastifyBaseLogger = FastifyBaseLogger> {}
call signature
( this: FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>, request: FastifyRequest< RouteGeneric, RawServer, RawRequest, SchemaCompiler, TypeProvider, ContextConfig, Logger >, reply: FastifyReply< RouteGeneric, RawServer, RawRequest, RawReply, ContextConfig, SchemaCompiler, TypeProvider >): Promise<unknown>;
interface preValidationHookHandler
interface preValidationHookHandler< RawServer extends RawServerBase = RawServerDefault, RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>, RawReply extends RawReplyDefaultExpression<RawServer> = RawReplyDefaultExpression<RawServer>, RouteGeneric extends RouteGenericInterface = RouteGenericInterface, ContextConfig = ContextConfigDefault, SchemaCompiler extends FastifySchema = FastifySchema, TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault, Logger extends FastifyBaseLogger = FastifyBaseLogger> {}
preValidation
is the third hook to be executed in the request lifecycle. The previous hook waspreParsing
, the next hook will bepreHandler
.
call signature
( this: FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>, request: FastifyRequest< RouteGeneric, RawServer, RawRequest, SchemaCompiler, TypeProvider, ContextConfig, Logger >, reply: FastifyReply< RouteGeneric, RawServer, RawRequest, RawReply, ContextConfig, SchemaCompiler, TypeProvider >, done: HookHandlerDoneFunction): void;
interface PrintRoutesOptions
interface PrintRoutesOptions {}
property commonPrefix
commonPrefix?: boolean;
property includeHooks
includeHooks?: boolean;
property includeMeta
includeMeta?: boolean | (string | symbol)[];
property method
method?: HTTPMethods;
interface RegisterOptions
interface RegisterOptions {}
property logLevel
logLevel?: LogLevel;
property logSerializers
logSerializers?: Record<string, (value: any) => string>;
property prefix
prefix?: string;
interface RequestGenericInterface
interface RequestGenericInterface {}
property Body
Body?: RequestBodyDefault;
property Headers
Headers?: RequestHeadersDefault;
property Params
Params?: RequestParamsDefault;
property Querystring
Querystring?: RequestQuerystringDefault;
interface RequestPayload
interface RequestPayload extends Readable {}
property receivedEncodedLength
receivedEncodedLength?: number;
interface RouteGenericInterface
interface RouteGenericInterface extends RequestGenericInterface, ReplyGenericInterface {}
interface RouteOptions
interface RouteOptions< RawServer extends RawServerBase = RawServerDefault, RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>, RawReply extends RawReplyDefaultExpression<RawServer> = RawReplyDefaultExpression<RawServer>, RouteGeneric extends RouteGenericInterface = RouteGenericInterface, ContextConfig = ContextConfigDefault, SchemaCompiler extends FastifySchema = FastifySchema, TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault, Logger extends FastifyBaseLogger = FastifyBaseLogger> extends RouteShorthandOptions< RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger > {}
Fastify route method options.
interface RouteShorthandMethod
interface RouteShorthandMethod< RawServer extends RawServerBase = RawServerDefault, RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>, RawReply extends RawReplyDefaultExpression<RawServer> = RawReplyDefaultExpression<RawServer>, TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault, Logger extends FastifyBaseLogger = FastifyBaseLogger> {}
Fastify Router Shorthand method type that is similar to the Express/Restify approach
interface RouteShorthandOptions
interface RouteShorthandOptions< RawServer extends RawServerBase = RawServerDefault, RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>, RawReply extends RawReplyDefaultExpression<RawServer> = RawReplyDefaultExpression<RawServer>, RouteGeneric extends RouteGenericInterface = RouteGenericInterface, ContextConfig = ContextConfigDefault, SchemaCompiler extends FastifySchema = FastifySchema, TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault, Logger extends FastifyBaseLogger = FastifyBaseLogger> {}
Route shorthand options for the various shorthand methods
property attachValidation
attachValidation?: boolean;
property bodyLimit
bodyLimit?: number;
property childLoggerFactory
childLoggerFactory?: FastifyChildLoggerFactory< RawServer, RawRequest, RawReply, Logger, TypeProvider>;
property config
config?: FastifyContextConfig & ContextConfig;
property constraints
constraints?: RouteConstraint;
property errorHandler
errorHandler?: ( this: FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>, error: FastifyError, request: FastifyRequest< RouteGeneric, RawServer, RawRequest, NoInfer<SchemaCompiler>, TypeProvider, ContextConfig, Logger >, reply: FastifyReply< RouteGeneric, RawServer, RawRequest, RawReply, ContextConfig, NoInfer<SchemaCompiler>, TypeProvider >) => void;
property exposeHeadRoute
exposeHeadRoute?: boolean;
property logLevel
logLevel?: LogLevel;
property onError
onError?: | onErrorMetaHookHandler< RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, FastifyError, NoInfer<SchemaCompiler>, TypeProvider, Logger > | onErrorMetaHookHandler< RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, FastifyError, NoInfer<SchemaCompiler>, TypeProvider, Logger >[];
property onRequest
onRequest?: | onRequestMetaHookHandler< RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, NoInfer<SchemaCompiler>, TypeProvider, Logger > | onRequestMetaHookHandler< RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, NoInfer<SchemaCompiler>, TypeProvider, Logger >[];
property onRequestAbort
onRequestAbort?: | onRequestAbortMetaHookHandler< RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, NoInfer<SchemaCompiler>, TypeProvider, Logger > | onRequestAbortMetaHookHandler< RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, NoInfer<SchemaCompiler>, TypeProvider, Logger >[];
property onResponse
onResponse?: | onResponseMetaHookHandler< RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, NoInfer<SchemaCompiler>, TypeProvider, Logger > | onResponseMetaHookHandler< RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, NoInfer<SchemaCompiler>, TypeProvider, Logger >[];
property onSend
onSend?: | onSendMetaHookHandler< unknown, RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, NoInfer<SchemaCompiler>, TypeProvider, Logger > | onSendMetaHookHandler< unknown, RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, NoInfer<SchemaCompiler>, TypeProvider, Logger >[];
property onTimeout
onTimeout?: | onTimeoutMetaHookHandler< RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, NoInfer<SchemaCompiler>, TypeProvider, Logger > | onTimeoutMetaHookHandler< RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, NoInfer<SchemaCompiler>, TypeProvider, Logger >[];
property prefixTrailingSlash
prefixTrailingSlash?: 'slash' | 'no-slash' | 'both';
property preHandler
preHandler?: | preHandlerMetaHookHandler< RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, NoInfer<SchemaCompiler>, TypeProvider, Logger > | preHandlerMetaHookHandler< RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, NoInfer<SchemaCompiler>, TypeProvider, Logger >[];
property preParsing
preParsing?: | preParsingMetaHookHandler< RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, NoInfer<SchemaCompiler>, TypeProvider, Logger > | preParsingMetaHookHandler< RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, NoInfer<SchemaCompiler>, TypeProvider, Logger >[];
property preSerialization
preSerialization?: | preSerializationMetaHookHandler< unknown, RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, NoInfer<SchemaCompiler>, TypeProvider, Logger > | preSerializationMetaHookHandler< unknown, RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, NoInfer<SchemaCompiler>, TypeProvider, Logger >[];
property preValidation
preValidation?: | preValidationMetaHookHandler< RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, NoInfer<SchemaCompiler>, TypeProvider, Logger > | preValidationMetaHookHandler< RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, NoInfer<SchemaCompiler>, TypeProvider, Logger >[];
property schema
schema?: SchemaCompiler;
property schemaErrorFormatter
schemaErrorFormatter?: SchemaErrorFormatter;
property serializerCompiler
serializerCompiler?: FastifySerializerCompiler<NoInfer<SchemaCompiler>>;
property validatorCompiler
validatorCompiler?: FastifySchemaCompiler<NoInfer<SchemaCompiler>>;
interface RouteShorthandOptionsWithHandler
interface RouteShorthandOptionsWithHandler< RawServer extends RawServerBase = RawServerDefault, RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>, RawReply extends RawReplyDefaultExpression<RawServer> = RawReplyDefaultExpression<RawServer>, RouteGeneric extends RouteGenericInterface = RouteGenericInterface, ContextConfig = ContextConfigDefault, SchemaCompiler extends FastifySchema = FastifySchema, TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault, Logger extends FastifyBaseLogger = FastifyBaseLogger> extends RouteShorthandOptions< RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger > {}
Shorthand options including the handler function property
property handler
handler: RouteHandlerMethod< RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, NoInfer<SchemaCompiler>, TypeProvider, Logger>;
Type Aliases
type ConstructorAction
type ConstructorAction = 'error' | 'remove' | 'ignore';
type ContextConfigDefault
type ContextConfigDefault = unknown;
type FastifyBodyParser
type FastifyBodyParser< RawBody extends string | Buffer, RawServer extends RawServerBase = RawServerDefault, RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>, RouteGeneric extends RouteGenericInterface = RouteGenericInterface, SchemaCompiler extends FastifySchema = FastifySchema, TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault> = | (( request: FastifyRequest< RouteGeneric, RawServer, RawRequest, SchemaCompiler, TypeProvider >, rawBody: RawBody, done: ContentTypeParserDoneFunction ) => void) | (( request: FastifyRequest< RouteGeneric, RawServer, RawRequest, SchemaCompiler, TypeProvider >, rawBody: RawBody ) => Promise<any>);
Body parser method that operators on request body
type FastifyContentTypeParser
type FastifyContentTypeParser< RawServer extends RawServerBase = RawServerDefault, RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>, RouteGeneric extends RouteGenericInterface = RouteGenericInterface, SchemaCompiler extends FastifySchema = FastifySchema, TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault> = | (( request: FastifyRequest< RouteGeneric, RawServer, RawRequest, SchemaCompiler, TypeProvider >, payload: RawRequest ) => Promise<any>) | (( request: FastifyRequest< RouteGeneric, RawServer, RawRequest, SchemaCompiler, TypeProvider >, payload: RawRequest, done: ContentTypeParserDoneFunction ) => void);
Content Type Parser method that operates on request content
type FastifyErrorCodes
type FastifyErrorCodes = Record< | 'FST_ERR_NOT_FOUND' | 'FST_ERR_OPTIONS_NOT_OBJ' | 'FST_ERR_QSP_NOT_FN' | 'FST_ERR_SCHEMA_CONTROLLER_BUCKET_OPT_NOT_FN' | 'FST_ERR_SCHEMA_ERROR_FORMATTER_NOT_FN' | 'FST_ERR_AJV_CUSTOM_OPTIONS_OPT_NOT_OBJ' | 'FST_ERR_AJV_CUSTOM_OPTIONS_OPT_NOT_ARR' | 'FST_ERR_VALIDATION' | 'FST_ERR_CTP_ALREADY_PRESENT' | 'FST_ERR_CTP_INVALID_TYPE' | 'FST_ERR_CTP_EMPTY_TYPE' | 'FST_ERR_CTP_INVALID_HANDLER' | 'FST_ERR_CTP_INVALID_PARSE_TYPE' | 'FST_ERR_CTP_BODY_TOO_LARGE' | 'FST_ERR_CTP_INVALID_MEDIA_TYPE' | 'FST_ERR_CTP_INVALID_CONTENT_LENGTH' | 'FST_ERR_CTP_EMPTY_JSON_BODY' | 'FST_ERR_CTP_INSTANCE_ALREADY_STARTED' | 'FST_ERR_DEC_ALREADY_PRESENT' | 'FST_ERR_DEC_DEPENDENCY_INVALID_TYPE' | 'FST_ERR_DEC_MISSING_DEPENDENCY' | 'FST_ERR_DEC_AFTER_START' | 'FST_ERR_DEC_REFERENCE_TYPE' | 'FST_ERR_HOOK_INVALID_TYPE' | 'FST_ERR_HOOK_INVALID_HANDLER' | 'FST_ERR_HOOK_INVALID_ASYNC_HANDLER' | 'FST_ERR_HOOK_NOT_SUPPORTED' | 'FST_ERR_MISSING_MIDDLEWARE' | 'FST_ERR_HOOK_TIMEOUT' | 'FST_ERR_LOG_INVALID_DESTINATION' | 'FST_ERR_LOG_INVALID_LOGGER' | 'FST_ERR_REP_INVALID_PAYLOAD_TYPE' | 'FST_ERR_REP_ALREADY_SENT' | 'FST_ERR_REP_SENT_VALUE' | 'FST_ERR_SEND_INSIDE_ONERR' | 'FST_ERR_SEND_UNDEFINED_ERR' | 'FST_ERR_BAD_STATUS_CODE' | 'FST_ERR_BAD_TRAILER_NAME' | 'FST_ERR_BAD_TRAILER_VALUE' | 'FST_ERR_FAILED_ERROR_SERIALIZATION' | 'FST_ERR_MISSING_SERIALIZATION_FN' | 'FST_ERR_MISSING_CONTENTTYPE_SERIALIZATION_FN' | 'FST_ERR_REQ_INVALID_VALIDATION_INVOCATION' | 'FST_ERR_SCH_MISSING_ID' | 'FST_ERR_SCH_ALREADY_PRESENT' | 'FST_ERR_SCH_CONTENT_MISSING_SCHEMA' | 'FST_ERR_SCH_DUPLICATE' | 'FST_ERR_SCH_VALIDATION_BUILD' | 'FST_ERR_SCH_SERIALIZATION_BUILD' | 'FST_ERR_SCH_RESPONSE_SCHEMA_NOT_NESTED_2XX' | 'FST_ERR_HTTP2_INVALID_VERSION' | 'FST_ERR_INIT_OPTS_INVALID' | 'FST_ERR_FORCE_CLOSE_CONNECTIONS_IDLE_NOT_AVAILABLE' | 'FST_ERR_DUPLICATED_ROUTE' | 'FST_ERR_BAD_URL' | 'FST_ERR_ASYNC_CONSTRAINT' | 'FST_ERR_DEFAULT_ROUTE_INVALID_TYPE' | 'FST_ERR_INVALID_URL' | 'FST_ERR_ROUTE_OPTIONS_NOT_OBJ' | 'FST_ERR_ROUTE_DUPLICATED_HANDLER' | 'FST_ERR_ROUTE_HANDLER_NOT_FN' | 'FST_ERR_ROUTE_MISSING_HANDLER' | 'FST_ERR_ROUTE_METHOD_INVALID' | 'FST_ERR_ROUTE_METHOD_NOT_SUPPORTED' | 'FST_ERR_ROUTE_BODY_VALIDATION_SCHEMA_NOT_SUPPORTED' | 'FST_ERR_ROUTE_BODY_LIMIT_OPTION_NOT_INT' | 'FST_ERR_ROUTE_REWRITE_NOT_STR' | 'FST_ERR_REOPENED_CLOSE_SERVER' | 'FST_ERR_REOPENED_SERVER' | 'FST_ERR_INSTANCE_ALREADY_LISTENING' | 'FST_ERR_PLUGIN_VERSION_MISMATCH' | 'FST_ERR_PLUGIN_NOT_PRESENT_IN_INSTANCE' | 'FST_ERR_PLUGIN_CALLBACK_NOT_FN' | 'FST_ERR_PLUGIN_NOT_VALID' | 'FST_ERR_ROOT_PLG_BOOTED' | 'FST_ERR_PARENT_PLUGIN_BOOTED' | 'FST_ERR_PLUGIN_TIMEOUT', FastifyErrorConstructor>;
type FastifyHttp2Options
type FastifyHttp2Options< Server extends http2.Http2Server, Logger extends FastifyBaseLogger = FastifyBaseLogger> = FastifyServerOptions<Server, Logger> & { http2: true; http2SessionTimeout?: number;};
type FastifyHttp2SecureOptions
type FastifyHttp2SecureOptions< Server extends http2.Http2SecureServer, Logger extends FastifyBaseLogger = FastifyBaseLogger> = FastifyServerOptions<Server, Logger> & { http2: true; https: http2.SecureServerOptions; http2SessionTimeout?: number;};
type FastifyHttpOptions
type FastifyHttpOptions< Server extends http.Server, Logger extends FastifyBaseLogger = FastifyBaseLogger> = FastifyServerOptions<Server, Logger> & { http?: http.ServerOptions | null;};
type FastifyHttpsOptions
type FastifyHttpsOptions< Server extends https.Server, Logger extends FastifyBaseLogger = FastifyBaseLogger> = FastifyServerOptions<Server, Logger> & { https: https.ServerOptions | null;};
type FastifyLogFn
type FastifyLogFn = pino.LogFn;
Standard Fastify logging function
type FastifyLoggerInstance
type FastifyLoggerInstance = FastifyBaseLogger;
Deprecated
Use FastifyBaseLogger instead
type FastifyPlugin
type FastifyPlugin<Options extends FastifyPluginOptions = Record<never, never>> = | FastifyPluginCallback<Options> | FastifyPluginAsync<Options>;
Generic plugin type.
Deprecated
union type doesn't work well with type inference in TS and is therefore deprecated in favor of explicit types. Use
FastifyPluginCallback
orFastifyPluginAsync
instead. To activate plugins useFastifyRegister
. https://fastify.dev/docs/latest/Reference/TypeScript/#register
type FastifyPluginAsync
type FastifyPluginAsync< Options extends FastifyPluginOptions = Record<never, never>, Server extends RawServerBase = RawServerDefault, TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault, Logger extends FastifyBaseLogger = FastifyBaseLogger> = ( instance: FastifyInstance< Server, RawRequestDefaultExpression<Server>, RawReplyDefaultExpression<Server>, Logger, TypeProvider >, opts: Options) => Promise<void>;
FastifyPluginAsync
Fastify allows the user to extend its functionalities with plugins. A plugin can be a set of routes, a server decorator or whatever. To activate plugins, use the
fastify.register()
method.
type FastifyPluginCallback
type FastifyPluginCallback< Options extends FastifyPluginOptions = Record<never, never>, Server extends RawServerBase = RawServerDefault, TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault, Logger extends FastifyBaseLogger = FastifyBaseLogger> = ( instance: FastifyInstance< Server, RawRequestDefaultExpression<Server>, RawReplyDefaultExpression<Server>, Logger, TypeProvider >, opts: Options, done: (err?: Error) => void) => void;
FastifyPluginCallback
Fastify allows the user to extend its functionalities with plugins. A plugin can be a set of routes, a server decorator or whatever. To activate plugins, use the
fastify.register()
method.
type FastifyPluginOptions
type FastifyPluginOptions = Record<string, any>;
type FastifyRegisterOptions
type FastifyRegisterOptions<Options> = | (RegisterOptions & Options) | ((instance: FastifyInstance) => RegisterOptions & Options);
type FastifySchemaCompiler
type FastifySchemaCompiler<T> = ( routeSchema: FastifyRouteSchemaDef<T>) => FastifyValidationResult;
Compiler for FastifySchema Type
type FastifyServerFactoryHandler
type FastifyServerFactoryHandler< RawServer extends RawServerBase = RawServerDefault, RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>, RawReply extends RawReplyDefaultExpression<RawServer> = RawReplyDefaultExpression<RawServer>> = RawServer extends http.Server | https.Server ? ( request: http.IncomingMessage & RawRequest, response: http.ServerResponse & RawReply ) => void : ( request: http2.Http2ServerRequest & RawRequest, response: http2.Http2ServerResponse & RawReply ) => void;
type FastifyServerOptions
type FastifyServerOptions< RawServer extends RawServerBase = RawServerDefault, Logger extends FastifyBaseLogger = FastifyBaseLogger> = { ignoreTrailingSlash?: boolean; ignoreDuplicateSlashes?: boolean; connectionTimeout?: number; keepAliveTimeout?: number; maxRequestsPerSocket?: number; forceCloseConnections?: boolean | 'idle'; requestTimeout?: number; pluginTimeout?: number; bodyLimit?: number; maxParamLength?: number; disableRequestLogging?: boolean; exposeHeadRoutes?: boolean; onProtoPoisoning?: ProtoAction; onConstructorPoisoning?: ConstructorAction; logger?: boolean | (FastifyLoggerOptions<RawServer> & PinoLoggerOptions); loggerInstance?: Logger; serializerOpts?: FJSOptions | Record<string, unknown>; serverFactory?: FastifyServerFactory<RawServer>; caseSensitive?: boolean; allowUnsafeRegex?: boolean; requestIdHeader?: string | false; requestIdLogLabel?: string; useSemicolonDelimiter?: boolean; genReqId?: (req: RawRequestDefaultExpression<RawServer>) => string; trustProxy?: boolean | string | string[] | number | TrustProxyFunction; querystringParser?: (str: string) => { [key: string]: unknown }; constraints?: { [name: string]: ConstraintStrategy<FindMyWayVersion<RawServer>, unknown>; }; schemaController?: { bucket?: (parentSchemas?: unknown) => { add(schema: unknown): FastifyInstance; getSchema(schemaId: string): unknown; getSchemas(): Record<string, unknown>; }; compilersFactory?: { buildValidator?: ValidatorFactory; buildSerializer?: SerializerFactory; }; }; return503OnClosing?: boolean; ajv?: { customOptions?: AjvOptions; plugins?: (Function | [Function, unknown])[]; }; frameworkErrors?: < RequestGeneric extends RequestGenericInterface = RequestGenericInterface, TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault, SchemaCompiler extends FastifySchema = FastifySchema >( error: FastifyError, req: FastifyRequest< RequestGeneric, RawServer, RawRequestDefaultExpression<RawServer>, FastifySchema, TypeProvider >, res: FastifyReply< RequestGeneric, RawServer, RawRequestDefaultExpression<RawServer>, RawReplyDefaultExpression<RawServer>, FastifyContextConfig, SchemaCompiler, TypeProvider > ) => void; rewriteUrl?: ( // The RawRequestDefaultExpression, RawReplyDefaultExpression, and FastifyTypeProviderDefault parameters // should be narrowed further but those generic parameters are not passed to this FastifyServerOptions type this: FastifyInstance< RawServer, RawRequestDefaultExpression<RawServer>, RawReplyDefaultExpression<RawServer>, Logger, FastifyTypeProviderDefault >, req: RawRequestDefaultExpression<RawServer> ) => string; schemaErrorFormatter?: SchemaErrorFormatter; /** * listener to error events emitted by client connections */ clientErrorHandler?: (error: ConnectionError, socket: Socket) => void; childLoggerFactory?: FastifyChildLoggerFactory;};
Options for a fastify server instance. Utilizes conditional logic on the generic server parameter to enforce certain https and http2
type getDefaultJsonParser
type getDefaultJsonParser = ( onProtoPoisoning: ProtoAction, onConstructorPoisoning: ConstructorAction) => FastifyBodyParser<string>;
type hasContentTypeParser
type hasContentTypeParser = (contentType: string | RegExp) => boolean;
Checks for a type parser of a content type
type HookHandlerDoneFunction
type HookHandlerDoneFunction = <TError extends Error = FastifyError>( err?: TError) => void;
type HTTPMethods
type HTTPMethods = Autocomplete<_HTTPMethods | Lowercase<_HTTPMethods>>;
type LogLevel
type LogLevel = pino.LevelWithSilent;
type ProtoAction
type ProtoAction = 'error' | 'remove' | 'ignore';
type RawReplyDefaultExpression
type RawReplyDefaultExpression<RawServer extends RawServerBase = RawServerDefault> = RawServer extends http.Server | https.Server ? http.ServerResponse : RawServer extends http2.Http2Server | http2.Http2SecureServer ? http2.Http2ServerResponse : never;
The default reply type based on the server type. Utilizes generic constraining.
type RawRequestDefaultExpression
type RawRequestDefaultExpression< RawServer extends RawServerBase = RawServerDefault> = RawServer extends http.Server | https.Server ? http.IncomingMessage : RawServer extends http2.Http2Server | http2.Http2SecureServer ? http2.Http2ServerRequest : never;
The default request type based on the server type. Utilizes generic constraining.
type RawServerBase
type RawServerBase = | http.Server | https.Server | http2.Http2Server | http2.Http2SecureServer;
A union type of the Node.js server types from the http, https, and http2 modules.
type RawServerDefault
type RawServerDefault = http.Server;
The default server type
type RequestBodyDefault
type RequestBodyDefault = unknown;
type RequestHeadersDefault
type RequestHeadersDefault = unknown;
type RequestParamsDefault
type RequestParamsDefault = unknown;
type RequestQuerystringDefault
type RequestQuerystringDefault = unknown;
type RouteHandler
type RouteHandler< RouteGeneric extends RouteGenericInterface = RouteGenericInterface, RawServer extends RawServerBase = RawServerDefault, RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>, RawReply extends RawReplyDefaultExpression<RawServer> = RawReplyDefaultExpression<RawServer>, ContextConfig = ContextConfigDefault, SchemaCompiler extends FastifySchema = FastifySchema, TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault, Logger extends FastifyBaseLogger = FastifyBaseLogger> = ( this: FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>, request: FastifyRequest< RouteGeneric, RawServer, RawRequest, SchemaCompiler, TypeProvider, ContextConfig, Logger >, reply: FastifyReply< RouteGeneric, RawServer, RawRequest, RawReply, ContextConfig, SchemaCompiler, TypeProvider >) => RouteGeneric['Reply'] | void | Promise<RouteGeneric['Reply'] | void>;
type RouteHandlerMethod
type RouteHandlerMethod< RawServer extends RawServerBase = RawServerDefault, RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>, RawReply extends RawReplyDefaultExpression<RawServer> = RawReplyDefaultExpression<RawServer>, RouteGeneric extends RouteGenericInterface = RouteGenericInterface, ContextConfig = ContextConfigDefault, SchemaCompiler extends FastifySchema = FastifySchema, TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault, Logger extends FastifyBaseLogger = FastifyBaseLogger> = ( this: FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>, request: FastifyRequest< RouteGeneric, RawServer, RawRequest, SchemaCompiler, TypeProvider, ContextConfig, Logger >, reply: FastifyReply< RouteGeneric, RawServer, RawRequest, RawReply, ContextConfig, SchemaCompiler, TypeProvider > // This return type used to be a generic type argument. Due to TypeScript's inference of return types, this rendered returns unchecked.) => ResolveFastifyReplyReturnType<TypeProvider, SchemaCompiler, RouteGeneric>;
Route handler method declaration.
type SafePromiseLike
type SafePromiseLike<T> = PromiseLike<T> & { __linterBrands: 'SafePromiseLike' };
This branded type is needed to indicate APIs that return Promise-likes which can safely "float" (not have rejections handled by calling code).
Please refer to the following Github issue for more info: https://github.com/fastify/fastify/issues/5498
type ValidationResult
type ValidationResult = FastifySchemaValidationError;
Deprecated
Package Files (19)
- fastify.d.ts
- test/types/decorate-request-reply.test-d.ts
- test/types/instance.test-d.ts
- test/types/route.test-d.ts
- types/content-type-parser.d.ts
- types/context.d.ts
- types/errors.d.ts
- types/hooks.d.ts
- types/instance.d.ts
- types/logger.d.ts
- types/plugin.d.ts
- types/register.d.ts
- types/reply.d.ts
- types/request.d.ts
- types/route.d.ts
- types/schema.d.ts
- types/serverFactory.d.ts
- types/type-provider.d.ts
- types/utils.d.ts
Dependencies (15)
Dev Dependencies (38)
- @fastify/pre-commit
- @jsumners/line-reporter
- @sinclair/typebox
- @sinonjs/fake-timers
- @stylistic/eslint-plugin
- @stylistic/eslint-plugin-js
- @types/node
- ajv
- ajv-errors
- ajv-formats
- ajv-i18n
- ajv-merge-patch
- autocannon
- borp
- branch-comparer
- concurrently
- cross-env
- eslint
- fast-json-body
- fastify-plugin
- fluent-json-schema
- h2url
- http-errors
- joi
- json-schema-to-ts
- JSONStream
- markdownlint-cli2
- neostandard
- node-forge
- proxyquire
- simple-get
- split2
- tap
- tsd
- typescript
- undici
- vary
- yup
Peer Dependencies (0)
No peer dependencies.
Badge
To add a badge like this oneto your package's README, use the codes available below.
You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/fastify
.
- Markdown[](https://www.jsdocs.io/package/fastify)
- HTML<a href="https://www.jsdocs.io/package/fastify"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>
- Updated .
Package analyzed in 9005 ms. - Missing or incorrect documentation? Open an issue for this package.