A client that wraps calls to the Bing API.
A simple case class representing one of the "blue links" from a Bing API query.
Helper spray directives.
Class providing a spray route with common information, handling requests to the /info path.
Helpers for setting HTTP headers.
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
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.