Created
November 7, 2023 21:13
-
-
Save isvargasmsft/f732a15462d615c56c9dad6a55119f53 to your computer and use it in GitHub Desktop.
Calling the demo API with PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use KiotaPosts\Client\PostsApiClient; | |
use KiotaPosts\Client\Models\Post; | |
use Microsoft\Kiota\Abstractions\ApiException; | |
use Microsoft\Kiota\Abstractions\Authentication\AnonymousAuthenticationProvider; | |
use Microsoft\Kiota\Http\GuzzleRequestAdapter; | |
require __DIR__.'/vendor/autoload.php'; | |
try { | |
$authProvider = new AnonymousAuthenticationProvider(); | |
$requestAdapter = new GuzzleRequestAdapter($authProvider); | |
$client = new PostsApiClient($requestAdapter); | |
// GET /posts | |
$allPosts = $client->posts()->get()->wait(); | |
$postCount = sizeof($allPosts); | |
echo "Retrieved {$postCount} posts.\n"; | |
}catch (ApiException $ex) { | |
echo $ex->getMessage(); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment