chase library

Chase - A fast, lightweight web framework for Dart.

Classes

BasicAuth
Basic HTTP Authentication middleware.
BearerAuth
Bearer Token Authentication middleware.
BodyLimit
Middleware that limits the size of request bodies.
BodyLimitOptions
Options for configuring body size limits.
CacheControl
Cache-Control HTTP header middleware.
Chase
The main Chase application class.
ChaseBuilder
A builder for configuring and registering a single route.
ChaseBuilderAll
A builder for configuring routes that match ALL HTTP methods.
ChaseBuilderOn
A builder for configuring routes that match specific HTTP methods.
ChaseGroup
A route group that organizes routes under a common path prefix.
ChaseWebSocket
WebSocket connection for bidirectional real-time communication.
Compress
HTTP Response Compression middleware.
ConnInfo
Connection information for the current request.
ContentSecurityPolicy
Configuration for Content-Security-Policy header.
Context
The context for handling HTTP requests and responses.
CookieDuration
Common cookie duration presets.
Cors
CORS (Cross-Origin Resource Sharing) middleware.
CorsOptions
Options for configuring CORS behavior.
Csrf
CSRF (Cross-Site Request Forgery) Protection middleware.
DefaultLogger
Default logger implementation.
ETag
Middleware that automatically generates and validates ETags.
ETagCheckResult
Result of an ETag check.
ETagHelper
Helper class for computing ETags.
ETagOptions
Options for configuring ETag generation.
ExceptionHandler
Middleware that catches exceptions and returns appropriate error responses.
I18n
Internationalization (i18n) middleware.
IpRestriction
Middleware that restricts access based on client IP address.
JwtAuth
JWT (JSON Web Token) Authentication middleware.
Log
Zone-based logger with automatic context propagation.
LogConfig
Configuration for the global logger.
Logger
Abstract logger interface.
LogRecord
A structured log entry.
MemorySessionStore
In-memory session store.
MethodOverrideConfig
Configuration for HTTP method override.
Middleware
MultipartBody
Parsed multipart/form-data body containing fields and files.
MultipartFile
Represents an uploaded file from multipart/form-data.
NetAddrInfo
Network address information.
NullLogger
A silent logger that does nothing.
Plugin
Base class for Chase plugins.
PrettyJson
Middleware that formats JSON responses with indentation.
Proxy
HTTP Proxy middleware.
RateLimit
Middleware that limits the rate of incoming requests.
RateLimitInfo
Information about rate limit status.
RateLimitOptions
Options for configuring rate limiting.
RateLimitStore
In-memory store for rate limit data.
RegexRouter
A regex-based router implementation.
Req
HTTP request wrapper providing convenient access to request data.
RequestId
Middleware that assigns a unique ID to each request.
RequestIdOptions
Configuration options for RequestId middleware.
RequestLogger
Structured HTTP request logging middleware with request ID and log context.
Res
HTTP response wrapper providing low-level access to the response.
Response
An immutable HTTP response object.
ResponseBuilder
A builder for creating Response objects with fluent API.
RouteMatch
Router
An interface for a router that can add routes and match incoming requests to handlers. Implementations of this interface should provide mechanisms to store and retrieve routes based on HTTP methods and paths.
Schema
Defines a validation schema for structured data.
SecureHeaders
Middleware that adds security-related HTTP headers to responses.
SecureHeadersOptions
Options for configuring security headers.
Session
Middleware that provides session management.
SessionData
Session data container.
SessionOptions
Options for configuring session management.
SessionStore
Interface for session storage backends.
Sse
Server-Sent Events (SSE) streaming for real-time server-to-client communication.
SSEMessage
SSE event data.
SSEStreamApi
SSE stream API for Server-Sent Events (Hono-style).
StaticFileHandler
Handler for serving static files from the filesystem.
StaticOptions
Options for configuring static file serving behavior.
StreamApi
Stream API for binary streaming (Hono-style).
Streaming
Binary streaming for sending data chunks to the client.
StreamingResponse
A response that executes a streaming callback.
StrictTransportSecurity
Configuration for Strict-Transport-Security (HSTS) header.
TextStreamApi
Text stream API for text streaming (Hono-style).
TextStreaming
Text streaming for sending text data to the client.
Timeout
Middleware that enforces a timeout on request processing.
TimeoutOptions
Options for configuring request timeout.
Timing
Middleware that adds Server-Timing headers for performance monitoring.
TrailingSlash
Middleware that normalizes trailing slashes in URLs.
TranslationLoader
Loads translations from files.
Translator
Translator class for performing translations.
TrieRouter
V
Builder for creating validation rules.
ValidationError
Represents a validation error.
ValidationResult
Represents the result of a validation.
Validator
Creates a validation middleware.

