|
8 | 8 | $dotenv->load(); |
9 | 9 |
|
10 | 10 | $url = $_ENV['SB_URL']; |
| 11 | +$url2 = $url."/rest/v1"; |
11 | 12 | $key = $_ENV['SB_API_KEY']; |
12 | 13 |
|
13 | | -$url2 = $url."/rest/v1/users?select=*"; |
| 14 | + |
| 15 | +$url3 = $url."/rest/v1/users?select=*"; |
14 | 16 |
|
15 | 17 | $ch = curl_init(); |
16 | | -curl_setopt($ch, CURLOPT_URL, $url2); |
| 18 | +curl_setopt($ch, CURLOPT_URL, $url3); |
17 | 19 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
18 | 20 | $header = [ |
19 | 21 | 'Content-Type: application/json', |
|
28 | 30 | print('<pre>'); |
29 | 31 | print_r($data); |
30 | 32 | print('</pre>'); |
| 33 | + |
| 34 | +/* |
| 35 | +use Fetch\Interfaces\Response as ResponseInterface; |
| 36 | +
|
| 37 | +$data = null; |
| 38 | +
|
| 39 | +async(fn () => fetch() |
| 40 | + ->baseUri("$url2") |
| 41 | + ->withQueryParameters(['select' => 1]) |
| 42 | + ->withToken("Bearer $key") |
| 43 | + ->withHeaders([ |
| 44 | + 'apikey' => $key, |
| 45 | + 'Content-Type' => 'application/json' |
| 46 | + ]) |
| 47 | + ->get('/users')) |
| 48 | + ->then(fn (ResponseInterface $response) |
| 49 | + => $data = $response->json()) // Success handler |
| 50 | + ->catch(fn (Throwable $e) => $e->getMessage()); // Error handler |
| 51 | +
|
| 52 | +echo $data; |
| 53 | +*/ |
| 54 | + |
| 55 | +use Fetch\Interfaces\Response as ResponseInterface; |
| 56 | + |
| 57 | +$data = null; |
| 58 | + |
| 59 | +// Asynchronously send a POST request using async/await syntax |
| 60 | +async(fn () => fetch($url2, [ |
| 61 | + 'method' => 'GET', |
| 62 | + 'headers' => ['Content-Type' => 'application/json'], |
| 63 | + 'body' => json_encode(['key' => 'value']), |
| 64 | +])) |
| 65 | + ->then(fn (ResponseInterface $response) => $data = $response->json()) // Success handler |
| 66 | + ->catch(fn (\Throwable $e) => print "Error: " . $e->getMessage()); // Error handler |
0 commit comments