pip install -r requirements.txt
The following can be added to a .env
file in the foot of this directory as well
APP_ENVIRONMENT="PROD"
SECRET_KEY="myverysecretkey"
DATABASE_URL="sqlite:///app.db"
The api allows for various functions. To work with it locally and easily, you can use httpie
in Pypi or just use curl:
pip install httpie
The following includes various methods:
# Get token
http --auth <username>:<password> POST http://localhost:5000/api/tokens
# Revoke token
http DELETE http://localhost:5000/api/tokens "Authorization:Bearer <token>"
# Create user
http POST http://localhost:5000/api/users "Authorization:Bearer <token>" username=alice password=dog email=alice@example.com
# Update current user
http PUT http://localhost:5000/api/users/1 "Authorization:Bearer <token>" email=new_email@example.com
# Various routes
http GET http://localhost:5000/api/users "Authorization:Bearer <token>"
http GET http://localhost:5000/api/users/1 "Authorization:Bearer <token>"
export FLASK_APP=stockpyle.py
app/models.py
flask db migrate -m "<class/table> table"
flask db upgrade
flask db upgrade
u = User(username='john', email='john@example.com')
u.set_password('password')
db.session.add(u)
u = User(username='susan', email='susan@example.com')
u.set_password('password')
db.session.add(u)
db.session.commit()
# get user
u = User.query.get(1)
u
#<User john>
# get all users in reverse alphabetical order
User.query.order_by(User.username.desc()).all()
#[<User susan>, <User john>]
users = User.query.all()
for u in users:
db.session.delete(u)
db.session.commit()