org.allenai.common

webapp

package webapp

Visibility
  1. Public
  2. All

Type Members

  1. class BingClient extends AnyRef

    A client that wraps calls to the Bing API.

  2. case class BingResult(query: String, pos: Int, id: String, url: String, title: String, description: String) extends Product with Serializable

    A simple case class representing one of the "blue links" from a Bing API query.

  3. trait Directives extends AnyRef

    Helper spray directives.

  4. class InfoRoute extends AnyRef

    Class providing a spray route with common information, handling requests to the /info path.

    Class providing a spray route with common information, handling requests to the /info path. Requests to the root of the path return a string with all the info keys separated by newlines, while requests to subpaths return the value of the given key, or a 404 for invalid keys.

Value Members

  1. object Directives extends Directives

  2. object Headers

    Helpers for setting HTTP headers.

  3. object SprayClientHelpers

    Utility methods for sending HTTP requests through spray without being tripped-up by the nastiness of spray's API / underlying implementation.

    Utility methods for sending HTTP requests through spray without being tripped-up by the nastiness of spray's API / underlying implementation. The two methods in this object are intended for use together.

    Example: Making quick GET requests with little internal buffering. format: OFF

    import SprayClientHelpers._
    
    // Define parameters for sending requests to the foo service.
    // This can be done once per web client instance as part of initialization, if all of the
    // fields are constant.
    val quickConnectorSetup = getConnectionSetup(
      host = "foo.com",
      port = 1234,
      connectionTimeout = 500.millis,
      requestTimeout = 1.second,
      maxConnections = 100
    )
    
    // Define a function that requests a Foo object from the remote service and parses the
    // response JSON.
    def getFoo: Future[Foo] = sendRequest(Get("/foo"), quickConnectorSetup) { response =>
      response ~> unmarshal[Foo]
    }
    
    // Completes in ~ 1 second, either with a Seq of 100 Foos or spray's RequestTimeoutException.
    Future.sequence(Seq.fill(100) { getFoo })

    format: ON

    Example: Making slow, CPU-intensive POST requests with internal rate-limiting. format: OFF

    import SprayClientHelpers._
    
    val slowConnectorSetup = getConnectorSetup(
      host = "bar.com",
      port = 9876,
      connectionTimeout = 1.second,
      requestTimeout = 10.seconds,
      // Limit the number of in-flight requests at any one time to 4, to avoid overloading the
      // remote service.
      maxConnections = 4
    )
    
    def fooToBar(foo: Foo): Future[Bar] = {
      sendRequest(Post("/bar", foo), slowConnectorSetup) { response =>
        response ~> unmarshal[Bar]
      }
    }
    
    // Takes longer than 10 seconds! Only 4 requests will be sent over the wire at a time, and
    // the 10-second request timeout doesn't apply until a request gets sent out.
    Future.sequence(Seq.fill(16) { fooToBar(someFoo) })

    format: ON

Ungrouped