scalapb-grpcweb


License

License

Categories

Categories

Scala Languages gRPC Net Networking
GroupId

GroupId

com.thesamet.scalapb
ArtifactId

ArtifactId

scalapb-grpcweb_sjs1_2.13
Last Version

Last Version

0.2.0
Release Date

Release Date

Type

Type

jar
Description

Description

scalapb-grpcweb
scalapb-grpcweb
Project URL

Project URL

https://github.com/scalapb/scalapb-grpcweb
Project Organization

Project Organization

com.thesamet.scalapb
Source Code Management

Source Code Management

https://github.com/scalapb/scalapb-grpcweb

Download scalapb-grpcweb_sjs1_2.13

How to add to project

<!-- https://jarcasting.com/artifacts/com.thesamet.scalapb/scalapb-grpcweb_sjs1_2.13/ -->
<dependency>
    <groupId>com.thesamet.scalapb</groupId>
    <artifactId>scalapb-grpcweb_sjs1_2.13</artifactId>
    <version>0.2.0</version>
</dependency>
// https://jarcasting.com/artifacts/com.thesamet.scalapb/scalapb-grpcweb_sjs1_2.13/
implementation 'com.thesamet.scalapb:scalapb-grpcweb_sjs1_2.13:0.2.0'
// https://jarcasting.com/artifacts/com.thesamet.scalapb/scalapb-grpcweb_sjs1_2.13/
implementation ("com.thesamet.scalapb:scalapb-grpcweb_sjs1_2.13:0.2.0")
'com.thesamet.scalapb:scalapb-grpcweb_sjs1_2.13:jar:0.2.0'
<dependency org="com.thesamet.scalapb" name="scalapb-grpcweb_sjs1_2.13" rev="0.2.0">
  <artifact name="scalapb-grpcweb_sjs1_2.13" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.thesamet.scalapb', module='scalapb-grpcweb_sjs1_2.13', version='0.2.0')
)
libraryDependencies += "com.thesamet.scalapb" % "scalapb-grpcweb_sjs1_2.13" % "0.2.0"
[com.thesamet.scalapb/scalapb-grpcweb_sjs1_2.13 "0.2.0"]

Dependencies

compile (4)

Group / Artifact Type Version
org.scala-lang : scala-library jar 2.13.1
org.scala-js : scalajs-library_2.13 jar 1.0.0
com.thesamet.scalapb : scalapb-runtime_sjs1_2.13 jar 0.10.2
com.thesamet.scalapb : protobuf-runtime-scala_sjs1_2.13 jar 0.8.5

test (1)

Group / Artifact Type Version
org.scala-js : scalajs-test-bridge_2.13 jar 1.0.0

Project Modules

There are no modules declared in this project.

Snapshot Artifacts

scalapb-grpcweb

Experimental grpc-web support for ScalaPB

This library provides a code generator and runtime that enables calling gRPC services from your Scala.js code using grpc-web.

Usage:

  1. Add the following to your project/plugins.sbt:

    val grpcWebVersion = "0.3.0"
    
    resolvers += "Sonatype OSS Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots"
    
    addSbtPlugin("com.thesamet" % "sbt-protoc" % "0.99.31")
    
    libraryDependencies += "com.thesamet.scalapb" %% "compilerplugin" % "0.10.2"
    
    libraryDependencies += "com.thesamet.scalapb.grpcweb" %% "scalapb-grpcweb-code-gen" % grpcWebVersion
    
    addSbtPlugin("ch.epfl.scala" % "sbt-scalajs-bundler" % "0.17.0")
    
  2. Add a cross-project with the protos that will be shared by Scala.js and JVM:

    lazy val protos =
      crossProject(JSPlatform, JVMPlatform)
         .crossType(CrossType.Pure)
         .in(file("protos"))
         .settings(
           PB.protoSources in Compile := Seq(
             (baseDirectory in ThisBuild).value / "protos" / "src" / "main" / "protobuf"
           ),
           libraryDependencies += "com.thesamet.scalapb" %%% "scalapb-runtime" % scalapb.compiler.Version.scalapbVersion
         )
         .jvmSettings(
           libraryDependencies += "com.thesamet.scalapb" %% "scalapb-runtime-grpc" % scalapb.compiler.Version.scalapbVersion,
           PB.targets in Compile := Seq(
             scalapb.gen() -> (sourceManaged in Compile).value
           ),
         )
         .jsSettings(
           // publish locally and update the version for test
           libraryDependencies += "com.thesamet.scalapb.grpcweb" %%% "scalapb-grpcweb" % scalapb.grpcweb.BuildInfo.version,
           PB.targets in Compile := Seq(
             scalapb.gen(grpc=false) -> (sourceManaged in Compile).value,
             scalapb.grpcweb.GrpcWebCodeGenerator -> (sourceManaged in Compile).value
           )
         )
    
  3. In your client code, instantiate the stub like this:

    val stub = TestServiceStub.stub(Channels.grpcwebChannel("http://localhost:8081"))
    
  4. Now, you can call it like:

    // Make an async unary call
    stub.unary(req).onComplete {
      f => println("Unary", f)
    }
    
    // You can also pass metadata
    // Make sure header1 is accepted on the envoy config, otherwise the request will be rejected
    stub.unary(req, Metadata("header1" -> "value1")).onComplete {
      f => println("Unary", f)
    }
    
    // Make an async server streaming call
    stub.serverStreaming(req, new StreamObserver[Res] {
      override def onNext(value: Res): Unit = {
        println("Next: " + value)
      }
    
      override def onError(throwable: Throwable): Unit = {
        println("Error! " + throwable)
      }
    
      override def onCompleted(): Unit = {
        println("Completed!")
      }
    })
    

Check the full example

com.thesamet.scalapb

ScalaPB

ScalaPB

Versions

Version
0.2.0