This guide helps you migrate from WebApp v1.x to the new v2.0.1 release, which introduces significant new features and some breaking changes.
- MySQL Database Support: Full MySQL integration with query builder
- OpenAPI v3.0 Documentation: Automatic API documentation generation
- Enhanced WebSocket Support: Improved real-time communication
- Advanced Routing: Better authentication and permissions
- Form Validators: Built-in validation system
- WebApp CLI Enhancements: Improved development tools
v1.x: Dart 2.12+
v2.0.1: Dart 3.0+
# pubspec.yaml
environment:
sdk: '>=3.0.0 <4.0.0'
dependencies:
webapp: ^2.0.1
Some imports have been reorganized:
// OLD (v1.x)
import 'package:webapp/wa_server.dart';
import 'package:webapp/wa_route.dart';
// NEW (v2.0.1) - Same imports, but new features available
import 'package:webapp/wa_server.dart';
import 'package:webapp/wa_route.dart';
import 'package:webapp/wa_mysql.dart'; // NEW: MySQL support
import 'package:webapp/wa_openapi.dart'; // NEW: OpenAPI support
Server configuration has new optional parameters:
// OLD (v1.x)
WaConfigs configs = WaConfigs(
widgetsPath: pathTo('./widgets'),
languagePath: pathTo('./languages'),
port: 8085,
dbConfig: WaDBConfig(enable: false),
publicDir: pathTo('./public'),
);
// NEW (v2.0.1) - Same config, with new optional features
WaConfigs configs = WaConfigs(
widgetsPath: pathTo('./widgets'),
languagePath: pathTo('./languages'),
port: 8085,
dbConfig: WaDBConfig(enable: false),
publicDir: pathTo('./public'),
// NEW: Optional MySQL configuration
mysqlConfig: MySQLConfig(
host: 'localhost',
username: 'user',
password: 'pass',
database: 'mydb',
),
);
Update your pubspec.yaml
:
dependencies:
webapp: ^2.0.1
# Update other dependencies as needed
environment:
sdk: '>=3.0.0 <4.0.0'
Run dependency update:
If you haven't already, update to Dart 3.0+:
# Check current version
dart --version
# Update Dart (if using Flutter)
flutter upgrade
# Or update Dart SDK directly
# Follow instructions at https://dart.dev/get-dart
Most v1.x code will continue to work in v2.0.1. However, review these areas:
Your existing server setup should work without changes:
// This continues to work in v2.0.1
WaServer server = WaServer(configs: configs);
final socketManager = SocketManager(
server,
event: SocketEvent(
onConnect: (socket) {
// Your existing WebSocket code
},
),
routes: getSocketRoute(),
);
void main() async {
server.addRouting(getWebRoute);
server.start().then((value) {
Console.p('Server started: http://localhost:${value.port}');
});
}
Your existing routes will continue to work:
// Existing routes work unchanged
Future<List<WebRoute>> getWebRoute(WebRequest rq) async {
return [
WebRoute(
path: '/',
rq: rq,
index: homeController.index,
),
// Your existing routes...
];
}
Take advantage of new v2.0.1 features:
void main() async {
var server = WaServer(configs: configs);
// NEW: Enable OpenAPI documentation
server.enableOpenAPI(
title: 'My WebApp API',
version: '1.0.0',
description: 'My application API',
);
server.addRouting(getWebRoute);
await server.start();
}
Now access your API docs at: http://localhost:8085/docs
// NEW: MySQL integration
import 'package:webapp/wa_mysql.dart';
class UserController extends WaController {
Future<void> getUsers() async {
var query = Q()
.selects([QSelectAll()])
.from(QField('users'))
.where(WhereOne(QField('status'), QO.EQ, QVar('active')))
.limit(10);
var result = await mysqlConnection.execute(query.toSQL());
return rq.renderJson({'data': result});
}
}
@OpenAPIController(tag: 'Users')
class UserController extends WaController {
@OpenAPIOperation(
summary: 'Get all users',
responses: {
200: OpenAPIResponse(description: 'Users retrieved successfully'),
},
)
Future<void> getUsers() async {
// Your existing code
}
}
Ensure your existing functionality works:
# Start your application
dart run
# or
webapp run
# Test your existing endpoints
curl http://localhost:8085/
Test new features if you've enabled them:
# Test OpenAPI documentation
curl http://localhost:8085/openapi.json
# View Swagger UI
open http://localhost:8085/docs
Test the enhanced CLI:
# Update WebApp CLI
dart pub global activate webapp
# Test CLI commands
webapp --version
webapp --help
Problem: Dart version compatibility issues
Solution:
# Update Dart to 3.0+
flutter upgrade
# or follow Dart installation guide
# Clean and rebuild
dart pub cache clean
dart pub get
Problem: Dependency version conflicts
Solution:
# Update all dependencies
dart pub upgrade
# If conflicts persist, check dependency_overrides in pubspec.yaml
Problem: New import paths not found
Solution:
// Ensure you're importing from the correct package
import 'package:webapp/wa_mysql.dart'; // For MySQL features
import 'package:webapp/wa_openapi.dart'; // For OpenAPI features
v2.0.1 introduces connection pooling for better performance:
// Configure connection pool for production
var mysqlConfig = MySQLConfig(
host: 'localhost',
username: 'user',
password: 'pass',
database: 'mydb',
poolSize: 10, // NEW: Connection pooling
timeout: Duration(seconds: 30),
);
v2.0.1 has improved memory management, but consider these best practices:
// Use connection pooling for database operations
// Close resources properly in controllers
// Use appropriate caching strategies
If you encounter issues, you can rollback to v1.x:
# pubspec.yaml
dependencies:
webapp: ^1.1.2 # Last stable v1.x version
environment:
sdk: '>=2.12.0 <4.0.0'
When reporting migration issues, include:
- WebApp version (before and after)
- Dart/Flutter version
- Operating system
- Error messages
- Minimal code example
WebApp v2.0.1 provides significant new capabilities while maintaining backward compatibility for most use cases. The migration should be straightforward for most applications, and the new features provide substantial value for modern web application development.
Take your time to test thoroughly, and don't hesitate to reach out for help if you encounter any issues during the migration process.