Skip to content

Commit 4a5f9ed

Browse files
committed
📝 updated readme
1 parent afb847f commit 4a5f9ed

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,38 @@ echo json_encode($res->data);
6767

6868
## The `Fetch` class
6969

70+
The fetch class contains all the options and methods needed to make a network request.
71+
72+
### baseUrl
73+
74+
You might have noticed that all the requests above needed us to type a long URL to make the requests, however, we can add a base url so we don't have to type it over and over again.
75+
76+
```php
77+
Fetch::baseUrl("https://jsonplaceholder.typicode.com");
78+
```
79+
80+
And from there you can make requests like this:
81+
82+
```php
83+
// make a get request
84+
$res = fetch("/todos");
85+
86+
// make a post request
87+
$res = fetch("/posts", [
88+
"title" => "foo",
89+
"body" => "bar",
90+
"userId" => 1,
91+
]);
92+
93+
// use the get shortcut method
94+
$res = Fetch::get("/todos/10");
95+
96+
// echo response
97+
echo json_encode($res);
98+
```
99+
100+
### shortcut methods
101+
70102
## View Leaf's docs [here](https://leafphp.netlify.app/#/)
71103

72104
Built with ❤ by [**Mychi Darko**](https://mychi.netlify.app)

0 commit comments

Comments
 (0)