Skip to content

Instantly share code, notes, and snippets.

@SuryaSankar
Created February 20, 2020 12:46
Show Gist options
  • Save SuryaSankar/8c8ea67978f91953673b0d19be24e073 to your computer and use it in GitHub Desktop.
Save SuryaSankar/8c8ea67978f91953673b0d19be24e073 to your computer and use it in GitHub Desktop.
Simple api for push subscriptions
@app.route("/api/push-subscriptions", methods=["POST"])
def create_push_subscription():
json_data = request.get_json()
subscription = PushSubscription.query.filter_by(
subscription_json=json_data['subscription_json']
).first()
if subscription is None:
subscription = PushSubscription(
subscription_json=json_data['subscription_json']
)
db.session.add(subscription)
db.session.commit()
return jsonify({
"status": "success"
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment