32 lines
663 B
Python
32 lines
663 B
Python
from flask import Flask, jsonify, request
|
|
from flask_cors import CORS
|
|
import os
|
|
from dotenv import load_dotenv
|
|
from db import get_connection
|
|
|
|
load_dotenv()
|
|
|
|
PORT = os.getenv("PORT")
|
|
|
|
app = Flask(__name__)
|
|
CORS(app)
|
|
|
|
@app.route("/health")
|
|
def health():
|
|
return jsonify({"message" : "API Flask version 1.0!!!"})
|
|
|
|
@app.route("/produtos",methods=["GET"])
|
|
def listar_produtos():
|
|
conexao = get_connection()
|
|
cursor = conexao.cursor(dictionary=True)
|
|
|
|
cursor.execute("select * from produto")
|
|
produtos = cursor.fetchall()
|
|
|
|
cursor.close()
|
|
conexao.close()
|
|
|
|
return jsonify(produtos)
|
|
|
|
if __name__ == "__main__":
|
|
app.run(port=PORT, debug=True) |