-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
58 lines (45 loc) · 1.4 KB
/
app.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
import json
from flask import Flask, request, jsonify
from models.model import autocomplete, search
app = Flask(__name__)
@app.route('/api/branches/autocomplete')
def autocomplete_api():
"""Autocomplete API to fetch possible matches on branch name.
Args:
q: The branch to be retrieved.
limit: The limit of results.
offset: The offset of results.
Returns: JSON serialized response.
Raises:
Message: Internal Server Error
"""
q = request.args.get("q")
limit = request.args.get("limit")
offset = request.args.get("offset")
response = autocomplete(q,limit,offset)
return jsonify(response)
@app.route('/api/branches')
def search_api():
"""Search API to search a word/term across the databse.
Args:
q: The term or word to be searched.
limit: The limit of query results.
offset: The offset of query results.
Returns: JSON serialized response.
Raises:
Message: Internal Server Error
"""
q = request.args.get("q")
limit = request.args.get("limit")
offset = request.args.get("offset")
response = search(q,limit,offset)
return jsonify(response)
@app.route('/')
def index():
return "<h1>Indian Banks API !!</h1>"
@app.errorhandler(404)
def not_found(e):
response = {"Message":"Malformed Url"}
return jsonify(response)
if __name__ == '__main__':
app.run(debug=True)