-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathapi.py
41 lines (35 loc) · 1.16 KB
/
api.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
from flask import Flask, request, jsonify
from nameko.standalone.rpc import ClusterRpcProxy
CONFIG = {'AMQP_URI': "amqp://guest:guest@localhost:5672"}
app = Flask(__name__)
@app.route('/playlists', methods=['GET'])
def playlists():
"""
Micro Service Based Weather and Spotify API
This API is made with Flask and Nameko
---
parameters:
- name: zipcode
in: path
required: true
schema:
type: integer
description: location ZipCode
responses:
200:
description: Location data
"""
with ClusterRpcProxy(CONFIG) as rpc:
# Get the Spotify Authrization Token from header
# and OWM AppId from the header
openwm_appid = request.headers.get('X-OPENWM-APPID')
spotify_token = request.headers.get('X-SPOTIFY-TOKEN')
# Consuming Nameko service
# Here we pass the OpenWeatherMap AppId
# and the Spotify JWT
result = rpc.playlists.get_playlists(
openwm_appid, spotify_token, request.args)
return jsonify(result), 200
if __name__ == "__main__":
"""Start Flask app to serve mircoservices"""
app.run(host='0.0.0.0')