You can download this code by clicking the button below.
This code is now available for download.
This function uses the httpx library to send an asynchronous GET request to https://randomuser.me/api/, then parses the returned JSON data, and finally returns a dictionary containing random user information.
Technology Stack : httpx, Asynchronous programming
Code Type : Asynchronous HTTP request
Code Difficulty : Intermediate
import httpx
import random
def fetch_random_user():
url = "https://randomuser.me/api/"
async with httpx.AsyncClient() as client:
response = await client.get(url)
data = response.json()
return data["results"][0]