1. Go to this page and download the library: Download beriyack/apiclient library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
use Beriyack\ApiClient;
try {
$newPost = [
'title' => 'Mon Nouveau Titre',
'body' => 'Contenu de mon nouveau post.',
'userId' => 1
];
$response = ApiClient::post('https://jsonplaceholder.typicode.com/posts', $newPost);
print_r($response);
} catch (Exception $e) {
echo "Erreur : " . $e->getMessage();
}
use Beriyack\ApiClient;
try {
$updatedPost = [
'id' => 1,
'title' => 'Titre Mis à Jour',
'body' => 'Nouveau contenu pour le post.',
'userId' => 1
];
$response = ApiClient::put('https://jsonplaceholder.typicode.com/posts/1', $updatedPost);
print_r($response);
} catch (Exception $e) {
echo "Erreur : " . $e->getMessage();
}
use Beriyack\ApiClient;
try {
$response = ApiClient::delete('https://jsonplaceholder.typicode.com/posts/1');
print_r($response); // Souvent vide ou un objet vide pour une suppression réussie
} catch (Exception $e) {
echo "Erreur : " . $e->getMessage();
}
use Beriyack\ApiClient;
try {
$options = [
CURLOPT_TIMEOUT => 10, // Timeout de 10 secondes
CURLOPT_SSL_VERIFYPEER => false // ATTENTION: À utiliser avec précaution et jamais en production sans bonne raison !
];
$data = ApiClient::get('https://some-api.com/data', $options);
print_r($data);
} catch (Exception $e) {
echo "Erreur : " . $e->getMessage();
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.