Created
May 13, 2011 09:35
-
-
Save aloiscochard/970258 to your computer and use it in GitHub Desktop.
Scala REST WebService Client
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Sample usage of ... | |
// - Dispatch (http://dispatch.databinder.net) | |
// - SJSON (https://github.com/debasishg/sjson) | |
// ... to create a basic REST Web Service client for Twitter API | |
import dispatch._ | |
import scala.reflect.BeanInfo | |
import sjson.json.Serializer.SJSON | |
// Model | |
@BeanInfo class User(val screen_name: String, val description: String) { def this() = this("", "") } | |
// Http Request | |
val http = new Http | |
val json = http(:/("api.twitter.com") / "1/users/show.json" <<? Map("screen_name" -> "aloiscochard") >~ { _.getLines.mkString }) | |
// Deserialization | |
val user = SJSON.in[User](json) | |
println(user.description) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment