Skip to main content
Version: 2.x

Getting Started with ZIO Config

ZIO Config is a ZIO-based library and act as an extension to core library ZIO's Config language.

Production Ready CI Badge Sonatype Releases Sonatype Snapshots javadoc ZIO Config

Let's enumerate some key features of this library:

  • Support for Various Sources โ€” It can read flat or nested configurations from HOCON, JSON, YAML, TOML, XML, maps, and more. Thanks to IndexedFlat.
  • Automatic Document Generation โ€” It can auto-generate documentation of configurations.
  • Automatic Derivation โ€” It has built-in support for automatic derivation of readers and writers for case classes and sealed traits.
  • Type-level Constraints and Automatic Validation โ€” because it supports Refined types, we can write type-level predicates which constrain the set of values described for data types.
  • Descriptive Errors โ€” It accumulates all errors and reports all of them to the user rather than failing fast.
  • Integrations โ€” Integrations with a variety of libraries

If you are only interested in automatic derivation of configuration, find the details here

Installationโ€‹

In order to use this library, we need to add the following line in our build.sbt file:

libraryDependencies += "dev.zio" %% "zio-config" % "<version>"

Sourcesโ€‹

Add the modules you need for your config sources:

// HOCON / JSON
libraryDependencies += "dev.zio" %% "zio-config-typesafe" % "<version>"

// YAML
libraryDependencies += "dev.zio" %% "zio-config-yaml" % "<version>"

// TOML
libraryDependencies += "dev.zio" %% "zio-config-toml" % "<version>"

// XML (experimental)
libraryDependencies += "dev.zio" %% "zio-config-xml" % "<version>"

See Read from various Sources for examples of each.

Quick Start

Let's add these four lines to our build.sbt file as we are using these modules in our examples:

libraryDependencies += "dev.zio" %% "zio-config" % "<version>"
libraryDependencies += "dev.zio" %% "zio-config-magnolia" % "<version>"
libraryDependencies += "dev.zio" %% "zio-config-typesafe" % "<version>"
libraryDependencies += "dev.zio" %% "zio-config-refined" % "<version>"

There are many examples in here

ZIO Chat

Hi, fellow coder! ๐ŸŒŸ Welcome to your ZIO adventure with the ZIO Chat Bot. ๐Ÿš€ Let's master functional Scala together. From referential transparency to concurrent prowess, I've got your back. Ready to dive in? Your questions, my insights โ€“ let's conquer ZIO! ๐Ÿ’ก๐Ÿค–