Enums

AddressType
IP address type.
CookiePrefix
Cookie prefix for enhanced security.
CrossOriginEmbedderPolicy
Options for Cross-Origin-Embedder-Policy header.
CrossOriginOpenerPolicy
Options for Cross-Origin-Opener-Policy header.
CrossOriginResourcePolicy
Options for Cross-Origin-Resource-Policy header.
LogLevel
Log level for filtering log output.
ReferrerPolicy
Options for Referrer-Policy header.
SameSite
SameSite cookie attribute.
TrailingSlashMode
The mode of trailing slash handling.
XFrameOptions
Options for X-Frame-Options header.

Extensions

ChaseConvenience on Chase
Convenience extension for Chase with common middleware setup.
ChaseGroupConvenience on ChaseGroup
Static file serving extension for ChaseGroup.
ETagContextExtension on Context
Extension on Context for ETag support.
I18nContextExtension on Context
Extension on Context for i18n access.
I18nFileLoader on I18n
Extension on I18n for convenient file-based initialization.
RequestIdContextExtension on Context
Extension on Context for request ID access.
SessionContextExtension on Context
Extension on Context for session access.
TimeoutContextExtension on Context
Extension on Context for timeout-related functionality.
ValidationContextExtension on Context
Extension on Context for validation access.

Constants

log → const Log
Default logger instance for quick logging.

Functions

appendTrailingSlash({int redirectStatus = HttpStatus.movedPermanently}) TrailingSlash
Appends trailing slashes to URLs.
decodeCookieJson<T>(String encoded) → T?
Decodes a JSON cookie value.
encodeCookieJson(Object? value) String
Encodes an object as a JSON string for cookie storage.
endTime(Context ctx, String name) → void
Ends a timer started with startTime and records the metric.
formatSetCookie(String name, String value, {Duration? maxAge, DateTime? expires, String? domain, String? path, bool httpOnly = true, bool secure = false, SameSite? sameSite, bool partitioned = false, CookiePrefix prefix = CookiePrefix.none}) String
Formats a Set-Cookie header value.
ipRestriction({List<String> denyList = const [], List<String> allowList = const [], FutureOr onDenied(Context ctx, String ip)?}) IpRestriction
Creates an IP restriction middleware that allows only specified IPs.
parseCookieHeader(String? header) Map<String, String>
Parses a Cookie header into a map.
prettyJson({bool condition(Context ctx)?}) PrettyJson
Formats JSON responses with indentation.
requestId({String headerName = 'X-Request-Id', bool setResponseHeader = true, bool useIncoming = true, String generator()?, bool validator(String id)?}) RequestId
Convenience function to create a RequestId middleware.
setMetric(Context ctx, String name, {double? duration, String? desc, String? value}) → void
Sets a custom metric.
signCookieValue(String value, String secret) String
Signs a cookie value using HMAC-SHA256.
startTime(Context ctx, String name, {String? description}) → void
Starts a timer with the given name.
stream(Context ctx, Future<void> callback(StreamApi stream), {void onError(Object error, StreamApi stream)?, Map<String, String>? headers}) Response
Returns a binary streaming response.
streamSSE(Context ctx, Future<void> callback(SSEStreamApi stream), {void onError(Object error, SSEStreamApi stream)?}) Response
Returns a Server-Sent Events streaming response.
streamText(Context ctx, Future<void> callback(TextStreamApi stream), {void onError(Object error, TextStreamApi stream)?, String contentType = 'text/plain; charset=utf-8', Map<String, String>? headers}) Response
Returns a text streaming response.
timeAsync<T>(Context ctx, String name, Future<T> operation(), {String? description}) Future<T>
Times an async operation and records the metric.
timing({bool total = true, String totalDescription = 'Total Response Time', bool enabled(Context ctx)?, bool autoEnd = true, String? crossOrigin}) Timing
Creates a Timing middleware.
trimTrailingSlash({int redirectStatus = HttpStatus.movedPermanently}) TrailingSlash
Removes trailing slashes from URLs.
verifySignedCookieValue(String signedValue, String secret) String?
Verifies and extracts the value from a signed cookie.

