Very basic API example done.
This commit is contained in:
parent
398bd8160f
commit
b6631ccaef
20
app.py
20
app.py
|
@ -3,4 +3,22 @@ from flask_restful import Resource, Api, reqparse
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
import ast
|
import ast
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
api = Api(app)
|
api = Api(app)
|
||||||
|
|
||||||
|
class Users(Resource):
|
||||||
|
def get(self):
|
||||||
|
data = pd.read_csv('users.csv') # read CSV
|
||||||
|
data = data.to_dict() # convert dataframe to dictionary
|
||||||
|
return {'data': data}, 200 # return data and 200 OK code
|
||||||
|
|
||||||
|
class Locations(Resource):
|
||||||
|
def get(self):
|
||||||
|
data = pd.read_csv('locations.csv') # read CSV
|
||||||
|
data = data.to_dict() # convert dataframe to dictionary
|
||||||
|
return {'data': data}, 200 # return data and 200 OK code
|
||||||
|
|
||||||
|
api.add_resource(Users, '/users') # '/users' is our entry point for Users
|
||||||
|
api.add_resource(Locations, '/locations') # and '/locations' is our entry point for Locations
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
app.run(debug=True) # run our Flask app
|
Loading…
Reference in New Issue
Block a user