Code Monkey home page Code Monkey logo

helm's Introduction

Helm

Logo

Build Status Maven Central codecov

A native Scala client for interacting with Consul. There is currently one supported client, which uses http4s to make HTTP calls to Consul. Alternative implementations could be added with relative ease by providing an additional free interpreter for the ConsulOp algebra.

Getting Started

Add the following to your build.sbt:

libraryDependencies += "io.verizon.helm" %% "http4s" % "1.3.+"

The Helm binaries are located on maven central, so no additional resolvers are needed.

Algebra

Consul operations are specified by the ConsulOp algebra. Two examples are get and set:

import helm._

val s: ConsulOpF[Unit] = : ConsulOp.set("key", "value")

val g: ConsulOpF[Option[String]] = : ConsulOp.get("key")

These are however just descriptions of what operations the program might perform in the future, just creating these operations does not actually execute the operations. In order to perform the gets and sets, we need to use the http4s interpreter.

The http4s interpreter

First we create an interpreter, which requires an http4s client and a base url for consul:

import helm.http4s._
import org.http4s.Uri.uri
import org.http4s.client.blaze.PooledHttp1Client

val client = PooledHttp1Client()
val baseUrl = uri("http://127.0.0.1:8500")

val interpreter = new Http4sConsulClient(baseUrl, client)

Now we can apply commands to our http4s client to get back Tasks which actually interact with consul.

import scalaz.concurrent.Task

val s: Task[Unit] = helm.run(ConsulOp.set("testkey", "testvalue"))(interpreter)

val g: Task[String] = helm.run(ConsulOp.get("testkey"))(interpreter)

// actually execute the calls
s.run
g.run

Typically, the Helm algebra would be a part of a Coproduct with other algebras in a larger program, so running the Task immediately after helm.run is not typical.

Contributing

Contributions are welcome; particularly to expand the algebra with additional operations that are supported by Consul but not yet supported by Helm.

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.