HttpClientPort.kt

  1. package com.hexagontk.http.client

  2. import com.hexagontk.http.HttpFeature
  3. import com.hexagontk.http.model.HttpProtocol
  4. import com.hexagontk.http.model.HttpRequestPort
  5. import com.hexagontk.http.model.HttpResponsePort
  6. import com.hexagontk.http.model.ServerEvent
  7. import com.hexagontk.http.model.ws.WsSession
  8. import java.util.concurrent.Flow.Publisher

  9. interface HttpClientPort {

  10.     fun startUp(client: HttpClient)

  11.     fun shutDown()

  12.     fun started(): Boolean

  13.     fun send(request: HttpRequestPort): HttpResponsePort

  14.     fun sse(request: HttpRequestPort): Publisher<ServerEvent>

  15.     fun ws(
  16.         path: String,
  17.         onConnect: WsSession.() -> Unit,
  18.         onBinary: WsSession.(data: ByteArray) -> Unit,
  19.         onText: WsSession.(text: String) -> Unit,
  20.         onPing: WsSession.(data: ByteArray) -> Unit = {},
  21.         onPong: WsSession.(data: ByteArray) -> Unit = {},
  22.         onClose: WsSession.(status: Int, reason: String) -> Unit,
  23.     ): WsSession

  24.     /**
  25.      * Return the client adapter's supported features.
  26.      *
  27.      * @return Set of supported features.
  28.      */
  29.     fun supportedFeatures(): Set<HttpFeature>

  30.     /**
  31.      * Return the server adapter's supported protocols.
  32.      *
  33.      * @return Set of supported protocols.
  34.      */
  35.     fun supportedProtocols(): Set<HttpProtocol>
  36. }