Last active
August 29, 2015 14:19
-
-
Save healsjnr/f82c376995a8130a5be5 to your computer and use it in GitHub Desktop.
Naive WebService Request
This file contains 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
def getUserData(userId: Int): Future[JsValue] = { | |
val request = WS.url("http://example.com/user/1").withHeaders("Content-Type" -> "application/json").get() | |
request.map { response => | |
if (response.status == 200) { | |
response.json | |
} else { | |
throw new Exception("Error received. Status: ${response.status} Body: ${response.json}") | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment