HttpServers.kt

  1. package com.hexagonkt.http.server

  2. import com.hexagonkt.http.handlers.HandlerBuilder
  3. import com.hexagonkt.http.handlers.HttpHandler

  4. /**
  5.  * Create a server and start it.
  6.  *
  7.  * @param adapter Adapter instance which implements [HttpServerPort].
  8.  * @param handler Handler to be used by the server.
  9.  * @param settings Server settings info.
  10.  *
  11.  * @return The started [HttpServer] instance.
  12.  */
  13. fun serve(
  14.     adapter: HttpServerPort,
  15.     handler: HttpHandler,
  16.     settings: HttpServerSettings = HttpServerSettings()
  17. ): HttpServer =
  18.     HttpServer(adapter, handler, settings).apply { start() }

  19. /**
  20.  * Create a server and start it.
  21.  *
  22.  * @param adapter Adapter instance which implements [HttpServerPort].
  23.  * @param settings Server settings info.
  24.  * @param block Lambda to be used to create the server's handlers.
  25.  *
  26.  * @return The started [HttpServer] instance.
  27.  */
  28. fun serve(
  29.     adapter: HttpServerPort,
  30.     settings: HttpServerSettings = HttpServerSettings(),
  31.     block: HandlerBuilder.() -> Unit
  32. ): HttpServer =
  33.     HttpServer(adapter, settings, block).apply { start() }