Last active
March 8, 2023 21:28
-
-
Save danjesus/b63741dec6885e080d3643eb793cf99e to your computer and use it in GitHub Desktop.
Api simples helloworld com flask
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import Flask, jsonify, request | |
app = Flask(__name__) | |
@app.route("/") | |
def index(): | |
return jsonify({"message": "Olá TI360 Experience!"}) | |
@app.route("/cadastro", methods=["POST"]) | |
def salvar_dados(): | |
dados = request.get_json() | |
print(dados['celular']) | |
print(dados['email']) | |
return dados | |
@app.route("/exemplo", methods=["GET"]) | |
def exemplo_de_uma_rota(): | |
return jsonify({"mensagem": "Olá TI360 GET!"}) | |
if __name__ == "__main__": | |
# aqui incializamos o servidor | |
app.run(debug=True, host="localhost", port=8080) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
No seu terminal instale as bibliotecas necessárias | |
``` | |
pip install flask | |
``` | |
Para executar a aplicação ir no terminal e rodar | |
``` | |
python app.py | |
``` | |
Ai é só usar o navegador para ver acessando: | |
http://localhost:8080/exemplo | |
http://localhost:8080 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment