Skip to content

AbstractHttpAdapter

reference
2 min readUpdated

Kind: Class

Source: packages/core/adapters/http-adapter.ts

Part of: Core

AbstractHttpAdapter defines the common HTTP server adapter contract used by NestJS platform integrations. It delegates middleware and route registration methods such as use(), get(), post(), and head() to the underlying HTTP framework instance, allowing Nest applications to work with different server implementations.

Implements: HttpServer

Methods

MethodSignatureReturns
initinit()void
useuse(args: any[])void
getget(handler: RequestHandler)void
getget(path: any, handler: RequestHandler)void
getget(args: any[])void
postpost(handler: RequestHandler)void
postpost(path: any, handler: RequestHandler)void
postpost(args: any[])void
headhead(handler: RequestHandler)void
headhead(path: any, handler: RequestHandler)void
headhead(args: any[])void
deletedelete(handler: RequestHandler)void
deletedelete(path: any, handler: RequestHandler)void
deletedelete(args: any[])void
putput(handler: RequestHandler)void
putput(path: any, handler: RequestHandler)void
putput(args: any[])void
patchpatch(handler: RequestHandler)void
patchpatch(path: any, handler: RequestHandler)void
patchpatch(args: any[])void
propfindpropfind(handler: RequestHandler)void
propfindpropfind(path: any, handler: RequestHandler)void
propfindpropfind(args: any[])void
proppatchproppatch(handler: RequestHandler)void
proppatchproppatch(path: any, handler: RequestHandler)void
proppatchproppatch(args: any[])void
mkcolmkcol(handler: RequestHandler)void
mkcolmkcol(path: any, handler: RequestHandler)void
mkcolmkcol(args: any[])void
copycopy(handler: RequestHandler)void
copycopy(path: any, handler: RequestHandler)void
copycopy(args: any[])void
movemove(handler: RequestHandler)void
movemove(path: any, handler: RequestHandler)void
movemove(args: any[])void
locklock(handler: RequestHandler)void
locklock(path: any, handler: RequestHandler)void
locklock(args: any[])void
unlockunlock(handler: RequestHandler)void
unlockunlock(path: any, handler: RequestHandler)void
unlockunlock(args: any[])void
allall(handler: RequestHandler)void
allall(path: any, handler: RequestHandler)void
allall(args: any[])void
searchsearch(handler: RequestHandler)void
searchsearch(path: any, handler: RequestHandler)void
searchsearch(args: any[])void
optionsoptions(handler: RequestHandler)void
optionsoptions(path: any, handler: RequestHandler)void
optionsoptions(args: any[])void

Properties

PropertyType
httpServerTServer
onRouteTriggered`

Diagram

mermaid
graph LR
  Nest[Nest Application] --> Adapter[AbstractHttpAdapter]
  Adapter --> Instance[Underlying HTTP Framework Instance]
  Adapter --> Init[init()]
  Adapter --> Middleware[use()]
  Adapter --> Routes[get() / post() / head()]
  Middleware --> Instance
  Routes --> Instance
  Instance --> Server[HTTP Server]

Usage

ts
import * as express from 'express';
import { NestFactory } from '@nestjs/core';
import { ExpressAdapter } from '@nestjs/platform-express';
import { AppModule } from './app.module';

async function bootstrap() {
  const expressApp = express();
  const httpAdapter = new ExpressAdapter(expressApp);

  // Register framework-native middleware through the adapter.
  httpAdapter.use((req, res, next) => {
    console.log(`${req.method} ${req.url}`);
    next();
  });

  // Register routes directly on the underlying platform.
  httpAdapter.get('/health', (_req, res) => {
    res.status(200).json({ status: 'ok' });
  });

  httpAdapter.head('/health', (_req, res) => {
    res.status(200).end();
  });

  const app = await NestFactory.create(AppModule, httpAdapter);
  await app.listen(3000);
}

bootstrap();

AI Coding Instructions

  • Extend AbstractHttpAdapter only when integrating a new HTTP platform; use concrete adapters such as ExpressAdapter or FastifyAdapter in application code.
  • Delegate route and middleware methods to the underlying framework instance so native platform behavior is preserved.
  • Keep get(), post(), and head() overload behavior compatible with the target framework’s route-registration API.
  • Use use() for platform middleware registration, but prefer Nest middleware, guards, interceptors, and controllers for application-level concerns.
  • Ensure the adapter is initialized and passed to NestFactory.create() when configuring a custom HTTP server instance.

How it works

AbstractHttpAdapter<TServer, TRequest, TResponse> is a public abstract base class for HTTP platform adapters. It implements the HttpServer<TRequest, TResponse> contract and stores both a platform instance and, separately, an HTTP server value. Its type parameters default to any. packages/core/adapters/http-adapter.ts:5-18

Relationships

  • IMPORTS → HttpServer
  • IMPORTS → RequestMethod
  • IMPORTS → VersioningOptions
  • IMPORTS → RequestHandler
  • IMPORTS → VersionValue
  • IMPORTS → NestApplicationOptions

Used by

3 references from 3 files. Each is a place in this repository where the symbol is actually used — go read one rather than trusting an example.

Imported by (3)

  • ExpressAdapterpackages/platform-express/adapters/express-adapter.ts:51
  • FastifyAdapterpackages/platform-fastify/adapters/fastify-adapter.ts:124
  • TestingModulepackages/testing/testing-module.ts:26

Was this page helpful?

Download as PDF
AbstractHttpAdapter — NestJS head-to-head