Skip to content

Commit 1850d36

Browse files
Supabase client for php: v3.0.0
1 parent 7c84cb0 commit 1850d36

1 file changed

Lines changed: 38 additions & 2 deletions

File tree

index.php

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@
88
$dotenv->load();
99

1010
$url = $_ENV['SB_URL'];
11+
$url2 = $url."/rest/v1";
1112
$key = $_ENV['SB_API_KEY'];
1213

13-
$url2 = $url."/rest/v1/users?select=*";
14+
15+
$url3 = $url."/rest/v1/users?select=*";
1416

1517
$ch = curl_init();
16-
curl_setopt($ch, CURLOPT_URL, $url2);
18+
curl_setopt($ch, CURLOPT_URL, $url3);
1719
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
1820
$header = [
1921
'Content-Type: application/json',
@@ -28,3 +30,37 @@
2830
print('<pre>');
2931
print_r($data);
3032
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

Comments
 (0)