dart_node_express library

External Documentation

Express.js bindings for Dart

Classes

BoolValidator

IntValidator

Invalid<T>

Validation failed with field errors

OptionalValidator<T>

Schema<T>

StringValidator

Valid<T>

Validation succeeded with typed value

ValidationResult<T>

Validation result - sealed for exhaustive matching

Validator<T>

Base validator interface

Extension Types

ExpressApp

Express application

JSNextFunction

Type for Express next function with error support

Request

Express Request object

Response

Express Response object

Router

Express Router for modular route handling.

Extensions

ExpressAppMultiHandler on ExpressApp

Extension for routes with multiple handlers (middleware + handler)

ResponseExtensions on Response

Extension for convenient methods

Functions

asyncHandler(AsyncRequestHandler handler) JSFunction

Wraps an async handler for Express.js compatibility.

bool_() BoolValidator

Create a bool validator

chain(List<JSFunction> middlewares) JSFunction

Chains multiple middleware functions into a single handler.

errorHandler() JSFunction

Express error handler middleware.

express() ExpressApp

Create an Express application

getContext<T>(Request req, String key) → T?

Gets a value from the request context.

getValidatedBody<T>(Request req) → T

Get validated body from request (use after validateBody middleware)

handler(RequestHandler fn) JSFunction

Convert a Dart handler to a JS function

int_() IntValidator

Create an int validator

middleware(MiddlewareHandler handler) JSFunction

Converts a Dart middleware to JS function.

optional<T>(Validator<T> inner) OptionalValidator<T>

Make a validator optional (null is valid)

schema<T>(Map<String, Validator> fields, T constructor(Map<String, dynamic>)) Schema<T>

Create a schema for validating objects

setContext<T>(Request req, String key, T value) → void

Sets a value in the request context.

string() StringValidator

Create a string validator

validateBody<T>(Schema<T> schema) JSFunction

Create middleware that validates request body

Typedefs

AsyncRequestHandler = Future<void> Function(Request req, Response res)
Type definition for async request handlers
MiddlewareHandler = void Function(Request req, Response res, NextFunction next)
Type for synchronous middleware
NextFunction = void Function()
Type for Express next function
RequestHandler = void Function(Request req, Response res)
Handler function type

Exceptions / Errors

AppError

Base class for all application errors.

ConflictError

409 Conflict - resource already exists or state conflict

ForbiddenError

403 Forbidden - authenticated but not allowed

InternalError

500 Internal Server Error - unexpected server error

NotFoundError

404 Not Found - resource doesn't exist

UnauthorizedError

401 Unauthorized - missing or invalid authentication

ValidationError

400 Bad Request - validation or malformed request