Created
November 7, 2023 20:57
-
-
Save isvargasmsft/6fe2748a7287138e5031c9bfa30ef4d0 to your computer and use it in GitHub Desktop.
Calling the JSON Placeholder API
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
import asyncio | |
from kiota_abstractions.authentication.anonymous_authentication_provider import ( | |
AnonymousAuthenticationProvider) | |
from kiota_http.httpx_request_adapter import HttpxRequestAdapter | |
from client.posts_client import PostsClient | |
from client.models.post import Post | |
async def main(): | |
# You may need this if your're using asyncio on windows | |
# See: https://stackoverflow.com/questions/63860576 | |
# asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy()) | |
# API requires no authentication, so use the anonymous | |
# authentication provider | |
auth_provider = AnonymousAuthenticationProvider() | |
# Create request adapter using the HTTPX-based implementation | |
request_adapter = HttpxRequestAdapter(auth_provider) | |
# Create the API client | |
client = PostsClient(request_adapter) | |
# GET /posts | |
all_posts = await client.posts.get() | |
print(f"Retrieved {len(all_posts)} posts.") | |
# Run main | |
asyncio.run(main()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment