timothypesi / Flask_Api

This Flask application and connects to a MySQL database hosted on aws and Creates an API end-point to fetching the Data from the datbase

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Flask_Api

The code above is a Python Flask application that connects to an RDS database in AWS and returns the data in a JSON format using a GET request.

The pymysql library is used to establish a connection to the RDS database. The conn variable defines the host name, user name, password, and database name to connect to.

The @app.route('/data', methods=['GET']) decorator specifies that the get_data() function should be called when a GET request is made to the /data URL of the Flask app.

The get_data() function creates a cursor object that executes a SQL query to fetch all the data from the specified table in the RDS database. The data is then returned in a JSON format using the jsonify() function.

The if name == 'main': block is used to start the Flask app. When the script is run directly, the app.run() method starts a development server on the default port 5000.

Note that you should replace the host, user, password, and db values with your own values to connect to your RDS database. Also, it's important to ensure that your RDS database is properly secured and that you are using the appropriate credentials to access the data.

About

This Flask application and connects to a MySQL database hosted on aws and Creates an API end-point to fetching the Data from the datbase


Languages

Language:Python 100.0%