How would you structure these rest api endpoints


Let’s say you have 4 types of data that are displayed similarly across 4 pages of a website like videos, articles, posts, etc.

Would you have individual routes to get the most recent 10 for each like /type1/getall, /type2/getall, etc…,

Or would you have one route like getAllByType that takes the type as a param and returns the respective data.

Thanks for your input

>Solution :

2nd method of defining a common route getAllByType with a param is the most used and recommended format because that way your routes structure is clean and it also avoids Redundant code. Hope it helps.

Leave a ReplyCancel reply