protoc-gen-scalapb-grpcweb


License

License

Categories

Categories

Scala Languages gRPC Net Networking
GroupId

GroupId

com.thesamet.scalapb.grpcweb
ArtifactId

ArtifactId

protoc-gen-scalapb-grpcweb
Last Version

Last Version

0.6.4
Release Date

Release Date

Type

Type

jar
Description

Description

protoc-gen-scalapb-grpcweb
protoc-gen-scalapb-grpcweb
Project URL

Project URL

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

Project Organization

com.thesamet.scalapb.grpcweb
Source Code Management

Source Code Management

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

Download protoc-gen-scalapb-grpcweb

How to add to project

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

Dependencies

There are no dependencies for this project. It is a standalone project that does not depend on any other jars.

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.6.2"
    
    resolvers += "Sonatype OSS Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots"
    
    addSbtPlugin("com.thesamet" % "sbt-protoc" % "1.0.3")
    
    libraryDependencies += "com.thesamet.scalapb" %% "compilerplugin" % "0.11.3"
    
    libraryDependencies += "com.thesamet.scalapb.grpcweb" %% "scalapb-grpcweb-code-gen" % grpcWebVersion
    
    addSbtPlugin("ch.epfl.scala" % "sbt-scalajs-bundler" % "0.20.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.grpcweb

ScalaPB

ScalaPB

Versions

Version
0.6.4
0.6.3
0.6.2
0.6.1
0.6.0
0.5.0
0.4.2
0.4.1
0.4.0
0.3.0