File tree Expand file tree Collapse file tree 4 files changed +50
-20
lines changed Expand file tree Collapse file tree 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")
8181val r = requests.head(" http://httpbin.org/head" )
8282
8383val 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+
8488```
8589
8690### Passing in Parameters
Original file line number Diff line number Diff line change @@ -34,6 +34,8 @@ trait BaseSession{
3434 lazy val options = Requester (" OPTIONS" , this )
3535 // unofficial
3636 lazy val patch = Requester (" PATCH" , this )
37+
38+ def send (method : String ) = Requester (method, this )
3739}
3840
3941object 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{
5757 )
5858 assert(read(res4).obj(" args" ) == Obj (" ++-- lol" -> " !@#$%" , " hello" -> " world" ))
5959 }
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- }
8060 }
8161 test(" multipart" ){
8262 for (chunkedUpload <- Seq (true , false )) {
You can’t perform that action at this time.
0 commit comments