Simple Bottle Web App with Random Number Endpoint

  • Share this:

Code introduction


This code defines a simple Bottle web application that includes an endpoint. When accessed, it returns a random number between 1 and 100.


Technology Stack : Bottle

Code Type : Web application

Code Difficulty : Intermediate


                
                    
from bottle import route, run, request, response

def generate_random_number():
    # This function generates a random number between 1 and 100.
    return str(random.randint(1, 100))

@route('/random-number', method='GET')
def get_random_number():
    # This endpoint returns a random number when accessed via a GET request.
    return generate_random_number()

# Run the Bottle web server on port 8080
run(host='localhost', port=8080)                
              
Tags: