You can download this code by clicking the button below.
This code is now available for download.
This function accepts an HTTP request, generates a random number between 1 and 100, and returns this number in JSON format.
Technology Stack : Sanic, random
Code Type : Web API
Code Difficulty : Intermediate
def random_number_response(request):
from sanic import response
import random
# Generate a random number between 1 and 100
random_number = random.randint(1, 100)
# Return the random number as a JSON response
return response.json({"random_number": random_number})