File tree Expand file tree Collapse file tree 1 file changed +38
-1
lines changed Expand file tree Collapse file tree 1 file changed +38
-1
lines changed Original file line number Diff line number Diff line change @@ -70,7 +70,44 @@ supports_message_receive_limit: false
7070
7171## Usage
7272
73- TODO: Add usage instructions
73+ Library is installed via SBT (you also need to install particular ` http4s` server implementation):
74+
75+ ` ` ` scala
76+ libraryDependencies ++= Seq(
77+ "io.github.igor-vovk" %% "connect-rpc-scala-core" % "<version>",
78+ "org.http4s" %% "http4s-ember-server" % "0.23.29"
79+ )
80+ ` ` `
81+
82+ After installing the library, you can expose your GRPC service to the clients using Connect-RPC protocol (suppose you
83+ already have a GRPC services generated with ScalaPB) :
84+
85+ ` ` ` scala
86+ import org.ivovk.connect_rpc_scala.ConnectRpcHttpRoutes
87+
88+ // Your GRPC service(s)
89+ val grpcServices: Seq[io.grpc.ServiceDefinition] = ???
90+
91+ val httpServer: Resource[IO, org.http4s.server.Server] = {
92+ import com.comcast.ip4s.*
93+
94+ for {
95+ // Create httpApp with Connect-RPC routes, specifying your GRPC services
96+ httpApp <- ConnectRpcHttpRoutes.create[IO](grpcServices)
97+ .map(_.orNotFound)
98+
99+ // Create http server
100+ httpServer <- EmberServerBuilder.default[IO]
101+ .withHost(host"0.0.0.0")
102+ .withPort(port"8080")
103+ .withHttpApp(httpApp)
104+ .build
105+ } yield httpServer
106+ }
107+
108+ // Start the server
109+ httpServer.use(_ => IO.never).unsafeRunSync()
110+ ` ` `
74111
75112# # Development
76113
You can’t perform that action at this time.
0 commit comments