File tree 4 files changed +50
-20
lines changed
4 files changed +50
-20
lines changed Original file line number Diff line number Diff line change @@ -81,6 +81,10 @@ val r = requests.delete("http://httpbin.org/delete")
81
81
val r = requests.head(" http://httpbin.org/head" )
82
82
83
83
val r = requests.options(" http://httpbin.org/get" )
84
+
85
+ // dynamically choose what HTTP method to use
86
+ val r = requests.send(" put" )(" http://httpbin.org/put" , data = Map (" key" -> " value" ))
87
+
84
88
```
85
89
86
90
### Passing in Parameters
Original file line number Diff line number Diff line change @@ -34,6 +34,8 @@ trait BaseSession{
34
34
lazy val options = Requester (" OPTIONS" , this )
35
35
// unofficial
36
36
lazy val patch = Requester (" PATCH" , this )
37
+
38
+ def send (method : String ) = Requester (method, this )
37
39
}
38
40
39
41
object BaseSession {
Original file line number Diff line number Diff line change
1
+ package requests
2
+
3
+ import utest ._
4
+ import ujson ._
5
+
6
+ object Scala2RequestTests extends TestSuite {
7
+ val tests = Tests {
8
+
9
+ test(" params" ){
10
+
11
+ test(" post" ){
12
+ for (chunkedUpload <- Seq (true , false )) {
13
+ val res1 = requests.post(
14
+ " https://httpbin.org/post" ,
15
+ data = Map (" hello" -> " world" , " foo" -> " baz" ),
16
+ chunkedUpload = chunkedUpload
17
+ ).text()
18
+ assert(read(res1).obj(" form" ) == Obj (" foo" -> " baz" , " hello" -> " world" ))
19
+ }
20
+ }
21
+ test(" put" ) {
22
+ for (chunkedUpload <- Seq (true , false )) {
23
+ val res1 = requests.put(
24
+ " https://httpbin.org/put" ,
25
+ data = Map (" hello" -> " world" , " foo" -> " baz" ),
26
+ chunkedUpload = chunkedUpload
27
+ ).text()
28
+ assert(read(res1).obj(" form" ) == Obj (" foo" -> " baz" , " hello" -> " world" ))
29
+ }
30
+ }
31
+ test(" send" ){
32
+ requests.send(" get" )(" https://httpbin.org/get?hello=world&foo=baz" )
33
+
34
+ val res1 = requests.send(" put" )(
35
+ " https://httpbin.org/put" ,
36
+ data = Map (" hello" -> " world" , " foo" -> " baz" ),
37
+ chunkedUpload = true
38
+ ).text
39
+
40
+ assert(read(res1).obj(" form" ) == Obj (" foo" -> " baz" , " hello" -> " world" ))
41
+ }
42
+ }
43
+ }
44
+ }
Original file line number Diff line number Diff line change @@ -57,26 +57,6 @@ object RequestTests extends TestSuite{
57
57
)
58
58
assert(read(res4).obj(" args" ) == Obj (" ++-- lol" -> " !@#$%" , " hello" -> " world" ))
59
59
}
60
- test(" post" ){
61
- for (chunkedUpload <- Seq (true , false )) {
62
- val res1 = requests.post(
63
- " https://httpbin.org/post" ,
64
- data = new RequestBlob .FormEncodedRequestBlob (Map (" hello" -> " world" , " foo" -> " baz" )),
65
- chunkedUpload = chunkedUpload
66
- ).text()
67
- assert(read(res1).obj(" form" ) == Obj (" foo" -> " baz" , " hello" -> " world" ))
68
- }
69
- }
70
- test(" put" ) {
71
- for (chunkedUpload <- Seq (true , false )) {
72
- val res1 = requests.put(
73
- " https://httpbin.org/put" ,
74
- data = new RequestBlob .FormEncodedRequestBlob (Map (" hello" -> " world" , " foo" -> " baz" )),
75
- chunkedUpload = chunkedUpload
76
- ).text()
77
- assert(read(res1).obj(" form" ) == Obj (" foo" -> " baz" , " hello" -> " world" ))
78
- }
79
- }
80
60
}
81
61
test(" multipart" ){
82
62
for (chunkedUpload <- Seq (true , false )) {
You can’t perform that action at this time.
0 commit comments