You can download this code by clicking the button below.
This code is now available for download.
This function accepts an HTTP request and returns a JSON response containing randomly generated user information.
Technology Stack : Starlette
Code Type : HTTP response
Code Difficulty : Intermediate
from starlette.responses import JSONResponse
from starlette.requests import Request
import random
def random_user_info(request: Request):
# Generate a random user information in JSON format
user_info = {
"id": random.randint(1, 1000),
"name": f"User_{random.randint(1, 1000)}",
"email": f"user{random.randint(1, 1000)}@example.com"
}
return JSONResponse(content=user_info)