Skip to content

Introduce RelicApp class to simplify common usage patterns #222

Closed

Description

@nielsenko

Problem

Current usage requires too much boilerplate and isn't intuitive:

final router = Router<Handler>()
  ..get('/hello', handler);

await serve(router.asHandler, InternetAddress.anyIPv4, 8080);

Issues:

  • Not obvious why Router<Handler> instead of just Router
  • Need .asHandler extension every time
  • Requires dart:io import for InternetAddress
  • Doesn't match conventions from Express, Flask, ASP.NET Core, etc.

Proposed Solution

Add RelicApp extending Router<Handler>:

final class RelicApp extends Router<Handler> {
  Future<RelicServer> run(
    FutureOr<Adapter> Function() adapterFactory,
  ) async {
    final server = RelicServer(await adapterFactory());
    await server.mountAndStart(call);
    return server;
  }
}

// Platform extension
extension RelicAppIOServeEx on RelicApp {
  Future<RelicServer> serve({
    InternetAddress? address,
    int port = 8080,
    // ... other options
  }) => run(() async => IOAdapter(await bindHttpServer(...)));
}

Usage becomes:

final app = RelicApp()
  ..get('/hello', handler);

await app.serve(); // Defaults: localhost:8080

Benefits

  • Familiar pattern matching other frameworks
  • Less boilerplate, cleaner imports
  • Better discoverability via IDE autocomplete
  • Only ~10 lines of code
  • Non-breaking - purely additive
  • Advanced usage (custom adapters, composition) still supported

Activity

  1. added
    enhancement
    on Oct 14, 2025
  2. self-assigned this
    on Oct 14, 2025
  3. moved this from Inbox 📫 to In Progress 🔥 in Serverpod Frameworkson Oct 15, 2025
  4. added
    ux
    area: runtime
    on Oct 15, 2025
  5. moved this from In Progress 🔥 to Done 🚀 in Serverpod Frameworkson Oct 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area: runtimeenhancementux

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions