Skip to content

Commit 775c77a

Browse files
committed
📝 updated readme
1 parent 85ed092 commit 775c77a

File tree

1 file changed

+31
-4
lines changed

1 file changed

+31
-4
lines changed

README.md

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,7 @@ Clean, simple, developer friendly interface for making network requests with PHP
1919
```php
2020
use function Leaf\fetch;
2121

22-
$res = fetch([
23-
"method" => "GET",
24-
"url" => 'https://jsonplaceholder.typicode.com/todos/1',
25-
]);
22+
$res = fetch("https://jsonplaceholder.typicode.com/todos/");
2623

2724
echo json_encode($res->data);
2825
```
@@ -33,13 +30,43 @@ You can also use the fetch class
3330
use Leaf\Fetch;
3431

3532
$res = Fetch::request([
33+
"url" => 'https://jsonplaceholder.typicode.com/todos/1',
34+
]);
35+
36+
echo json_encode($res->data);
37+
```
38+
39+
## The `fetch` method
40+
41+
Leaf fetch provides the fetch method as an easy way to make HTTP requests. This allows you to quickly make requests without bringing up the whole fetch class and without even having to build up your own request array.
42+
43+
```php
44+
// make a get request
45+
$res = fetch("https://jsonplaceholder.typicode.com/todos/");
46+
47+
// make a post request
48+
$res = fetch("https://jsonplaceholder.typicode.com/posts", [
49+
"title" => "foo",
50+
"body" => "bar",
51+
"userId" => 1,
52+
]);
53+
54+
// build a custom request array
55+
$res = fetch([
3656
"method" => "GET",
3757
"url" => 'https://jsonplaceholder.typicode.com/todos/1',
58+
"data" => [
59+
"firstName" => 'Fred',
60+
"lastName" => 'Flintstone'
61+
]
3862
]);
3963

64+
// get response body
4065
echo json_encode($res->data);
4166
```
4267

68+
## The `Fetch` class
69+
4370
## View Leaf's docs [here](https://leafphp.netlify.app/#/)
4471

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

0 commit comments

Comments
 (0)