Spry

Test Pub Version GitHub license X (twitter) Documentation Netlify Status

Next-generation Dart server framework. Build modern servers and deploy them to the runtime you prefer.

Quick Start

Install the package:

dart pub add spry

Create a minimal project structure:

.
├─ routes/
│  └─ index.dart
└─ spry.config.dart

spry.config.dart

import 'package:spry/config.dart';

void main() {
  defineSpryConfig(
    host: '127.0.0.1',
    port: 4000,
    target: BuildTarget.dart,
  );
}

routes/index.dart

import 'package:spry/spry.dart';

Response handler(Event event) {
  return Response.json({
    'message': 'hello from spry',
    'runtime': event.context.runtime.name,
    'path': event.url.path,
  });
}

Start the dev server:

dart run spry serve

Core Ideas

  • routes/ defines request handlers with file routing
  • middleware/ and _middleware.dart shape cross-cutting request behavior
  • _error.dart provides scoped error handling
  • public/ serves static assets directly
  • spry.config.dart selects the runtime target and build behavior

Runtime Targets

Spry can emit output for:

  • Dart VM
  • Node.js
  • Bun
  • Deno
  • Cloudflare Workers
  • Vercel

WebSockets

Spry exposes websocket upgrades from the request event without introducing a second routing system.

import 'package:spry/spry.dart';
import 'package:spry/websocket.dart';

Response handler(Event event) {
  if (!event.ws.isSupported || !event.ws.isUpgradeRequest) {
    return Response('plain http fallback');
  }

  return event.ws.upgrade((ws) async {
    ws.sendText('connected');

    await for (final message in ws.events) {
      switch (message) {
        case TextDataReceived(text: final text):
          ws.sendText('echo:$text');
        case BinaryDataReceived():
        case CloseReceived():
          break;
      }
    }
  }, protocol: 'chat');
}

Current websocket support follows the underlying osrv runtime surface:

  • supported: Dart VM, Node.js, Bun, Deno, Cloudflare Workers
  • unsupported: Vercel, current Netlify Functions runtime

Documentation

Ask DeepWiki

Read the documentation at spry.medz.dev.

Start here:

License

MIT

Sponsors

Spry framework is an MIT licensed open source project with its ongoing development made possible entirely by the support of these awesome backers. If you'd like to join them, please consider sponsoring Seven(@medz) development.

sponsors

Contributing

Thank you to all the people who already contributed to Spry!

Contributors