-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi.py
47 lines (30 loc) · 1.04 KB
/
api.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
38
39
40
41
42
43
44
45
46
47
from flask import Flask
from flask import request
from models import db
app = Flask(__name__)
app.config['DEBUG'] = True
app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql://{PROJECT_DB_USER}:{PROJECT_DB_PASSWORD}@localhost/{PROJECT_NAME}'
db.init_app(app)
@app.route('/')
def get_home():
return 'OI ESTOU AQUI'
if __name__ == '__main__':
app.run(host = '0.0.0.0', port = 80, debug = True)
@app.route('/users')
class User(Resource):
def post(self, *args, **kwargs):
""" Creating a new User """
data = request.get_json(force=True)
schema = UserSchema()
if data:
logger.info("Data got by /api/test/testId method %s" % data)
# Validation with schema.load() OPTION_2
user, errors = schema.load(data)
print(user)
print(errors)
if errors:
return {"errors": errors}, 422
user.save_to_db()
return {"message": USER_CREATED_SUCCESSFULLY}, 201
def get(self):
return {"subscriberList":users}