A sane DSL to test REST API's.
There are two variations of the client that can be used:
- Blocking
- Non-Blocking
package import:
// blocking implementation
import com.wix.e2e.http.client.sync._
// or non blocking implementation
import com.wix.e2e.http.client.async._
Other Options
//Import Object
// blocking implementation
import com.wix.e2e.http.client.BlockingHttpClientSupport
// or non blocking implementation
import com.wix.e2e.http.client.NonBlockingHttpClientSupport
// Or add mixin trait to call site
// blocking implementation
class MyClass extends com.wix.e2e.http.client.BlockingHttpClientSupport
// or non blocking implementation
class MyClass extends com.wix.e2e.http.client.NonBlockingHttpClientSupport
val somePort = 99123 /// any port
implicit val baseUri = BaseUri(port = somePort)
get("/somePath")
post("/anotherPath")
// suported method: get, post, put, patch, delete, options, head, trace
Each request can be easily customized with a set of basic transformers allowing all basic functionality (add parameters, headers, cookies and request body)
get("/somePath",
but = withParam("param1" -> "value")
and header("header" -> "value")
and withCookie("cookie" -> "cookieValue"))
// post plain text data to api
post("/somePath",
but = withPayload("Hi There !!!"))
// or post entity that would be marshalled using testkit marshaller (or custom user marshaller)
case class SomeCaseClass(str: String)
// request will automatically be marshalled to json
put("/somePath", but = withPayload(SomeCaseClass("Hi There !!!")))
Handlers can be also be defined by developer, it can use existing transformers or to implement transformers from scratch
def withSiteId(id: String): RequestTransformer = withParam("site-id" -> id) and withHeader("x-user-custom" -> "whatever")
get("/path", but = withSiteId("someId"))
To validate HTTP response use the included Specs2 Matcher Suite.
Testkit comes out of the box with a default Jackson json marshaller preloaded with several commonly used modules, to define your own marshaller see Custom Marshaller.