cornerman/covenant
null
{ "createdAt": "2018-02-06T19:54:00Z", "defaultBranch": "master", "description": null, "fullName": "cornerman/covenant", "homepage": null, "language": "Scala", "name": "covenant", "pushedAt": "2022-03-29T08:36:36Z", "stargazersCount": 8, "topics": [], "updatedAt": "2023-01-28T02:03:08Z", "url": "https://github.com/cornerman/covenant"}covenant
Section titled “covenant”Deprecated Check out fun-stack, sloth instead.
Simply create HTTP or Websocket Server and client in scala.
Server-side is JVM only and uses akka, client-side additionally supports scala-js.
Get via jitpack (add the following to your build.sbt):
resolvers += "jitpack" at "https://jitpack.io"libraryDependencies ++= Seq( "com.github.cornerman.covenant" %%% "covenant-http" % "master-SNAPSHOT", "com.github.cornerman.covenant" %%% "covenant-ws" % "master-SNAPSHOT")Define a trait as your Api:
trait Api { def fun(a: Int): Future[Int]}Server
Section titled “Server”Implement your Api:
object ApiImpl extends Api { def fun(a: Int): Future[Int] = Future.successful(a)}Define a router with sloth using e.g. boopickle for serialization:
import sloth._import boopickle.Default._import chameleon.ext.boopickle._import java.nio.ByteBufferimport cats.implicits._
val router = Router[ByteBuffer, Future].route[Api]!(ApiImpl)Plug the router into your akka-http server route:
import akka.http.scaladsl.Httpimport akka.http.scaladsl.server.RouteResult._import covenant.http._
Http().bindAndHandle(AkkaHttpRoute.fromFutureRouter(router), interface = "0.0.0.0", port = port)Client
Section titled “Client”Let sloth implement your Api on the client side:
import sloth._import boopickle.Default._import chameleon.ext.boopickle._import java.nio.ByteBufferimport cats.implicits._import covenant.http._
val client = HttpClient[ByteBuffer]!(yourUrl)val api: Api = client.wire[Api]Make requests to the server like normal method calls:
api.fun(1).foreach { num => println(s"Got response: $num")}Websocket
Section titled “Websocket”TODO: documentation
See: