You can download this code by clicking the button below.
This code is now available for download.
This function uses the httpx library to asynchronously fetch random user information from the JSONPlaceholder API.
Technology Stack : httpx
Code Type : Asynchronous HTTP request
Code Difficulty : Intermediate
import httpx
import random
def fetch_random_user_info():
url = "https://jsonplaceholder.typicode.com/users"
async with httpx.AsyncClient() as client:
response = await client.get(url)
user = response.json()[random.randint(0, 9)]
return user
# JSON output