Skip to content

Instantly share code, notes, and snippets.

@aloiscochard
Created May 13, 2011 09:35
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save aloiscochard/970258 to your computer and use it in GitHub Desktop.
Save aloiscochard/970258 to your computer and use it in GitHub Desktop.
Scala REST WebService Client
// 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