Lift a value asynchronously into a HTTP computation.
Lift a value asynchronously into a HTTP computation.
The result will be computed concurrently according to ExecutionContext.global.
lazy val bigExpensiveComputation: Int = ??? val x: Http[String, Int] = HttpOps[String].async(bigExpensiveComputation)
Wrap an asynchronous computation without handling exceptions.
Wrap an asynchronous computation without handling exceptions.
Any exception thrown by the original future will propagate up via Future.failed.
Wrap an arbitrary asynchronous computation, and selectively recover from them.
Wrap an arbitrary asynchronous computation, and selectively recover from them.
If a particular exception isn't handled, then it is propagated up via Future.failed.
import scala.concurrent.ExecutionContext.Implicits.global val x: Http[String, Int] = HttpOps[String].liftFutureHandle(Future("abc".toInt)) { case _: NumberFormatException => HttpOps[String].raiseError("Bad number") } scala> x res0: com.pagerduty.sprayfunclient.Http[String, Int] = // ...
Map over the result of two independent HTTP computations.
Map over the result of two independent HTTP computations.
val x: Http[String, Int] = HttpOps[String].unit(3) val y: Http[String, Double] = HttpOps[String].unit(4.2) scala> HttpOps[String].map2(x, y) { _.toInt + _ } res0: com.pagerduty.sprayfunclient.Http[String, Double] = // ...
Fail the computation with a specific error.
Fail the computation with a specific error.
The error will short-circuit any future computations.
Errors can be manipulated via Http.mapError or recovered from via Http.handleError.
def sqrt(x: Double): Http[String, Double] = { if (x < 0) HttpOps[String].raiseError("negative number") else HttpOps[String].unit(math.sqrt(x)) } scala> sqrt(4.0) res0: com.pagerduty.sprayfunclient.Http[String, Double] = // ... scala> sqrt(-4) res1: com.pagerduty.sprayfunclient.Http[String, Double] = // ...
Execute multiple HTTP computations.
Execute multiple HTTP computations.
Asynchronous computations started via async will execute concurrently.
The computation fails if any one of the computations fail.
val x = HttpOps[String].async("First big computation") val y = HttpOps[String].async("Second big computation") scala> HttpOps[String].sequence(Seq(x, y)) res0: com.pagerduty.sprayfunclient.Http[String, Seq[String]] = // ...
Add a HTTP request and it's execution time to the request log.
Add a HTTP request and it's execution time to the request log.
This log is accessible when the computation is "run" via Http.asFutureWithLog.
request automatically invokes trace, so it is not necessary to invoke it manually when making HTTP requests.
Lift a value into an HTTP computation.
Lift a value into an HTTP computation.
The value is strict (computed immediately).
val x = HttpOps[String].unit(3.2)