val client = new HttpClientXLightWeb
client.host("somesite.com").get[ByteChunk]("/some/url")
That, plus some imports, is all you need val client = new HttpClientXLightWeb
client.host("somesite.com").get[ByteChunk]("/some/url")
That, plus some imports, is all you needIt's mostly an absurd comparison (equivalent to Fibonacci or something), and a tangent besides, but in Clojure:
(slurp "http://somesite.com/some/url")
That gives me the response as a string. If I want a binary stream: (clojure.java.io/input-stream "http://somesite.com/some/url")
The same functions work for URLs, URIs, Files, and strings that describe them.BlueEyes is a framework for writing high performance web services. For it's use cases you care whether you're getting or putting. Thus it is explicit. Similarly, you care about performance, and so don't want to parse strings if you can help it -- thus you set the host once rather than parsing a URL.
For a pure ease-of-use library Dispatch is probably the best, if you can figure out the syntax (see earlier discussion). In Dispatch you can write something like
url("http://somesite.com/some/url") >>> System.out
I forget how you read into a string. Probably change >>> to >>@!#$$T%^@#$% or similar.Of course, more involved interactions require an API with more knobs. Clojure has a number of options, including touching the JDK's HTTP client API, or using a wrapper around something more grounded like clj-http[1] / Apache HTTPComponents.
That being said, programmers can over-engineer things in any language; it's just that in Java, over-engineered things are "incomprehensible and huge" while in Scala over-engineering things are usually "incomprehensible and small".
Have any good recommendations for JSON parsers? This was another case where I found the common libraries to be rather obtuse.
https://github.com/lift/lift/tree/master/framework/lift-base...
Here's a summary:
The JSON AST is pretty straightforward. The JSON DSL works like this:
- A tuple ("key", value) constructs a key/value pair
- ~ joins them together to construct an object
E.g. ("foo", 1) ~ ("bar", "Hi") = {"foo": 1, "bar": "Hi"}
I never actually invoke the parser myself. BlueEyes does it if you change the ByteChunk is my example above to JValue.
Drop me an email (noel at untyped dot com) or tweet (@noelwelsh) or IM or Skype or whatever if you want to discuss more.
Alternatively, I've never used Coda Hale's Jerkson package, but I expect it is of high quality.
Does any of raw string <-> JSON AST, or maps/lists <-> JSON (...IIRC), or case objects <-> JSON (what I'm using it for, pseudo ORM).
val source = scala.io.Source.fromURL("http://news.ycombinator.com/item?id=3264849")