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
class SomeClass { | |
private def get(url: String): Future[Option[String]] = | |
for { | |
serviceResponse <- sendGetRequest(url) | |
} yield maybeBody(url, serviceResponse) | |
private def maybeBody(url: String, response: HttpResponse[String]): String = | |
if (response.is2xx) Some(response.body) | |
else None | |
private def sendGetRequest(url: String): Future[HttpResponse[String]] = | |
Future { | |
Http(url).headers(criticalHeaders).asString | |
} | |
private def criticalHeaders = Seq( | |
"x-http-request-id" -> Context.getRequestContext.getRequestId, | |
"x-http-caller-id" -> Context.getRequestContext.getCallerId, | |
"Accept" -> "application/json" | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment