-
-
Save pablete/7d29f578709fbab3b60a98e1c9dccfb2 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