Skip to content

Latest commit

 

History

History
63 lines (51 loc) · 2.61 KB

README.md

File metadata and controls

63 lines (51 loc) · 2.61 KB

consul4s

GitHub license Maven Central

A native Scala client for interacting with Consul built on top of sttp-client.

Features

Currently consul4s supports these endpoints:

  • agent
  • catalog
  • coordinate
  • event
  • health
  • kv
  • prepared queries (only existing query execution)
  • session
  • status
  • transaction

Modules

Consul4s uses multi-project structure and contains of the following modules_:

Installation

consul4s is published for Scala 2.13 and 2.12 to Maven Central, so just add the following to your build.sbt:

libraryDependencies ++= Seq(
  "com.nryanov.consul4s" %% "consul4s-core" % "[version]",
  // And one of the following:
  "com.nryanov.consul4s" %% "consul4s-circe" % "[version]",
  "com.nryanov.consul4s" %% "consul4s-json4s" % "[version]",
  "com.nryanov.consul4s" %% "consul4s-spray-json" % "[version]",
)

Also you can add any sttp-client backend you want.

Getting Started

Without any additional dependencies you can use the default HttpURLConnectionBackend as backend for requests. But sttp also supports other backend implementations:

STTP: Backend implementations include ones based on akka-http, async-http-client, http4s, OkHttp, and HTTP clients which ship with Java. They integrate with Akka, Monix, fs2, cats-effect, scalaz and ZIO.

import consul4s.v1._
import consul4s.circe._
import sttp.client.HttpURLConnectionBackend

object Main {
 def main(args: Array[String]): Unit = {
    val backend = HttpURLConnectionBackend()
    val client = ConsulClient(backend) // will use default host and port: http://localhost:8500

    for {
      datacenters <- client.getDatacenters().body
    } yield datacenters
  }
}