@@ -7,21 +7,20 @@ import {HTTP} from "../src/HTTP.sol";
7
7
import {strings} from "solidity-stringutils/strings.sol " ;
8
8
9
9
contract HTTPTest is Test {
10
- using HTTP for HTTP.Builder;
11
- using HTTP for HTTP.Request;
10
+ using HTTP for * ;
12
11
using strings for * ;
13
12
14
- HTTP.Builder http;
13
+ HTTP.Client http;
15
14
16
15
function test_HTTP_GET () public {
17
- HTTP.Response memory res = http.build ().GET ("https://jsonplaceholder.typicode.com/todos/1 " ).request ();
16
+ HTTP.Response memory res = http.initialize ().GET ("https://jsonplaceholder.typicode.com/todos/1 " ).request ();
18
17
19
18
assertEq (res.status, 200 );
20
19
assertEq (res.data, '{ "userId": 1, "id": 1, "title": "delectus aut autem", "completed": false} ' );
21
20
}
22
21
23
22
function test_HTTP_GET_options () public {
24
- HTTP.Response memory res = http.build (). GET ( "https://httpbin.org/headers " ).withHeader (
23
+ HTTP.Response memory res = http.initialize ( "https://httpbin.org/headers " ). GET ( ).withHeader (
25
24
"accept " , "application/json "
26
25
).withHeader ("Authorization " , "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ== " ).request ();
27
26
@@ -33,7 +32,7 @@ contract HTTPTest is Test {
33
32
34
33
function test_HTTP_POST_form_data () public {
35
34
HTTP.Response memory res =
36
- http.
build ().
POST (
"https://httpbin.org/post " ).
withBody (
"[email protected] " ).
request ();
35
+ http.
initialize ().
POST (
"https://httpbin.org/post " ).
withBody (
"[email protected] " ).
request ();
37
36
38
37
assertEq (res.status, 200 );
39
38
@@ -42,35 +41,40 @@ contract HTTPTest is Test {
42
41
}
43
42
44
43
function test_HTTP_POST_json () public {
45
- HTTP.Response memory res = http.build ().POST ("https://httpbin.org/post " ).withBody ('{"foo": "bar"} ' ).request ();
44
+ HTTP.Response memory res =
45
+ http.initialize ("https://httpbin.org/post " ).POST ().withBody ('{"foo": "bar"} ' ).request ();
46
46
47
47
assertEq (res.status, 200 );
48
48
assertTrue (res.data.toSlice ().contains (("foo " ).toSlice ()));
49
49
assertTrue (res.data.toSlice ().contains (("bar " ).toSlice ()));
50
50
}
51
51
52
52
function test_HTTP_PUT () public {
53
- HTTP.Response memory res = http.build ().PUT ("https://httpbin.org/put " ).request ();
53
+ HTTP.Response memory res = http.initialize ().PUT ("https://httpbin.org/put " ).request ();
54
54
assertEq (res.status, 200 );
55
55
}
56
56
57
57
function test_HTTP_PUT_json () public {
58
- HTTP.Response memory res = http.build ().PUT ("https://httpbin.org/put " ).withBody ('{"foo": "bar"} ' ).withHeader (
59
- "Content-Type " , "application/json "
60
- ).request ();
58
+ HTTP.Response memory res = http.initialize ("https://httpbin.org/put " ).PUT ().withBody ('{"foo": "bar"} ' )
59
+ .withHeader ("Content-Type " , "application/json " ).request ();
61
60
62
61
assertEq (res.status, 200 );
63
62
assertTrue (res.data.toSlice ().contains (('"foo" ' ).toSlice ()));
64
63
assertTrue (res.data.toSlice ().contains (('"bar" ' ).toSlice ()));
65
64
}
66
65
67
66
function test_HTTP_DELETE () public {
68
- HTTP.Response memory res = http.build ().DELETE ("https://httpbin.org/delete " ).request ();
67
+ HTTP.Response memory res = http.initialize ().DELETE ("https://httpbin.org/delete " ).request ();
69
68
assertEq (res.status, 200 );
70
69
}
71
70
72
71
function test_HTTP_PATCH () public {
73
- HTTP.Response memory res = http.build ().PATCH ("https://httpbin.org/patch " ).request ();
72
+ HTTP.Response memory res = http.initialize ().PATCH ("https://httpbin.org/patch " ).request ();
74
73
assertEq (res.status, 200 );
75
74
}
75
+
76
+ function test_HTTP_instance () public {
77
+ HTTP.Request storage req = http.initialize ("https://jsonplaceholder.typicode.com/todos/1 " );
78
+ assertEq (req.url, "https://jsonplaceholder.typicode.com/todos/1 " );
79
+ }
76
80
}
0 commit comments