server_nano 1.5.1 server_nano: ^1.5.1 copied to clipboard
A light, very fast, and friendly http and websocket server written in dart.
import 'package:server_nano/server_nano.dart';
void main() {
final server = Server();
server.get('/', (req, res) {
res.sendJson({'Hello': 'World!'});
});
server.get('/user/:id', (req, res) async {
await Future.delayed(Duration(seconds: 2));
res.send('Hello User ${req.params['id']}!');
});
server.ws('/socket', (socket) {
socket.onMessage((message) {
print(message);
});
socket.join('tech-group');
socket.emitToRoom(
'connected', 'tech-group', 'User connected to tech-group');
});
server.listen(port: 3000, wsPort: 3001);
}