spring_boot_starter_edge

spring_boot_starter_edge runs the same Spring for Dart application as a function: on Supabase Edge Functions, Cloudflare Workers, AWS Lambda, Deno Deploy, Netlify Edge Functions and Vercel Functions. The application is compiled to JavaScript (or WebAssembly) and answers through the platform's fetch API instead of a socket. Controllers, filters, Spring Security, Feign clients and the other starters are those of a server.

Why

A function platform starts an instance when a request comes and calls a JavaScript entry file with it. A Dart server cannot be that file: it opens a socket. The starter compiles the application with dart compile js, writes the entry file of the platform next to the result, and gives the entry a FetchApplication: a request goes in, a response comes out, the application's filters and controllers run in between. Nothing of the entry is written by hand.

Setup

dependencies:
  spring_boot_starter_edge: ^0.9.0   # brings and exports the web starter

Example

import 'package:spring_boot_starter_edge/spring_boot_starter_edge.dart';

import 'spring_gen/main.spring.dart';

@RestController()
class BooksController {
  @GetMapping('/books')
  Future<List<Book>> list() => books.all();
}

@SpringBootApplication()
void main() => runFetchApplication(() => springApplication);
dart run build_runner build
dart run spring_boot_starter_edge:build --platform supabase --name api

Run with dart run bin/main.dart, the same main starts an ordinary server on server.port: that is how a function is developed and debugged.

What is inside

Not yet

In Spring (Java)

The serverless Java container (SpringBootLambdaContainerHandler) and the adapters of Spring Cloud Function.

See also