Interface FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>

Fastify server instance. Returned by the core fastify() method.

interface FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider> {
    addContentTypeParser: AddContentTypeParser<RawServer, RawRequest, RouteGenericInterface, FastifySchema, TypeProvider>;
    all: RouteShorthandMethod<RawServer, RawRequest, RawReply, TypeProvider, Logger>;
    childLoggerFactory: FastifyChildLoggerFactory<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
    decorate: DecorationMethod<FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>, FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>>;
    decorateReply: DecorationMethod<FastifyReply<RawServerDefault, IncomingMessage, ServerResponse<IncomingMessage>, RouteGenericInterface, unknown, FastifySchema, FastifyTypeProviderDefault, unknown>, FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>>;
    decorateRequest: DecorationMethod<FastifyRequest<RouteGenericInterface, RawServerDefault, IncomingMessage, FastifySchema, FastifyTypeProviderDefault, unknown, FastifyBaseLogger, ResolveFastifyRequestType<FastifyTypeProviderDefault, FastifySchema, RouteGenericInterface>>, FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>>;
    defaultTextParser: FastifyBodyParser<string>;
    delete: RouteShorthandMethod<RawServer, RawRequest, RawReply, TypeProvider, Logger>;
    errorHandler: ((error, request, reply) => void);
    get: RouteShorthandMethod<RawServer, RawRequest, RawReply, TypeProvider, Logger>;
    getDefaultJsonParser: getDefaultJsonParser;
    hasContentTypeParser: hasContentTypeParser;
    head: RouteShorthandMethod<RawServer, RawRequest, RawReply, TypeProvider, Logger>;
    initialConfig: Readonly<{
        allowUnsafeRegex?: boolean;
        bodyLimit?: number;
        caseSensitive?: boolean;
        connectionTimeout?: number;
        disableRequestLogging?: boolean;
        forceCloseConnections?: boolean;
        http2?: boolean;
        http2SessionTimeout?: number;
        https?: boolean | Readonly<{
            allowHTTP1: boolean;
        }>;
        ignoreDuplicateSlashes?: boolean;
        ignoreTrailingSlash?: boolean;
        keepAliveTimeout?: number;
        maxParamLength?: number;
        onConstructorPoisoning?: ConstructorAction;
        onProtoPoisoning?: ProtoAction;
        pluginTimeout?: number;
        requestIdHeader?: string | false;
        requestIdLogLabel?: string;
        useSemicolonDelimiter?: boolean;
    }>;
    listeningOrigin: string;
    log: Logger;
    options: RouteShorthandMethod<RawServer, RawRequest, RawReply, TypeProvider, Logger>;
    patch: RouteShorthandMethod<RawServer, RawRequest, RawReply, TypeProvider, Logger>;
    pluginName: string;
    post: RouteShorthandMethod<RawServer, RawRequest, RawReply, TypeProvider, Logger>;
    prefix: string;
    put: RouteShorthandMethod<RawServer, RawRequest, RawReply, TypeProvider, Logger>;
    register: FastifyRegister<FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider> & PromiseLike<undefined>, RawServerDefault, FastifyTypeProvider, FastifyBaseLogger>;
    removeAllContentTypeParsers: removeAllContentTypeParsers;
    removeContentTypeParser: removeContentTypeParser;
    serializerCompiler: undefined | FastifySerializerCompiler<any>;
    server: RawServer;
    validatorCompiler: undefined | FastifySchemaCompiler<any>;
    version: string;
    [asyncDispose](): Promise<undefined>;
    addConstraintStrategy(strategy): void;
    addHook<RouteGeneric, ContextConfig, SchemaCompiler, Logger, Fn>(name, hook): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
    addHook<RouteGeneric, ContextConfig, SchemaCompiler, Logger, Fn>(name, hook): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
    addHook<RouteGeneric, ContextConfig, SchemaCompiler, Logger, Fn>(name, hook): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
    addHook<RouteGeneric, ContextConfig, SchemaCompiler, Logger, Fn>(name, hook): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
    addHook<PreSerializationPayload, RouteGeneric, ContextConfig, SchemaCompiler, Logger, Fn>(name, hook): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
    addHook<OnSendPayload, RouteGeneric, ContextConfig, SchemaCompiler, Logger, Fn>(name, hook): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
    addHook<RouteGeneric, ContextConfig, SchemaCompiler, Logger, Fn>(name, hook): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
    addHook<RouteGeneric, ContextConfig, SchemaCompiler, Logger, Fn>(name, hook): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
    addHook<RouteGeneric, ContextConfig, SchemaCompiler, Logger, Fn>(name, hook): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
    addHook<RouteGeneric, ContextConfig, SchemaCompiler, Logger, Fn>(name, hook): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
    addHook<RouteGeneric, ContextConfig, SchemaCompiler, Logger>(name, hook): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
    addHook(name, hook): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
    addHook<Fn>(name, hook): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
    addHook<Fn>(name, hook): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
    addHook<Fn>(name, hook): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
    addHook<Fn>(name, hook): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
    addHook<K, Fn>(name, hook): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
    addSchema(schema): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
    addresses(): AddressInfo[];
    after(): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider> & PromiseLike<undefined>;
    after(afterListener): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
    close(): Promise<undefined>;
    close(closeListener): undefined;
    findRoute<RouteGeneric, ContextConfig, SchemaCompiler>(opts): Omit<FindMyWayFindResult<RawServer>, "store">;
    getDefaultRoute(): DefaultRoute<RawRequest, RawReply>;
    getSchema(schemaId): unknown;
    getSchemas(): Record<string, unknown>;
    hasConstraintStrategy(strategyName): boolean;
    hasDecorator(decorator): boolean;
    hasPlugin(name): boolean;
    hasReplyDecorator(decorator): boolean;
    hasRequestDecorator(decorator): boolean;
    hasRoute<RouteGeneric, ContextConfig, SchemaCompiler>(opts): boolean;
    inject(opts, cb): void;
    inject(opts): Promise<Response>;
    inject(): Chain;
    listen(opts, callback): void;
    listen(opts?): Promise<string>;
    listen(callback): void;
    listen(port, address, backlog, callback): void;
    listen(port, address, callback): void;
    listen(port, callback): void;
    listen(port, address?, backlog?): Promise<string>;
    printPlugins(): string;
    printRoutes(opts?): string;
    ready(): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider> & PromiseLike<undefined>;
    ready(readyListener): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
    route<RouteGeneric, ContextConfig, const SchemaCompiler>(opts): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
    routing(req, res): void;
    setChildLoggerFactory(factory): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
    setDefaultRoute(defaultRoute): void;
    setErrorHandler<TError, RouteGeneric, SchemaCompiler, TypeProvider>(handler): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
    setGenReqId(fn): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
    setNotFoundHandler<RouteGeneric, ContextConfig, TypeProvider, SchemaCompiler>(handler): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
    setNotFoundHandler<RouteGeneric, ContextConfig, TypeProvider, SchemaCompiler>(opts, handler): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
    setReplySerializer(replySerializer): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
    setSchemaController(schemaControllerOpts): FastifyInstance<RawServer, RawRequest, RawReply, Logger, FastifyTypeProviderDefault>;
    setSchemaErrorFormatter(errorFormatter): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
    setSerializerCompiler<T>(schemaCompiler): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
    setValidatorCompiler<T>(schemaCompiler): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
    withTypeProvider<Provider>(): FastifyInstance<RawServer, RawRequest, RawReply, Logger, Provider>;
}

