com.soundcloud.twinagle.ClientEndpointBuilder.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of twinagle-runtime_2.13 Show documentation
Show all versions of twinagle-runtime_2.13 Show documentation
An implementation of the Twirp protocol on top of Finagle
The newest version!
package com.soundcloud.twinagle
import com.twitter.finagle.http.{Request, Response}
import com.twitter.finagle.{Filter, Service}
import scalapb.{GeneratedMessage, GeneratedMessageCompanion}
/** ClientEndpointBuilder is not part of Twinagle's public API.
* It is only public because it is referenced from generated code and may change at any time.
*/
class ClientEndpointBuilder(
httpClient: Service[Request, Response],
extension: EndpointMetadata => Filter.TypeAgnostic,
prefix: String
) {
if (prefix.nonEmpty) {
require(prefix.startsWith("/"), "prefix must start with slash")
require(!prefix.endsWith("/"), "prefix must not end with slash")
}
def jsonEndpoint[
Req <: GeneratedMessage,
Resp <: GeneratedMessage: GeneratedMessageCompanion
](
endpointMetadata: EndpointMetadata
): Service[Req, Resp] = {
extension(endpointMetadata).toFilter andThen
new TracingFilter[Req, Resp](endpointMetadata) andThen
new JsonClientFilter[Req, Resp](s"$prefix/${endpointMetadata.service}/${endpointMetadata.rpc}") andThen
new TwirpHttpClient andThen
httpClient
}
def protoEndpoint[
Req <: GeneratedMessage,
Resp <: GeneratedMessage: GeneratedMessageCompanion
](
endpointMetadata: EndpointMetadata
): Service[Req, Resp] = {
extension(endpointMetadata).toFilter andThen
new TracingFilter[Req, Resp](endpointMetadata) andThen
new ProtobufClientFilter[Req, Resp](s"$prefix/${endpointMetadata.service}/${endpointMetadata.rpc}") andThen
new TwirpHttpClient andThen
httpClient
}
}