Typedefs

BearerTokenValidator = FutureOr<bool> Function(String token)
Callback function for validating bearer tokens. Returns true if the token is valid, false otherwise.
CredentialValidator = FutureOr<bool> Function(String username, String password)
Callback function for validating credentials. Returns true if the credentials are valid, false otherwise.
ErrorHandler = FutureOr Function(Object error, StackTrace stackTrace, Context ctx)
A function that handles errors during request processing.
ETagGenerator = String Function(Uint8List content)
Function type for generating ETags from content.
Handler = FutureOr Function(Context ctx)
A function that handles an HTTP request.
IdGenerator = String Function()
Function type for generating request IDs.
JwtPayloadValidator = FutureOr<bool> Function(Map<String, dynamic> payload)
Callback function for validating JWT payload. Returns true if the payload is valid, false otherwise.
KeyExtractor = String Function(Context ctx)
Function type for extracting a unique key from a request.
LocaleResolver = String? Function(Context ctx)
Function type for resolving locale from context.
LogFormatter = String Function(LogRecord record)
Formatter for log records.
LogHandler = void Function(LogRecord record)
Handler for log records.
NextFunction = FutureOr Function()
OnLimitReached = void Function(Context ctx, RateLimitInfo info)
Function type for callback when rate limit is exceeded.
OriginCallback = bool Function(String? origin)
Callback function for dynamic origin validation. Returns true if the origin is allowed, false otherwise.
OriginValidator = bool Function(String origin, Context ctx)
Callback function for validating origin headers. Returns true if the origin is valid, false otherwise.
SecFetchSiteValidator = bool Function(String secFetchSite, Context ctx)
Callback function for validating Sec-Fetch-Site headers. Returns true if the sec-fetch-site value is valid, false otherwise.
TimeoutHandler = FutureOr<void> Function(Context ctx)
Function type for custom timeout handling.
Translations = Map<String, Map<String, dynamic>>
Translation messages type.
ValidationRule = ValidationError? Function(String field, dynamic value)
A validation rule that can be applied to a value.

Exceptions / Errors

BadRequestException
400 Bad Request - The request was invalid or cannot be served
ConflictException
409 Conflict - The request conflicts with the current state of the server
ForbiddenException
403 Forbidden - The request is valid but the server is refusing action
HttpException
Custom HTTP exception with status code support for Chase framework.
InternalServerErrorException
500 Internal Server Error - A generic error occurred on the server
JsonEncodingError
Thrown when JSON encoding fails.
NotFoundException
404 Not Found - The requested resource could not be found
ServiceUnavailableException
503 Service Unavailable - The server is not ready to handle the request
TimeoutException
Exception thrown when a request times out.
UnauthorizedException
401 Unauthorized - Authentication is required and has failed or not been provided
ValidationException
Exception thrown when validation fails.