File tree 1 file changed +35
-0
lines changed
1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change @@ -26,6 +26,41 @@ $client->post("https://example.com", ["json" => ["key" => "value"]]);
26
26
$client->put("https://example.com");
27
27
$client->delete("https://example.com");
28
28
```
29
+ ### Using Request class
30
+ HttpClient provides ability to create "request classes".
31
+ ``` php
32
+ <?php
33
+
34
+ use Ivan770\HttpClient\Request;
35
+ use Ivan770\HttpClient\HttpClient;
36
+
37
+ class HttpBinGet extends Request
38
+ {
39
+ // Request URL
40
+ protected $resource = "https://httpbin.org/get";
41
+
42
+ // Request method
43
+ protected $method = "GET";
44
+
45
+ // This method is called on request execution.
46
+ // Here, you are able to use builder to modify your request
47
+ protected function defaultAttach(HttpClient $client)
48
+ {
49
+ $client->authBearer("test");
50
+ }
51
+ }
52
+
53
+ // Execute request
54
+ app(HttpBinGet::class)->execute();
55
+
56
+ // Execute request and receive result
57
+ app(HttpBinGet::class)->get();
58
+
59
+ // Modify request using "attach" method.
60
+ app(HttpBinGet::class)->attach(function (HttpClient $client) {
61
+ $client->headers(["test" => true]);
62
+ })->execute();
63
+ ```
29
64
### Request builder
30
65
You can send your request parameters directly to client methods, but you can also use fluent request builder.
31
66
``` php
You can’t perform that action at this time.
0 commit comments