Skip to content

Commit 5d72e8b

Browse files
authored
Add usage instructions (#26)
1 parent 50732cc commit 5d72e8b

File tree

1 file changed

+38
-1
lines changed

1 file changed

+38
-1
lines changed

README.md

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)