akka-http-thrift-scrooge


License

License

Categories

Categories

Akka Container Microservices Reactive libraries
GroupId

GroupId

fr.davit
ArtifactId

ArtifactId

akka-http-thrift-scrooge_2.11
Last Version

Last Version

0.2.1
Release Date

Release Date

Type

Type

jar
Description

Description

akka-http-thrift-scrooge
akka-http-thrift-scrooge
Project URL

Project URL

https://github.com/RustedBones/akka-http-thrift
Project Organization

Project Organization

Michel Davit
Source Code Management

Source Code Management

https://github.com/RustedBones/akka-http-thrift

Download akka-http-thrift-scrooge_2.11

How to add to project

<!-- https://jarcasting.com/artifacts/fr.davit/akka-http-thrift-scrooge_2.11/ -->
<dependency>
    <groupId>fr.davit</groupId>
    <artifactId>akka-http-thrift-scrooge_2.11</artifactId>
    <version>0.2.1</version>
</dependency>
// https://jarcasting.com/artifacts/fr.davit/akka-http-thrift-scrooge_2.11/
implementation 'fr.davit:akka-http-thrift-scrooge_2.11:0.2.1'
// https://jarcasting.com/artifacts/fr.davit/akka-http-thrift-scrooge_2.11/
implementation ("fr.davit:akka-http-thrift-scrooge_2.11:0.2.1")
'fr.davit:akka-http-thrift-scrooge_2.11:jar:0.2.1'
<dependency org="fr.davit" name="akka-http-thrift-scrooge_2.11" rev="0.2.1">
  <artifact name="akka-http-thrift-scrooge_2.11" type="jar" />
</dependency>
@Grapes(
@Grab(group='fr.davit', module='akka-http-thrift-scrooge_2.11', version='0.2.1')
)
libraryDependencies += "fr.davit" % "akka-http-thrift-scrooge_2.11" % "0.2.1"
[fr.davit/akka-http-thrift-scrooge_2.11 "0.2.1"]

Dependencies

compile (3)

Group / Artifact Type Version
org.scala-lang : scala-library jar 2.11.12
fr.davit : akka-http-thrift_2.11 jar 0.2.1
com.twitter : scrooge-core_2.11 jar 19.11.0

provided (2)

Group / Artifact Type Version
com.typesafe.akka : akka-stream_2.11 jar 2.5.26
ch.qos.logback : logback-classic jar 1.2.3

test (3)

Group / Artifact Type Version
com.typesafe.akka : akka-testkit_2.11 jar 2.5.26
com.typesafe.akka : akka-http-testkit_2.11 jar 10.1.11
org.scalatest : scalatest_2.11 jar 3.1.0

Project Modules

There are no modules declared in this project.

akka-http-thrift

Build Status Maven Central Software License

akka-http thrift and json marshalling/unmarshalling for Thrift structs and Scrooge generated classes

Versions

Version Release date Akka Http version Thrift version Scrooge version Scala versions
0.2.1 2019-12-06 10.1.11 0.13.0 19.11.0 2.11.12, 2.12.10, 2.13.1
0.2.0 2019-07-13 10.1.8 0.11.0 19.1.0 2.11.12, 2.12.8
0.1.0 2019-01-31 10.1.7 0.11.0 19.1.0 2.11.12, 2.12.8

The complete list can be found in the CHANGELOG file.

Getting akka-http-thrift

Libraries are published to Maven Central. Add to your build.sbt:

libraryDependencies += "fr.davit" %% "akka-http-thrift"         % <version> // thrift support
libraryDependencies += "fr.davit" %% "akka-http-thrift-scrooge" % <version> // srooge support

Important: Since akka-http 10.1.0, akka-stream transitive dependency is marked as provided. You should now explicitly include it in your build.

[...] we changed the policy not to depend on akka-stream explicitly anymore but mark it as a provided dependency in our build. That means that you will always have to add a manual dependency to akka-stream. Please make sure you have chosen and added a dependency to akka-stream when updating to the new version

libraryDependencies += "com.typesafe.akka" %% "akka-stream" % <version> // Only Akka 2.5 supported

For more details, see the akka-http 10.1.x release notes

Quick start

For the examples, we are using the following thrift domain model

struct Item {
  1: string name
  2: i64 id
}

struct Order {
  1: list<Item> items
}

Marshalling/Unmarshalling of the generated classes depends on the Accept/Content-Type header sent by the client:

  • Content-Type: application/json: json
  • Content-Type: application/vnd.apache.thrift.json: json
  • Content-Type: application/vnd.apache.thrift.binary: binary
  • Content-Type: application/vnd.apache.thrift.compact: compact

-No Accept header or matching several (eg Accept: application/*) will take the 1st matching type from the above list.

Thrift

The implicit marshallers and unmarshallers for your generated thrift classes are defined in ThriftSupport. Specific (un)marshallers can be imported from ThriftBinarySupport, ThriftCompactSupport and ThriftJsonSupport. You simply need to have them in scope.

import akka.http.scaladsl.server.Directives
import fr.davit.akka.http.scaladsl.marshallers.thrift.ThriftSupport


class MyThriftService extends Directives with ThriftSupport {

  // format: OFF
  val route =
    get {
      pathSingleSlash {
        complete(Item("thing", 42))
      }
    } ~
    post {
      entity(as[Order]) { order =>
        val itemsCount = order.items.size
        val itemNames = order.items.map(_.name).mkString(", ")
        complete(s"Ordered $itemsCount items: $itemNames")
      }
    }
  // format: ON
}

Scrooge

The implicit marshallers and unmarshallers for your generated thrift classes are defined in ScroogeSupport. Specific (un)marshallers can be imported from ScroogeBinarySupport, ScroogeCompactSupport and ScroogeJsonSupport. You need to have them in scope as well as the ThriftStructCodec for the classes (The companion object generated by scrooge is the codec).

import akka.http.scaladsl.server.Directives
import fr.davit.akka.http.scaladsl.marshallers.thrift.scrooge.ScroogeSupport
import com.twitter.scrooge.ThriftStructCodec

class MyScroogeService extends Directives with ScroogeSupport {

  implicit val itemCodec: ThriftStructCodec[Item] = Item
  implicit val orderCodec: ThriftStructCodec[Order] = Order

  // format: OFF
  val route =
    get {
      pathSingleSlash {
        complete(Item("thing", 42))
      }
    } ~
    post {
      entity(as[Order]) { order =>
        val itemsCount = order.items.size
        val itemNames = order.items.map(_.name).mkString(", ")
        complete(s"Ordered $itemsCount items: $itemNames")
      }
    }
  // format: ON
}

Limitation

Entity streaming (http chunked transfer) is at the moment not supported by the library.

Versions

Version
0.2.1
0.1.0