spray-util

The spray-util module contains a number of smaller helper classes that are used by all other spray modules, except spray-http, which is kept intentionally free of other spray dependencies.

Dependencies

Apart from the Scala library (see Current Versions chapter) spray-util only depends on akka-actor (with ‘provided’ scope, i.e. you need to pull it in yourself).

Installation

The Maven Repository chapter contains all the info about how to pull spray-util into your classpath.

Afterwards just import spray.util._ to bring all relevant identifiers into scope.

Configuration

Just like Akka spray-util relies on the typesafe config library for configuration. As such its JAR contains a reference.conf file holding the default values of all configuration settings. In your application you typically provide an application.conf, in which you override Akka and/or spray settings according to your needs.

Note

Since spray uses the same configuration technique as Akka you might want to check out the Akka Documentation on Configuration.

This is the reference.conf of the spray-util module:

####################################
# spray-util Reference Config File #
####################################

# This is the reference config file that contains all the default settings.
# Make your edits/overrides in your application.conf.

spray {

  # Always contains the deployed version of spray.
  # Referenced, for example, from the `spray.can.server.server-header` setting.
  version = "<VERSION>"
}

Pimps

spray-util provides a number of convenient “extensions” to standard Scala and Akka classes.

The currently available pimps can be found here. Their hooks are placed in the spray.util package object, you bring them in scope with the following import:

import spray.util._

Side Note

Even though now officially somewhat frowned upon due to its arguably limited PC-ness we still like the term “pimps” for these, since it honors the origins of the technique (the “pimp-my-library” pattern, as it was originally coined by Martin Odersky in a short article in late 2006) and provides a very succinct and, in the scala community, well-known label for it.

LoggingContext

The LoggingContext is a simple akka.event.LoggingAdapter that can always be implicitly created. It is mainly used by spray-routing directives, which require a logging facility for an implicitly available ActorRefFactory (i.e. ActorSystem or ActorContext).