You can download this code by clicking the button below.
This code is now available for download.
This function creates a simple web service that can receive two numbers and return their sum or difference via HTTP GET requests.
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(num1, num2):
result = num1 + num2
response.content_type = 'application/json'
return {"sum": result}
@route('/subtract/<int:num1>/<int:num2>')
def subtract(num1, num2):
result = num1 - num2
response.content_type = 'application/json'
return {"difference": result}
run(host='localhost', port=8080)
random_bottle_function()