All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.sbuslab.http.directives.SbusDirectives.scala Maven / Gradle / Ivy

There is a newer version: 1.2.26
Show newest version
package com.sbuslab.http.directives

import scala.concurrent.{ExecutionContext, Future}

import akka.http.scaladsl.server.{Directive1, Directives}

import com.sbuslab.http.Headers
import com.sbuslab.sbus.Context


trait SbusDirectives extends Directives {

  def sbusContext: Directive1[Context] = {
    optionalHeaderValueByName(Headers.CorrelationId).flatMap {
      case Some(corrId) ⇒ provide(Context.withCorrelationId(corrId))
      case _            ⇒ provide(Context.empty)
    }
  }

  def wrap[T](name: String)(f: Future[T])(implicit ec: ExecutionContext) =
    f.map(result ⇒ Map(name → result))
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy