osrv 0.2.0 copy "osrv: ^0.2.0" to clipboard
osrv: ^0.2.0 copied to clipboard

Unified Dart server runtime for Dart, Node, Bun, Cloudflare, and Vercel.

osrv #

License: MIT Dart SDK GitHub stars

osrv is a unified server runtime for Dart applications.

It provides one portable Server contract and explicit runtime entrypoints for:

  • dart
  • node
  • bun
  • cloudflare
  • vercel

osrv is a runtime layer focused on running the same server contract across different host families, while keeping runtime capabilities and host-specific extensions explicit.

Why osrv #

Use osrv when you want:

  • one request-handling contract across multiple runtime families
  • explicit runtime selection instead of host auto-detection
  • honest capability reporting instead of fake cross-platform uniformity
  • typed runtime extensions for host-specific access

Features #

  • Unified Server contract built around Request, Response, and RequestContext
  • Explicit runtime selection through RuntimeConfig or defineFetchEntry(...)
  • Runtime capability model via RuntimeCapabilities
  • Lifecycle hooks: onStart, onStop, and onError
  • Typed runtime-specific extension access
  • Separate entry models for listener runtimes and fetch-export runtimes

Installation #

dart pub add osrv

Supported Runtimes #

Runtime Entry model Import
dart serve(server, DartRuntimeConfig(...)) package:osrv/runtime/dart.dart
node serve(server, NodeRuntimeConfig(...)) package:osrv/runtime/node.dart
bun serve(server, BunRuntimeConfig(...)) package:osrv/runtime/bun.dart
cloudflare defineFetchEntry(server, runtime: FetchEntryRuntime.cloudflare) package:osrv/runtime/cloudflare.dart + package:osrv/esm.dart
vercel defineFetchEntry(server, runtime: FetchEntryRuntime.vercel) package:osrv/runtime/vercel.dart + package:osrv/esm.dart

Quick Start #

Serve-Based Runtime #

import 'package:osrv/osrv.dart';
import 'package:osrv/runtime/dart.dart';

Future<void> main() async {
  final server = Server(
    fetch: (request, context) {
      return Response.json({
        'runtime': context.runtime.name,
        'path': request.url.path,
      });
    },
  );

  final runtime = await serve(
    server,
    const DartRuntimeConfig(host: '127.0.0.1', port: 3000),
  );

  print('Listening on ${runtime.url}');
}

Fetch-Export Runtime #

import 'package:osrv/osrv.dart';
import 'package:osrv/esm.dart';

void main() {
  defineFetchEntry(
    Server(
      fetch: (request, context) => Response.text('Hello from osrv'),
    ),
    runtime: FetchEntryRuntime.cloudflare,
  );
}

Example JavaScript shim:

import './cloudflare.dart.js';

export default { fetch: globalThis.__osrv_fetch__ };

Core API #

The public core entrypoint is package:osrv/osrv.dart.

Main exported concepts:

  • Server
  • serve(...)
  • Runtime
  • RuntimeConfig
  • RequestContext
  • RuntimeCapabilities
  • RuntimeExtension

For fetch-export runtimes, use package:osrv/esm.dart.

Documentation #

  • Documentation Index
  • Architecture
  • Configuration
  • Capabilities
  • Core API
  • Runtime API
  • Public Surface
  • Runtime Guides
  • Usage Examples

Examples #

The example directory contains runnable minimal entries for:

  • dart
  • node
  • bun
  • cloudflare
  • vercel

License #

MIT

5
likes
0
points
474
downloads

Documentation

Documentation

Publisher

verified publishermedz.dev

Weekly Downloads

Unified Dart server runtime for Dart, Node, Bun, Cloudflare, and Vercel.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

ht, web

More

Packages that depend on osrv