Type Parameters

Properties

Add a content type parser

Hook function that is called when creating a child logger instance for each request which allows for modifying or adding child logger bindings and logger options, or returning a completely custom child logger implementation.

defaultTextParser: FastifyBodyParser<string>

Fastify default plain text parser

errorHandler: ((error, request, reply) => void)

Fastify default error handler

getDefaultJsonParser: getDefaultJsonParser

Fastify default JSON parser

hasContentTypeParser: hasContentTypeParser
initialConfig: Readonly<{
    allowUnsafeRegex?: boolean;
    bodyLimit?: number;
    caseSensitive?: boolean;
    connectionTimeout?: number;
    disableRequestLogging?: boolean;
    forceCloseConnections?: boolean;
    http2?: boolean;
    http2SessionTimeout?: number;
    https?: boolean | Readonly<{
        allowHTTP1: boolean;
    }>;
    ignoreDuplicateSlashes?: boolean;
    ignoreTrailingSlash?: boolean;
    keepAliveTimeout?: number;
    maxParamLength?: number;
    onConstructorPoisoning?: ConstructorAction;
    onProtoPoisoning?: ProtoAction;
    pluginTimeout?: number;
    requestIdHeader?: string | false;
    requestIdLogLabel?: string;
    useSemicolonDelimiter?: boolean;
}>

