You can download this code by clicking the button below.
This code is now available for download.
This code defines a simple web service using the Bottle framework, providing two APIs: one for addition and another for multiplication. Users can access specific URLs and pass two integers to get the result.
Technology Stack : Bottle
Code Type : Web API
Code Difficulty : Intermediate
from bottle import route, run, request, response
def random_bottle_function():
@route('/add/<int:num1>/<int:num2>')
def add_numbers(num1, num2):
result = num1 + num2
response.content_type = 'text/plain'
return str(result)
@route('/multiply/<int:num1>/<int:num2>')
def multiply_numbers(num1, num2):
result = num1 * num2
response.content_type = 'text/plain'
return str(result)
def main():
run(host='localhost', port=8080)
random_bottle_function()