
# 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

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

## Example

```dart
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);
```

```bash
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

- [A function from an empty directory](first-function.md): a small REST API over a Supabase table, run, tested, run locally, deployed.
- [Building](building.md): the command, its options, what is written for each platform, WebAssembly, a deploy workflow, sizes.
- [Deploying a function](deploying.md): step by step for Supabase, Cloudflare and AWS, by hand and from GitHub Actions, secrets, checking a deployed function.
- [Supabase Edge Functions](supabase.md): the context path, the environment, `verify_jwt`, the anon key, the local stack.
- [Cloudflare Workers](cloudflare.md): bindings (KV, D1), the rate limiter in D1, cron triggers.
- [AWS Lambda](aws.md): four triggers, base64, cookies, `--streaming`, EventBridge schedules.
- [Deno Deploy, Netlify, Vercel](other-platforms.md)
- [What a function does differently](differences.md): the table, `waitUntil`, work by a schedule, the warning list, the rate limiter.
- [All properties](properties.md)
- [Testing](testing.md): `FetchApplication`, `FetchRequest`, `FetchResponse`, where the starter's own tests run.

## Not yet

- Cloudflare's other bindings (queues, R2, Durable Objects).
- Azure Functions and Google Cloud Functions (their own request types; their container platforms run the ordinary server).
- Deploy workflows for Deno Deploy, Netlify and Vercel.

## In Spring (Java)

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

## See also

- [spring_boot_starter_web](../spring-boot-starter-web/index.md)
- [spring_boot_starter_supabase](../spring-boot-starter-supabase/index.md)
- [An Edge Function in Dart](../spring-boot-starter-supabase/edge-function.md)
- [What a build contains](optimizations.md)
