Provides javalin/jex style request handling for AWS Lambda HTTP requests.
Depending on your infrastructure, you can use ALBHttpEvent, APIGatewayV2HttpEvent, or APIGatewayProxyEvent.
Add dependency:
<dependency> <groupId>io.avaje</groupId> <artifactId>avaje-sigma</artifactId> <version>${sigma.version}</version> </dependency>Create Server:
public class LambdaRequestHandler implements RequestHandler<APIGatewayV2HttpEvent, AWSHttpResponse> { HttpFunction handler = Sigma.create() .routing( r -> r.get("/lambda", ctx -> ctx.text("Hello World")) .get("/route2/{param}", ctx -> ctx.text(ctx.pathParam("param")))) .createHttpFunction(); @Override public AWSHttpResponse handleRequest(APIGatewayV2HttpEvent event, Context context) { return handler.apply(event, context); } }Quick Start with Avaje Http
<dependency> <groupId>io.avaje</groupId> <artifactId>avaje-sigma</artifactId> <version>${sigma.version}</version> </dependency> <dependency> <groupId>io.avaje</groupId> <artifactId>avaje-http-api</artifactId> <version>${avaje.http.version}</version> </dependency> <!-- Annotation processor --> <dependency> <groupId>io.avaje</groupId> <artifactId>avaje-http-sigma-generator</artifactId> <version>${avaje.http.version}</version> <scope>provided</scope> <optional>true</optional> </dependency>In JDK 23+, annotation processors are disabled by default, you will need to add a flag to re-enable.
<properties> <maven.compiler.proc>full</maven.compiler.proc> </properties>package org.example.hello; import io.avaje.http.api.Controller; import io.avaje.http.api.Get; import java.util.List; @Controller("/widgets") public class WidgetController { private final HelloComponent hello; public WidgetController(HelloComponent hello) { this.hello = hello; } @Get("/{id}") Widget getById(int id) { return new Widget(id, "you got it"+ hello.hello()); } @Get() List<Widget> getAll() { return List.of(new Widget(1, "Rob"), new Widget(2, "Fi")); } record Widget(int id, String name){}; }This will generate routing code we can register using any JSR-330 compliant DI:
@Generated("avaje-sigma-generator") @Singleton public class WidgetController$Route implements HttpService { private final WidgetController controller; public WidgetController$Route(WidgetController controller) { this.controller = controller; } @Override public void setup(Router router) { router.get("/widgets/{id}", ctx -> { ctx.status(200); var id = asInt(ctx.pathParam("id")); var result = controller.getById(id); ctx.json(result); }); router.get("/widgets", ctx -> { ctx.status(200); var result = controller.getAll(); ctx.json(result); }); } }public class LambdaRequestHandler implements RequestHandler<APIGatewayV2HttpEvent, AWSHttpResponse> { HttpFunction handler; public LambdaRequestHandler() { List<HttpService> services = // Retrieve HttpServices via DI; handler = Sigma.create().routing(services).createHttpFunction(); } @Override public AWSHttpResponse handleRequest(APIGatewayV2HttpEvent event, Context context) { return handler.apply(event, context); } }