Choosing an adapter
An adapter connects your app to an HTTP server. Your routes, middlewares, errors and tests do not depend on it: switching from one adapter to another changes one line of createApp().
Compared
Which one?
- Your team knows one of them, or your app already runs on it: take that one. Mount Dotpress on your existing application, next to its native routes, and move them over time.
- You need middlewares or plugins of a specific ecosystem (
helmet,@fastify/rate-limit, Hono middlewares…): take the server of that ecosystem. - The API runs on AWS Lambda: take Hono for the smallest bundle, or Fastify if you need its plugins.
- No preference: any of them works the same with Dotpress. You can change your mind later.
Coming from Dotpress 1, which ran on Express: keep Express to migrate in small steps.
The same behavior everywhere
Whatever the adapter, Dotpress itself:
- matches the routes, with the same rules: case-sensitive, static segments before parameters, trailing slashes ignored,
405with anAllowheader; - reads and parses the bodies: JSON, forms, text, multipart uploads, with the same size limit and errors;
- builds the responses, including streams and Server-Sent Events;
- formats the errors, including the client errors of native middlewares (a
4xxkeeps its status).
Every adapter passes the same conformance test suite of @dotpress/testing, which covers routing, parsing, validation, errors, middlewares and responses.
Common options
The app also gives access to the server:
app.native()returns the native application (Express app, Fastify instance, Hono app);adapter.server()returns the Node.js HTTP server started bylisten();ctx.rawis the native request (or context), as an escape hatch in a route.
app.close() waits for the pending requests, closes the responses being streamed, then runs the onClose hooks of the plugins: call it on SIGTERM for a graceful shutdown (see Node.js and containers).
In tests
The memory adapter of @dotpress/testing is an adapter too: it runs the requests in memory, without a port. See Testing.