Skip to content

Instantly share code, notes, and snippets.

@wadouk
Created November 23, 2022 18:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wadouk/dbe455395463ebd821c6535ee4843639 to your computer and use it in GitHub Desktop.
Save wadouk/dbe455395463ebd821c6535ee4843639 to your computer and use it in GitHub Desktop.
package server
import sttp.capabilities.zio.ZioStreams
import sttp.tapir.generic.auto.*
import sttp.tapir.json.zio.TapirJsonZio
import sttp.tapir.server.ziohttp.ZioHttpInterpreter
import sttp.tapir.ztapir.*
import sttp.tapir.{json, Endpoint, PublicEndpoint}
import zhttp.http.*
import zhttp.http.middleware.Cors.CorsConfig
import zhttp.service.Server
import zio.{ZIO, ZLayer}
object MyServer:
case class ServerConfig(port: Int)
case class Hello(int: Int)
import zio.json.*
implicit val helloDecoder: JsonDecoder[Hello] = DeriveJsonDecoder.gen[Hello]
implicit val helloEncoder: JsonEncoder[Hello] = DeriveJsonEncoder.gen[Hello]
val serverSetup: ZIO[Any, Nothing, Server[Any, Throwable]] =
def countCharacters(s: String): ZIO[Any, Nothing, Hello] = ZIO.succeed(Hello(s.length))
val apiEndpoint = endpoint.securityIn(cookie[String]("hey")).zServerSecurityLogic(_ => ZIO.succeed(1))
val countCharactersEndpoint = apiEndpoint.in(stringBody).out(json.zio.jsonBody[Hello])
val value = countCharactersEndpoint.serverLogic(_ => countCharacters)
val countCharactersHttp: Http[Any, Throwable, Request, Response] = ZioHttpInterpreter().toHttp(value)
val serverConfig = ServerConfig(2000)
for _ <- ZIO.logInfo(s"Starting iesm-back on port ${serverConfig.port}")
yield Server.port(serverConfig.port) ++ Server.app(countCharactersHttp)
@wadouk
Copy link
Author

wadouk commented Nov 23, 2022

Get error

[error] 30 |        val countCharactersHttp: Http[Any, Throwable, Request, Response] = ZioHttpInterpreter().toHttp(value)
[error]    |                                                                                                       ^^^^^
[error]    |Found:    (value : sttp.tapir.ztapir.ZServerEndpoint[Nothing, Any])
[error]    |Required: sttp.tapir.ztapir.ZServerEndpoint[Any, sttp.capabilities.zio.ZioStreams

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment