-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapidae.py
39 lines (32 loc) · 1.24 KB
/
apidae.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
#!/usr/local/bin python
from flask import Flask
from flask import jsonify
from flask import request
from database.dao import beedao
from flask.ext.cors import CORS, cross_origin
app = Flask( __name__ )
cors = CORS(app, resources={r"/foo": {"origins": "*"}})
app.config['CORS_HEADERS'] = 'Content-Type'
# Welcome to BeeBox
@app.route("/", methods=["GET"])
@cross_origin(origin='*',headers=['Content-Type','Authorization'])
def welcome():
return "Welcome to BeeBox!"
# Creates new bee occurrence
@app.route("/savebee", methods=["POST"])
@cross_origin(origin='*',headers=['Content-Type','Authorization'])
def savebee():
beedao.save(request.form["beedata"])
return jsonify( {"status": 200, "text": "bee saved"} )
# Lists all bee occurrences
@app.route("/listbee", methods=["GET"])
@cross_origin(origin='*',headers=['Content-Type','Authorization'])
def listbees():
return jsonify( beedao.listBeeOccurrences() )
@app.route("/listrelatives/<occurrence_id>", methods=["GET"])
@cross_origin(origin='*',headers=['Content-Type','Authorization'])
def listrelatives(occurrence_id):
return jsonify( beedao.listRelativesByOccurrenceId(occurrence_id) )
if __name__ == '__main__':
app.run()
# app.run(app.config['LISTEN_HOST'], app.config['LISTEN_PORT'])