JdkHttpServer

sttp.tapir.server.jdkhttp.JdkHttpServer
case class JdkHttpServer(endpoints: Vector[ServerEndpoint[Any, Id]], options: JdkHttpServerOptions)

Attributes

Graph
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all

Members list

Value members

Concrete methods

def addEndpoint(se: ServerEndpoint[Any, Id]): JdkHttpServer
def addEndpoints(ses: List[ServerEndpoint[Any, Id]]): JdkHttpServer
def backlogSize(size: Int): JdkHttpServer

Sets the size of server's tcp connection backlog. This is the maximum number of queued incoming connections to allow on the listening socket. Queued TCP connections exceeding this limit may be rejected by the TCP implementation. If set to 0 or less the system default for backlog size will be used. Default is 0.

Sets the size of server's tcp connection backlog. This is the maximum number of queued incoming connections to allow on the listening socket. Queued TCP connections exceeding this limit may be rejected by the TCP implementation. If set to 0 or less the system default for backlog size will be used. Default is 0.

Attributes

def basePath(path: String): JdkHttpServer

Sets the base path under which your endpoints will be mounted, so if you have an endpoint configured to respond to /hello path and base path set to /api your endpoint will in fact respond under /api/hello path.

Sets the base path under which your endpoints will be mounted, so if you have an endpoint configured to respond to /hello path and base path set to /api your endpoint will in fact respond under /api/hello path.

The default base path is "/".

Attributes

def executor(executor: Executor): JdkHttpServer

Allows you to configure the Executor which will be used to handle HTTP requests. By default com.sun.net.httpserver.HttpServer uses a single thread (a calling thread executor to be precise) executor to handle traffic which might be fine for local toy projects.

Allows you to configure the Executor which will be used to handle HTTP requests. By default com.sun.net.httpserver.HttpServer uses a single thread (a calling thread executor to be precise) executor to handle traffic which might be fine for local toy projects.

If you intend to use this HTTP server for any deployments that will run under load it's absolutely necessary to set an executor that will use proper thread pool to handle the load. Recommended approach is to use JdkHttpServerOptions.httpExecutor method to create a ThreadPoolExecutor that will scale under load. You can also use an Executor returned from any of the constructors in the java.util.concurrent.Executors class.

Alternatively, if running with a JDK 19+ you can leverage Project Loom and use Executors.newVirtualThreadPerTaskExecutor() to run each request on a virtual thread. This however means it is possible for your server to be overloaded with work as each request will be given a thread with no backpressure on how many should be executed in parallel.

Attributes

def host(host: String): JdkHttpServer

Sets the hostname to which the server will be bound.

Sets the hostname to which the server will be bound.

Attributes

def https(httpsConfigurator: HttpsConfigurator): JdkHttpServer

Takes an instance of com.sun.net.httpserver.HttpsConfigurator, which is a thin wrapper around javax.net.ssl.SSLContext to configure the SSL termination for this server.

Takes an instance of com.sun.net.httpserver.HttpsConfigurator, which is a thin wrapper around javax.net.ssl.SSLContext to configure the SSL termination for this server.

Attributes

Replace the options - any modifications to the host, prot, executor etc. will be replaced with what is configured in the given options instance. Useful for customising interceptors.

Replace the options - any modifications to the host, prot, executor etc. will be replaced with what is configured in the given options instance. Useful for customising interceptors.

Attributes

def port(port: Int): JdkHttpServer

Sets the port to which the server will be bound.

Sets the port to which the server will be bound.

Attributes

def setup(): HttpServer

Use this if you want to add more routes manually, outside of the routes defined with tapir. Afterwards it is necessary to call HttpServer.start() to actually start the server.

Use this if you want to add more routes manually, outside of the routes defined with tapir. Afterwards it is necessary to call HttpServer.start() to actually start the server.

Attributes

def start(): HttpServer

Setup and start the server in the background.

Setup and start the server in the background.

Attributes

Inherited methods

def productElementNames: Iterator[String]

Attributes

Inherited from:
Product
def productIterator: Iterator[Any]

Attributes

Inherited from:
Product