Class ServerRequestHandler

java.lang.Object
io.karatelabs.http.ServerRequestHandler
All Implemented Interfaces:
Function<HttpRequest,HttpResponse>

public class ServerRequestHandler extends Object implements Function<HttpRequest,HttpResponse>
Main request handler implementing routing for static files, API endpoints, and HTML templates. Implements Function<HttpRequest, HttpResponse> for use with HttpServer.

Routing logic:

  1. If path starts with static prefix (e.g., /pub/) → serve static file
  2. If path starts with API prefix (e.g., /api/) → execute JS file
  3. Otherwise → render HTML template

Usage:

 ServerConfig config = new ServerConfig()
     .resourceRoot("classpath:web")
     .sessionStore(new InMemorySessionStore())
     .engineSupplier(Engine::new);

 ServerRequestHandler handler = new ServerRequestHandler(config, resolver);
 HttpServer server = HttpServer.start(8080, handler);