-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi_gateway.py
101 lines (92 loc) · 2.63 KB
/
api_gateway.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
from flask import Flask, request
from flasgger import Swagger
from nameko.standalone.rpc import ClusterRpcProxy
app = Flask(__name__)
Swagger(app)
CONFIG = {'AMQP_URI': "amqp://guest:guest@localhost"}
@app.route('/email', methods=['POST'])
def email():
"""
Micro Service Based Mail API
This API is made with Flask, Flasgger and Nameko
---
parameters:
- name: body
in: body
required: true
schema:
id: data
properties:
email:
type: string
subject:
type: string
msg:
type: string
responses:
200:
description: Email message has been submitted
"""
email = request.json.get('email')
subject = request.json.get('subject')
msg = request.json.get('msg')
with ClusterRpcProxy(CONFIG) as rpc:
rpc.mail.send(email, subject, msg)
return msg, 200
@app.route('/compute', methods=['POST'])
def compute():
"""
Micro Service Based Compute API, which also uses Mail and Customer Micro services via RPC communication
This API is made with Flask, Flasgger and Nameko
---
parameters:
- name: body
in: body
required: true
schema:
id: data
properties:
changeto:
type: string
enum:
- dolar
- euro
value:
type: integer
customerid:
type: integer
responses:
200:
description: Please wait the calculation, you'll receive an email with results
"""
changeto = request.json.get('changeto')
value = request.json.get('value')
customerid = request.json.get('customerid')
msg = "Please wait the calculation, you'll receive an email with results"
with ClusterRpcProxy(CONFIG) as rpc:
result = rpc.compute.compute.call_async(changeto, value,customerid)
return msg, 200
@app.route('/customer/<customerid>', methods = ['GET'])
def find(customerid):
"""
Micro Service Based Customer API
This API is made with Flask, Flasgger and Nameko
---
parameters:
- name: customerid
description: Please enter your customer id
in: customerid
required: true
responses:
200:
description: We Found the Customer
404:
description: Customer Not Found
"""
with ClusterRpcProxy(CONFIG) as rpc:
res,b = rpc.customer.find(customerid)
if (res == 1):
return "We Found the Customer",200
else:
return "Customer Not Found",404
app.run(host="0.0.0.0",port=5000)