-
Notifications
You must be signed in to change notification settings - Fork 13
/
meu_python.py
37 lines (26 loc) · 754 Bytes
/
meu_python.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
from flask import Flask, request
app = Flask(__name__)
lista_alunos = []
@app.route("/")
def hello_world():
return "<p>Web service em execução</p>"
@app.route("/cadastra_aluno", methods=["POST"])
def cadastra_aluno_func():
dic_aluno = request.json
nome = dic_aluno.get("nome", "") # dic_aluno["nome"]
if nome == "":
resp = {"erro": "Nome não informado"}
return resp, 400
lista_alunos.append(dic_aluno)
# resp de sucesso
resp = {
"mensagem": "Aluno cadastrado",
"aluno": dic_aluno
}
return resp, 201
@app.route("/lista_alunos", methods=["GET"])
def lista_alunos_func():
resp = {"alunos": lista_alunos}
return resp
if __name__ == "__main__":
app.run(debug=True)