Let's say there is a SINGLE mobile application which receives various types of notifications (like WhatsApp notifications, Facebook Messenger notifications ,etc). What would be a better REST API structure for this?
/users/[email protected]/notifications //Gives all the notifications
There is a confusion between the below two formats on how .
/users/[email protected]/notifications?category=whatsapp,facebook //Gives all the notifications
vs
/users/[email protected]/notifications/whatsapp //Gives only whatsapp notification
/users/[email protected]/notifications/facebook //Gives only facebook notification
To access an individual notification resource
/users/[email protected]/notifications/facebook/{notification-id}
vs
/users/[email protected]/notifications/{notification-id}
If a resource has a unique ID then it should be directly accessible from that, so in my opinion
/notifications/{id}
Would make most sense. In terms of filtering, this is probably more about preference than anything. Here's what I think would be the most idiomatic approach
/notifications // fetch all notifications
/notifications/facebook // fetch all Facebook messages
/notifications/whatsapp // fetch all WhatsApp messages
/users/{id}/notifications // fetch user notifications
/users/{id}/notifications/facebook // fetch user Facebook notifications
/users/{id}/notifications/whatsapp // fetch user WhatsApp messages