PHP Örnekleri
PHP (Guzzle HTTP) ile API istekleri yapmak için örnekler.
Kurulum
composer require guzzlehttp/guzzle
Temel Kullanım
GET İsteği
use GuzzleHttp\Client;
$client = new Client([
'base_uri' => 'https://api.example.com/api/v1',
'headers' => [
'Authorization' => 'Bearer YOUR_TOKEN',
'Content-Type' => 'application/json'
]
]);
$response = $client->get('/users');
$data = json_decode($response->getBody(), true);
POST İsteği
$response = $client->post('/users', [
'json' => [
'name' => 'John Doe',
'email' => 'john@example.com'
]
]);
$data = json_decode($response->getBody(), true);