Main.java 851 B

123456789101112131415161718192021222324252627
  1. package benchmark;
  2. import io.avaje.inject.BeanScope;
  3. import io.avaje.jex.Jex;
  4. import io.avaje.jex.Routing.HttpService;
  5. import io.avaje.jsonb.Jsonb;
  6. import io.avaje.jsonb.Types;
  7. import java.util.Map;
  8. public class Main {
  9. public static void main(String[] args) {
  10. var beans = BeanScope.builder().build();
  11. var routes = beans.list(HttpService.class);
  12. var type = Jsonb.builder().build().type(Types.mapOf(String.class));
  13. Jex.create()
  14. .config(c -> c.compression().disableCompression())
  15. .get("/plaintext", ctx -> ctx.text("Hello, World!"))
  16. .get("/json", ctx -> ctx.jsonb(type, Map.of("message", "Hello, World!")))
  17. .before(ctx -> ctx.header("Server", "avaje-jex"))
  18. .error(Exception.class, (ctx, _) -> ctx.status(503).text("503 Service Unavailable"))
  19. .routing(routes)
  20. .start();
  21. }
  22. }