Thu Oct 15 2015
Full Stack Developer and Tech Lead @ Associate.io
UI (web)
API
/add
/subtract
/multiply
/divide
UI (web)
APIs
/add
/subtract
/multiply
/divide
(flask)
(django)
http
@app.route("/add")
def add():
try:
first_number = int(request.args.get('a'))
second_number = int(request.args.get('b'))
return jsonify({'result': first_number + second_number})
except Exception as e:
return jsonify({'result': "There was an error" + str(e)})
@app.route("/subtract")
def subtract():
try:
first_number = int(request.args.get('a'))
second_number = int(request.args.get('b'))
return jsonify({'result': first_number - second_number})
except Exception as e:
return jsonify({'result': "There was an error" + str(e)})
class Multiply(APIView):
renderer_classes = (JSONPRenderer,)
@staticmethod
def get(request):
try:
first_number = int(request.GET.get('a'))
second_number = int(request.GET.get('b'))
return Response({'result': first_number * second_number})
except Exception as e:
return Response({'result': 'there was an error ' + str(e)})
class Divide(APIView):
renderer_classes = (JSONPRenderer,)
@staticmethod
def get(request):
try:
first_number = int(request.GET.get('a'))
second_number = int(request.GET.get('b'))
return Response({'result': first_number / second_number})
except Exception as e:
return Response({'result': 'there was an error ' + str(e)})
function callAddService(firstAddNumberValue, secondAddNumberValue){
var url = "https://flask-calculator-microservice.herokuapp.com/add?a=
"+firstAddNumberValue+"&b="+secondAddNumberValue;
basicAjaxCall(url,callAddServiceSuccess);
}
function callMultiplyService(firstAddNumberValue, secondAddNumberValue){
var url = "https://django-calculator-microservice.herokuapp.com/multiply?a=
"+firstAddNumberValue+"&b="+secondAddNumberValue;
basicAjaxCall(url,callMultiplyServiceSuccess);
}
function basicAjaxCall(url, successCallback){
$.ajax({
url: url,
dataType: "jsonp",
success : successCallback
});
}
____________________________
/add
/subtract
/multiply
/divide
(flask)
(django)
/derivative
/integrate
(tornado)
(pyramid)
/series
/sequences
Ruby
Ruby on Rails
Sinatra
Javascript
NodeJs + ExpressJs
PHP
Laravel
Codeigniter
Java
Spring framework
Cake php
____________________________
/add
/subtract
/multiply
/divide
(flask)
/derivative
/integrate
(NodeJs + express JS)
(laravel)
/series
/sequences
(sinatra)