aim_server
A lightweight, modular web framework for Dart.
Features
- Context API - Intuitive request/response handling inspired by Hono
- Routing - Path parameters, wildcards, and method-based routing
- Middleware - Composable middleware chain with early response support
- Type-Safe - Custom
Variablesclasses for type-safe context variables - Validation - Declare a request's shape once and read it back with static types, no code generation
- Modular - Use only the middleware packages you need
- Runs anywhere - The same app runs on the Dart VM (
aim_server), on Cloudflare Workers (aim_workers), on Supabase Edge Functions (aim_deno), and, experimentally, on Cloud Functions for Firebase (aim_functions)
Quick Start
Installation
bash
dart pub add aim_serverHello World
dart
import 'dart:io';
import 'package:aim_server/aim_server.dart';
void main() async {
final app = Aim();
app.get('/', (c) async {
return c.json({'message': 'Hello, Aim!'});
});
await app.serve(host: InternetAddress.anyIPv4, port: 8080);
print('Server running on http://localhost:8080');
}With Middleware
dart
import 'dart:io';
import 'package:aim_server/aim_server.dart';
import 'package:aim_server_cors/aim_server_cors.dart';
import 'package:aim_server_logger/aim_server_logger.dart';
void main() async {
final app = Aim();
// Add middleware
app.use(logger());
app.use(cors());
// Routes
app.get('/users', (c) async {
return c.json({'users': []});
});
app.post('/users', (c) async {
final body = await c.req.json();
return c.json({'created': body}, statusCode: 201);
});
await app.serve(host: InternetAddress.anyIPv4, port: 8080);
}Middleware Packages
| Package | Description |
|---|---|
| aim_server_cors | CORS support |
| aim_server_cookie | Cookie management |
| aim_server_form | Form data parsing |
| aim_server_multipart | File uploads |
| aim_server_static | Static file serving |
| aim_server_logger | Request logging |
| aim_server_sse | Server-Sent Events |
| aim_server_jwt | JWT authentication |
| aim_server_basic_auth | Basic authentication |
| aim_server_testing | Test utilities |
Next Steps
- Installation - Detailed setup guide
- Quick Start - Build your first API
- Cloudflare Workers - Deploy the same app to the edge
- Supabase Edge Functions - Deploy the same app on Deno
- Cloud Functions for Firebase - Deploy the same app as an HTTP function (experimental)
- Routing - Path parameters and wildcards
- Middleware - Create custom middleware
- Validation - Validate request bodies and query strings with static types
