Last active
December 24, 2015 13:09
-
-
Save arschles/6802348 to your computer and use it in GitHub Desktop.
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
//Newman has a DSL for building up HttpRequests. | |
//the DSL uses the familiar builder pattern from Java. | |
//it copies the state of the request on each call, instead of modifying any internal state. | |
val url = new URL("http://siliconvalley-codecamp.com") | |
//the familiar GET function returns an instance of a Builder | |
//you can convert any Builder to a Newman HttpRequest | |
val builder1 = GET(url) | |
//we can add headers to any Builder. | |
//addHeaders copies the existing Builder to a new one with the headers | |
val builder2 = builder1.addHeaders("X-SVCC-Hello", "World") | |
//we can't add a body to a GET, so this won't compile. | |
//remember type safety? | |
val builder3 = builder1.addBody("Hello SVCC!") | |
//but we can add a body to a POST request, so this will compile | |
val builder4 = POST(url).addBody("Hello SVCC!") | |
//we can call toRequest on any Builder object to copy all its information into an HttpRequest | |
val req = builder4.toRequest | |
... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
a few notes on performance: