Created
August 26, 2016 12:23
-
-
Save dcaoyuan/f2f70bed35c647a4d9a43dfdbcb6dbb8 to your computer and use it in GitHub Desktop.
akka-http-client-example
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
val uri = "http://www.yahoo.com" | |
val reqEntity = Array[Byte]() | |
val respEntity = for { | |
request <- Marshal(reqEntity).to[RequestEntity] | |
response <- Http().singleRequest(HttpRequest(method = HttpMethods.POST, uri = uri, entity = request)) | |
entity <- Unmarshal(response.entity).to[ByteString] | |
} yield entity | |
val payload = respEntity.andThen { | |
case Success(entity) => | |
s"""{"content": "${entity.utf8String}"}""" | |
case Failure(ex) => | |
s"""{"error": "${ex.getMessage}"}""" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment