Skip to content

Instantly share code, notes, and snippets.

@isvargasmsft
Created November 7, 2023 20:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save isvargasmsft/6fe2748a7287138e5031c9bfa30ef4d0 to your computer and use it in GitHub Desktop.
Save isvargasmsft/6fe2748a7287138e5031c9bfa30ef4d0 to your computer and use it in GitHub Desktop.
Calling the JSON Placeholder API
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