Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
from flask import Flask, request
from flask_restful import Api, Resource
import pandas as pd
app = Flask(name)
api = Api(app)
class Users(Resource):
def get(self):
data = pd.read_csv('users.csv')
data = data.to_dict('records')
return {'data' : data}, 200
class Cities(Resource):
def get(self):
data = pd.read_csv('users.csv',usecols=[2])
data = data.to_dict('records')
return {'data' : data}, 200
class Name(Resource):
def get(self,name):
data = pd.read_csv('users.csv')
data = data.to_dict('records')
for entry in data:
if entry['name'] == name :
return {'data' : entry}, 200
return {'message' : 'No entry found with this name !'}, 404
Add URL endpoints
api.add_resource(Users, '/users')
api.add_resource(Cities, '/cities')
api.add_resource(Name, '/string:name')
if name == 'main':
# app.run(host="0.0.0.0", port=5000)
app.run()