Coder Social home page Coder Social logo

reboot's Introduction

Dispatch Reboot

Dispatch reboot is a rewrite of the Dispatch library for HTTP interaction in Scala, using sonatype/async-http-client as its underlying transport. For background on the project, read this series of blog posts.

The Scala project listing site ls tracks reboot's Maven artifact IDs and the latest release numbers.

Example Usage

The best examples of Dispatch reboot so far are conscript and herald which use it exclusively for HTTP interaction. The reboot tests, as ScalaCheck properties, are also a good source of example interaction.

And here is a very simple example to get you started:

import dispatch._
val raw = :/("raw.github.com").secure
val readme = raw / "dispatch" / "reboot" / "master" / "README.markdown"
val promise = Http(readme OK As.string)
for (string <- promise) {
  println(string)
}

Leaving the scene

Dispatch's client uses a thread-pool and, as usual when working in the Scala console or sbt interactive mode, you will need to shut it down manually to ensure a clean and quick exit.:

Http.shutdown()

Applications typically use one Dispatch executor instance and handle it in a general shutdown routine.

Promises

Dispatch's Promise is a rich interface to the underlying client's ListenableFuture. It is designed to make it as easy and elegant as possible to work with expected responses and the errors that might occur, and to avoid blocking operations while promoting composability.

For example, two functions that perform network operations might both yield a Promise to avoid blocking, and these could be composed in a third trivial function:

def add(p1: Promise[Int], p2: Promise[Int]): Promise[Int] =
  for {
    i1 <- p1
    i2 <- p2
  } yield i1 + i2

Since errors are known to occur, we might want to work with a different type of Promise:

def add(p1: Promise[Either[String,Int]],
        p2: Promise[Either[String,Int]])
        : Promise[Either[String,Int]] =
  for {
    i1 <- p1.right
    i2 <- p2.right
  } yield i1 + i2

The Future

The forthcoming Scala 2.10 defines a Future/Promise type and Dispatch will bind to it once it's available. Dispatch also supports Scala 2.8.x and 2.9.x; its aim is to create an interface that works well with existing software and with what's coming down the pike.

OAuth

OAuth is built into reboot just like in the original Dispatch. See Herald for an implementation that is configured for Tumblr.

reboot's People

Contributors

romanb avatar softprops avatar

Stargazers

 avatar

Watchers

 avatar  avatar

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.