Skip to content

v18.0.0

Compare
Choose a tag to compare
@losizm losizm released this 10 Aug 02:40
ce456f7

What's New?

Public Interface Changes

The following interface changes are applied in this release:

  • withDecoded is renamed to withDecode in scamper.BodyParser
  • withQueryBody is renamed to withFormBody in scamper.Implicits.HttpMessageType
  • isInformational, isSuccessful, isRedirection, isClientError, and isServerError are added to scamper.HttpResponse
  • scamper.client.ResponsePredicate is removed
  • withOptionalHeader and addOptionalHeader are added to scamper.MessageBuilder; consequently they are implemented by HttpRequest and HttpResponse

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.