I have a notification list at the top of my website.
- Each notification can be either "read" or "unread."
- Each notification is a clickable anchor element, taking the user to the post related to this notification.
Currently I use GET request to handle the user's click:
@webapp.route('/read')
@webapp.route('/read/<int:notification_id>')
@login_required
def read_notification(notification_id=None):
if notification_id is None:
return notifications.read(user=current_user)
fetched_notifications = notifications.get(current_user)
if notification is None:
return fail(404, 'Invalid notification ID.')
if notification.user.id != current_user.id:
return fail(403, "You aren't allowed to access this page.")
notifications.read(id_=notification_id)
return redirect(notification.action_url or '/exercises')
I have a bad feeling about using a GET request to /read
in order to change the state of the notification. On the other hand, I don't want to use POST (or PATCH), 'cause it will require me to use <form>
(semantically wrong) or JavaScript (may create a laggy user experience).
Is there any better option?
The stack is vanilla JavaScript and Flask (Python 3.8).