Class ServerBuilder

java.lang.Object
com.linecorp.armeria.server.ServerBuilder

public final class ServerBuilder extends Object
Builds a new Server and its ServerConfig.

Example


 ServerBuilder sb = Server.builder();
 // Add a port to listen
 sb.http(8080);
 // Add services to the default virtual host.
 sb.service(...);
 sb.serviceUnder(...);
 // Build a server.
 Server s = sb.build();
 

Example 2


 ServerBuilder sb = Server.builder();
 Server server =
     sb.http(8080) // Add a port to listen
       .defaultVirtualHost() // Add services to the default virtual host.
           .service(...)
           .serviceUnder(...)
       .and().virtualHost("*.foo.com") // Add a another virtual host.
           .service(...)
           .serviceUnder(...)
       .and().build(); // Build a server.
 

What happens if no HTTP(S) port is specified?

When no TCP/IP port number or local address is specified, ServerBuilder will automatically bind to a random TCP/IP port assigned by the OS. It will serve HTTPS if you configured TLS (or HTTP otherwise), e.g.


 // Build an HTTP server that runs on an ephemeral TCP/IP port.
 Server httpServer = Server.builder()
                           .service(...)
                           .build();

 // Build an HTTPS server that runs on an ephemeral TCP/IP port.
 Server httpsServer = Server.builder()
                            .tls(...)
                            .service(...)
                            .build();
 
See Also:
VirtualHostBuilder