Frozen read-only object registering the initial options passed down by the user to the fastify instance

Type declaration

  • Optional allowUnsafeRegex?: boolean
  • Optional bodyLimit?: number
  • Optional caseSensitive?: boolean
  • Optional connectionTimeout?: number
  • Optional disableRequestLogging?: boolean
  • Optional forceCloseConnections?: boolean
  • Optional http2?: boolean
  • Optional http2SessionTimeout?: number
  • Optional https?: boolean | Readonly<{
        allowHTTP1: boolean;
    }>
  • Optional ignoreDuplicateSlashes?: boolean
  • Optional ignoreTrailingSlash?: boolean
  • Optional keepAliveTimeout?: number
  • Optional maxParamLength?: number
  • Optional onConstructorPoisoning?: ConstructorAction
  • Optional onProtoPoisoning?: ProtoAction
  • Optional pluginTimeout?: number
  • Optional requestIdHeader?: string | false
  • Optional requestIdLogLabel?: string
  • Optional useSemicolonDelimiter?: boolean
listeningOrigin: string
log: Logger
pluginName: string
prefix: string
removeAllContentTypeParsers: removeAllContentTypeParsers

Remove all content type parsers, including the default ones

removeContentTypeParser: removeContentTypeParser

Remove an existing content type parser

serializerCompiler: undefined | FastifySerializerCompiler<any>

Fastify schema serializer for all routes.

server: RawServer
validatorCompiler: undefined | FastifySchemaCompiler<any>

Fastify schema validator for all routes.

version: string

Methods

  • Alias for ()

    Returns Promise<undefined>

  • Returns Promise<undefined>

  • Parameters

    • closeListener: (() => void)
        • (): void
        • Returns void

    Returns undefined

  • Parameters

    • schemaId: string

    Returns unknown

  • Returns Record<string, unknown>

  • Parameters

    • strategyName: string

    Returns boolean

  • Parameters

    • decorator: string | symbol

    Returns boolean

  • Parameters

    • name: string

    Returns boolean

  • Parameters

    • decorator: string | symbol

    Returns boolean

  • Parameters

    • decorator: string | symbol

    Returns boolean

  • Parameters

    • opts: FastifyListenOptions
    • callback: ((err, address) => void)
        • (err, address): void
        • Parameters

          • err: null | Error
          • address: string

          Returns void

    Returns void

  • Parameters

    Returns Promise<string>

  • Parameters

    • callback: ((err, address) => void)
        • (err, address): void
        • Parameters

          • err: null | Error
          • address: string

          Returns void

    Returns void

  • Parameters

    • port: string | number
    • address: string
    • backlog: number
    • callback: ((err, address) => void)
        • (err, address): void
        • Parameters

          • err: null | Error
          • address: string

          Returns void

    Returns void

    Deprecated

    Variadic listen method is deprecated. Please use .listen(optionsObject, callback) instead. The variadic signature will be removed in fastify@5

    See

    https://github.com/fastify/fastify/pull/3712

  • Parameters

    • port: string | number
    • address: string
    • callback: ((err, address) => void)
        • (err, address): void
        • Parameters

          • err: null | Error
          • address: string

          Returns void

    Returns void

    Deprecated

    Variadic listen method is deprecated. Please use .listen(optionsObject, callback) instead. The variadic signature will be removed in fastify@5

    See

    https://github.com/fastify/fastify/pull/3712

  • Parameters

    • port: string | number
    • callback: ((err, address) => void)
        • (err, address): void
        • Parameters

          • err: null | Error
          • address: string

          Returns void

    Returns void

    Deprecated

    Variadic listen method is deprecated. Please use .listen(optionsObject, callback) instead. The variadic signature will be removed in fastify@5

    See

    https://github.com/fastify/fastify/pull/3712

  • Parameters

    • port: string | number
    • Optional address: string
    • Optional backlog: number

    Returns Promise<string>

    Deprecated

    Variadic listen method is deprecated. Please use .listen(optionsObject) instead. The variadic signature will be removed in fastify@5

    See

    https://github.com/fastify/fastify/pull/3712

  • Prints the representation of the plugin tree used by avvio, the plugin registration system

    Returns string

  • Prints the representation of the internal radix tree used by the router

    Parameters

    Returns string

  • Parameters

    Returns void

  • Parameters

    Returns void