v18.0.0
What's New?
Public Interface Changes
The following interface changes are applied in this release:
withDecoded
is renamed towithDecode
inscamper.BodyParser
withQueryBody
is renamed towithFormBody
inscamper.Implicits.HttpMessageType
isInformational
,isSuccessful
,isRedirection
,isClientError
, andisServerError
are added toscamper.HttpResponse
scamper.client.ResponsePredicate
is removedwithOptionalHeader
andaddOptionalHeader
are added toscamper.MessageBuilder
; consequently they are implemented byHttpRequest
andHttpResponse
Optional Headers
When working with an optional header, you can now use withOptionalHeader
or addOptionalHeader
to not break the builder pattern.
def createRequest(userId: Long, bypassKey: Option[String]): HttpRequest =
GET("/users/$userId")
.withHeader("accept: text/plain")
.withHeader("accept-encoding: gzip, deflate")
.withOptionalHeader("bypass-key", bypassKey)
Prior to this release, the above example would have probably been written as follows, which interrupts the flow of building the message.
def createRequest(userId: Long, bypassKey: Option[String]): HttpRequest = {
val req = GET("/users/$userId")
.withHeader("accept: text/plain")
.withHeader("accept-encoding: gzip, deflate")
bypassKey.map(key => req.withHeader("bypass-key" -> key)
.getOrElse(req)
}
And, if there were multiple optional headers, the code would have been even less attractive.