GithubHelp home page GithubHelp logo

nryanov / consul4s Goto Github PK

View Code? Open in Web Editor NEW
6.0 3.0 4.0 578 KB

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

License: Apache License 2.0

Scala 100.00%
scala consul sttp client consul-api

consul4s's Introduction

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
  }
}

consul4s's People

Contributors

andreamarcolin avatar mergify[bot] avatar nryanov avatar sake92 avatar scala-steward avatar ssahayam-zd avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

consul4s's Issues

Update examples section

  • CatsBackendExample still using cats-effect 2.x, but sttp client was updated and now uses cats-effect 3.x

Upgrade sttp to 3.x

It would be nice if sttp could be updated to 3.x :)
To be fair sttp 3 changed its package name and organization, to allow sttp 2 to be included in projects side by side, so there shouldn't be cases of dependency hell.
Nonetheless I think that depending on the most recent major release could be beneficial in the long term, given that sttp 2 is also unlikely to receive many more updates and backports.

I'm soon going to migrate another project to sttp3, I can help migrating consul4s too after that if there is a desire!

Can we make Node optional in NewSession ?

Hi,

When creating a new session through the Session API, the Node name is mandatory in NewSession.

def createSession(newSession: NewSession, dc: Option[String] = None, token: Option[String] = None): F[Result[SessionId]]  


final case class NewSession(
  Node: String, //Mandatory
  LockDelay: String,
  Name: Option[String] = None,
  ID: Option[String] = None,
  Checks: Option[List[String]] = Some(List("serfHealth")),
  Behavior: SessionBehavior = SessionBehavior.Release,
  TTL: Option[String] = None
)

The Consul API does not require this as mandatory and it can be excluded, such that the requests is submitted to the cluster as opposed to a specific node.

Would be possible to make Node optional in NewSession?


final case class NewSession(
  Node: Option[String], //Optional
  LockDelay: String,
  Name: Option[String] = None,
  ID: Option[String] = None,
  Checks: Option[List[String]] = Some(List("serfHealth")),
  Behavior: SessionBehavior = SessionBehavior.Release,
  TTL: Option[String] = None
)

I'm happy to submit a PR to update this, if this change is acceptable.

Integrate scala-steward and mergify to keep dependencies up-to-date

By opening a PR to scala-steward public instance and (eventually) adding mergify, it's way easier to keep dependencies of a public project up to date.
It should be just a matter of opening a PR to https://github.com/scala-steward-org/repos/blob/master/repos-github.md (adding a line with the repo name) and then signing up to mergify with the github account (free for OSS).
Example configurations for Mergify:

Add scalafmt?

From what I can see the project contains a .scalafmt.conf file. Scalafmt sbt plugin is not present though, not sure if it's just an oversight or if the file was included by accident.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.