-
-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow dynamic choice of HTTP method (#94)
Fixes #67 Fixes #52 This was always possible in a roundabout way via ```scala requests.Requester("get", requests.Session()).apply("https://www.google.com") ``` But this PR adds a convenient alias and documents it for discoverability ```scala requests.send("get")("https://www.google.com") ```
- Loading branch information
Showing
4 changed files
with
50 additions
and
20 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package requests | ||
|
||
import utest._ | ||
import ujson._ | ||
|
||
object Scala2RequestTests extends TestSuite{ | ||
val tests = Tests{ | ||
|
||
test("params"){ | ||
|
||
test("post"){ | ||
for(chunkedUpload <- Seq(true, false)) { | ||
val res1 = requests.post( | ||
"https://httpbin.org/post", | ||
data = Map("hello" -> "world", "foo" -> "baz"), | ||
chunkedUpload = chunkedUpload | ||
).text() | ||
assert(read(res1).obj("form") == Obj("foo" -> "baz", "hello" -> "world")) | ||
} | ||
} | ||
test("put") { | ||
for (chunkedUpload <- Seq(true, false)) { | ||
val res1 = requests.put( | ||
"https://httpbin.org/put", | ||
data = Map("hello" -> "world", "foo" -> "baz"), | ||
chunkedUpload = chunkedUpload | ||
).text() | ||
assert(read(res1).obj("form") == Obj("foo" -> "baz", "hello" -> "world")) | ||
} | ||
} | ||
test("send"){ | ||
requests.send("get")("https://httpbin.org/get?hello=world&foo=baz") | ||
|
||
val res1 = requests.send("put")( | ||
"https://httpbin.org/put", | ||
data = Map("hello" -> "world", "foo" -> "baz"), | ||
chunkedUpload = true | ||
).text | ||
|
||
assert(read(res1).obj("form") == Obj("foo" -> "baz", "hello" -> "world")) | ||
} | ||
} | ||
} | ||
} |
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