com.stackmob.newman.dsl

ResponseHandlerDSL

trait ResponseHandlerDSL extends AnyRef

Facilitates the handling of various response codes per response, where each handler for a given code may fail or may succeed with a value of some type Success or fail with a value of some type Failure. Failure must have an implicit conversion from Throwable in scope, and defaults to Throwable. ResponseHandler is an immutable wrapper; handlers, a HTTPResponse => Validation[Failure,Success]. can be added by using handleCode, which returns a new instance. After all desired handlers have been added calling toIO or using the implicit provided in com.stackmob.newman.dsl will return an IO[Validation[Failure,Success].

For response codes without a "catchall" handler always scalaz.Failure with a com.stackmob.newman.dsl.UnhandledResponseCode as its value.

To begin using ResponseHandler call com.stackmob.newman.request.HttpRequest's prepare method and then begin changing calls to handleCode.

Example:

GET(genURL("cnames", cName))
.addHeaders(acceptHeader)
.prepare
.handleCode(HttpResponseCode.Ok, (resp: HttpResponse) => {
  val json = parse(resp.bodyString)
  (json \ "app-id", json \ "env") match {
    case (JInt(appID), JString(env)) => (appID.longValue(), env.toEnum[EnvironmentType]).some.success[Throwable]
     case _ => (UnexpectedLookupBody(resp.bodyString): Throwable).fail[Option[(Long,EnvironmentType)]]
   }
 })
.handleCode(HttpResponseCode.NotFound, (_: HttpResponse) => none.success)
.handleCode(HttpResponseCode.InternalServerError, (resp: HttpResponse) => {
  (new Exception("server error: %s" format resp.bodyString)).fail
})
.toIO // there's also an implicit called ResponseHandlerToResponse in the `com.stackmob.newman.dsl` package

If the response is expected to be considered a success when it its code is 200 OK and is expected to have a body whose content can is valid JSON expectJSONBody can be called given there is an implicit net.liftweb.json.scalaz.Types.JSONR in scope for T. See expectJSONBody for more info.

Example:

implicit def jsonrForBody: JSONR[(Long,EnvironmentType) = ...
GET(genURL("cnames", cName))
 .addHeaders(acceptHeader)
 .prepare
 .expectJSONBody[(Long,EnvironmentType)] // if called in any other position in the chain the type parameter should not need to be specified
 .handleCode(HttpResponseCode.NotFound, (_: HttpResponse) => ...)

If the response is expected to be considered a success when it its code is 204 No Content, expectNoContent(t: T) can be called to return a scalaz.Success when the IO is performed. See expectNoContent for more info.

Linear Supertypes
AnyRef, Any
Known Subclasses
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. ResponseHandlerDSL
  2. AnyRef
  3. Any
  1. Hide All
  2. Show all
Learn more about member selection
Visibility
  1. Public
  2. All

Type Members

  1. case class ResponseHandler[Failure, Success](handlers: List[((HttpResponseCode) ⇒ Boolean, (HttpResponse) ⇒ Validation[Failure, Success])], resp: HttpResponse)(implicit errorConv: (Throwable) ⇒ Failure) extends Product with Serializable

Value Members

  1. final def !=(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  2. final def !=(arg0: Any): Boolean

    Definition Classes
    Any
  3. final def ##(): Int

    Definition Classes
    AnyRef → Any
  4. final def ==(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  5. final def ==(arg0: Any): Boolean

    Definition Classes
    Any
  6. final def asInstanceOf[T0]: T0

    Definition Classes
    Any
  7. def clone(): AnyRef

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  8. final def eq(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  9. def equals(arg0: Any): Boolean

    Definition Classes
    AnyRef → Any
  10. def finalize(): Unit

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  11. final def getClass(): Class[_]

    Definition Classes
    AnyRef → Any
  12. def hashCode(): Int

    Definition Classes
    AnyRef → Any
  13. final def isInstanceOf[T0]: Boolean

    Definition Classes
    Any
  14. final def ne(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  15. final def notify(): Unit

    Definition Classes
    AnyRef
  16. final def notifyAll(): Unit

    Definition Classes
    AnyRef
  17. final def synchronized[T0](arg0: ⇒ T0): T0

    Definition Classes
    AnyRef
  18. def toString(): String

    Definition Classes
    AnyRef → Any
  19. final def wait(): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  20. final def wait(arg0: Long, arg1: Int): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  21. final def wait(arg0: Long): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )

Inherited from AnyRef

Inherited from Any

Ungrouped