FinchApp class

A comprehensive web application server framework for Dart. The FinchApp class provides a complete HTTP server implementation with built-in support for routing, database connectivity (MongoDB and MySQL), WebSocket management, scheduled tasks (cron jobs), and development tools. Features:

  • HTTP request/response handling with middleware support
  • MongoDB and MySQL database integration
  • WebSocket server capabilities
  • Cron job scheduling
  • Multi-language support
  • Development debugging tools
  • Migration system for database schema management Example usage:
final config = FinchConfigs(
  ip: '0.0.0.0',
  port: 8080,
  dbConfig: DbConfig(
    enable: true,
    link: 'mongodb://localhost:27017/myapp'
  ),
);
final server = FinchApp(configs: config);
await server.start();

Constructors

FinchApp({required FinchConfigs configs, Future<Request> onRequest(Request rq)?})
Creates an instance of FinchApp with the specified FinchConfigs and an optional onRequest function. The configs parameter is required and provides the configuration for the server. The onRequest parameter, if provided, allows customization of the Request before handling.

Properties

commands List<CappController>
getter/setter pair
crons List<FinchCron>
A list of FinchCron instances representing scheduled tasks.
final
debugger SocketManager?
WebSocket-based debugger for local development. Provides real-time debugging capabilities including route inspection, memory monitoring, language reloading, and server restart functionality. Only active when config.enableLocalDebugger and config.isLocalDebug are true.
getter/setter pair
hashCode int
The hash code for this object.
no setterinherited
hasSocket bool
A boolean indicating if the server has an active WebSocket manager.
no setter
mongoDb Db
Gets the MongoDB database instance. If the database is not connected, this method will attempt to connect to MongoDB. Throws an exception if the database is not running.
no setter
mysqlDb → MySQLConnection
no setter
mysqlDriver DatabaseDriver<MySQLConnection>
no setter
onRequest Future<Request> Function(Request rq)?
A function that takes a Request and returns a Future containing the modified Request.
getter/setter pair
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
server HttpServer?
The HTTP server instance.
getter/setter pair
socketManager SocketManager?
Manages WebSocket connections.
getter/setter pair
sqliteDb Database
no setter
sqliteDriver DatabaseDriver<Database>
no setter

Methods

addRouting(Future<List<FinchRoute>> router(Request rq)) FinchApp
Adds a routing function to the server. The router function returns a Future containing a list of FinchRoute based on the provided Request. This allows for dynamic routing based on the request. Returns the FinchApp instance to allow method chaining.
all({required String path, Future<String> index(Request rq)?, List<String> methods = Methods.ALL, AuthController? auth, List<FinchRoute> children = const [], List<String> extraPath = const [], Future<ApiDoc>? apiDoc()?, Controller? controller, List<String> excludePaths = const [], List<String> hosts = const ['*'], List<int> ports = const [], String? key, Map<String, dynamic> params = const {}, List<String> permissions = const []}) FinchApp
cleanRoutes() FinchApp
Clears all registered routes from the server. Returns the FinchApp instance to allow method chaining. Note: This will remove all routes, so use with caution.
connectMongoDb() Future<Db>
Connects to MongoDB using the connection string from the configuration. If config.dbConfig.enable is true, the database connection is opened. Returns a Future containing the mongo.Db instance.
connectMysqlDb() Future<void>
Connects to MySQL using the connection string from the configuration.
connectSqliteDb() Future<void>
Connects to SQLite using the connection string from the configuration.
debuggerInit() → void
Initializes the local development debugger system. Sets up a WebSocket-based debugging interface that provides:
exploreAllRoutes() Future<List<Map>>
get({required String path, Future<String> index(Request rq)?, AuthController? auth, List<FinchRoute> children = const [], List<String> extraPath = const [], Future<ApiDoc>? apiDoc()?, Controller? controller, List<String> excludePaths = const [], List<String> hosts = const ['*'], List<int> ports = const [], String? key, Map<String, dynamic> params = const {}, List<String> permissions = const []}) FinchApp
getAllRoutes() Future<List<FinchRoute>>
Get routing list of Server Here you can get all routing of server that added to server Returns a list of FinchRoute instances.
handleCommands(HttpServer server) Future<void>
Handles commands for the server, such as starting or stopping the server.
handleRequests(HttpServer server) Future<void>
Handles incoming HTTP requests by processing them through routing functions and the onRequest function. If config.dbConfig.enable is true, this method ensures the MongoDB database is connected before handling requests. The request is processed in a guarded zone to catch and log errors, and an error response is sent if needed.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
post({required String path, Future<String> index(Request rq)?, AuthController? auth, List<FinchRoute> children = const [], List<String> extraPath = const [], Future<ApiDoc>? apiDoc()?, Controller? controller, List<String> excludePaths = const [], List<String> hosts = const ['*'], List<int> ports = const [], String? key, Map<String, dynamic> params = const {}, List<String> permissions = const []}) FinchApp
postGet({required String path, Future<String> index(Request rq)?, AuthController? auth, List<FinchRoute> children = const [], List<String> extraPath = const [], Future<ApiDoc>? apiDoc()?, Controller? controller, List<String> excludePaths = const [], List<String> hosts = const ['*'], List<int> ports = const [], String? key, Map<String, dynamic> params = const {}, List<String> permissions = const []}) FinchApp
registerCron(FinchCron cron) → void
Registers a FinchCron instance to be scheduled. The cron parameter is the FinchCron instance to be registered.
restart() Future<void>
Restarts the server by stopping and starting it again. This method performs a graceful restart by:
start([List<String>? args, bool awaitCommands = true]) Future<HttpServer>
Starts the server and binds it to the specified IP and port. If config.noStop is true, the server will run within a guarded zone to handle errors. Otherwise, it runs normally. Returns a Future containing the HttpServer instance. If awaitCommands is true, it will also handle command-line inputs.
stop({bool force = true}) Future
Stops the server and closes the database connection. The force parameter specifies whether to forcefully close the server.
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Properties

appLanguages Map<String, Map<String, String>>
A map of application languages, where the key is the language code and the value is a map of strings.
getter/setter pair
config FinchConfigs
The server configuration.
getter/setter pair
info → _Info
Provides information about the version of the server.
final