Skip to content

Instantly share code, notes, and snippets.

@always-hii
Last active May 9, 2020 07:38
Show Gist options
  • Save always-hii/9f59e3fec89dcd054915041c3e1e9d29 to your computer and use it in GitHub Desktop.
Save always-hii/9f59e3fec89dcd054915041c3e1e9d29 to your computer and use it in GitHub Desktop.
[Recipe of Code] GET /makers
import pandas as pd
import pymysql
from flask import Flask, request
from flask_restful import Api, Resource
host = 'your_mysql_ip'
user = 'your_username'
password = 'your_password'
database = 'rest'
class Makers(Resource):
""" /makers """
def get(self):
query = f'SELECT * FROM rest.Makers'
conn = pymysql.connect(host=host, user=user, password=password, database=database)
dataframe = pd.read_sql(sql=query, con=conn)
conn.close()
makers = dataframe.to_dict('record')
ret = { 'data': makers }
return ret, 200
if __name__ == '__main__':
app = Flask(__name__)
api = Api(app)
api.add_resource(Makers, '/makers')
app.run(host='0.0.0.0', port=5555)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment