Backend routes serving 2 frontends


Let’s say I have a Vue app for the “normal” users and a different Vue app serving an admin panel. Both apps needs to access to pretty much the same resources, but in differeny ways using the same backend (API).

Here are some of the resources for my app: Users, Projects, Dates, Todos

Like I said, the Todos resource needs to be accessed by both Users and Admins but in different ways:

  • return my todos if I am a User (user frontend)
  • return all Todos of a User (admin frontend)
  • return all Todos of a Project (admin frontend)
  • return all Todos of a Date (admin frontend)

What are the best practices for the routes. Here are the options I thought of:

  • 1 route GET /todos
    Both frontends could access it. Then in the handler, I could have an if statement to check if I am a user or an admin. If I am a user, I return my todos, else if I am an admin, I could have a filter to return either a project’s todos or a user’s todos or todos under a date with either the project_id, user_id or date_id.

  • Multiple routes like:
    GET /todos (for users, return my todos)
    GET /projects/:project_id/todos (for admins, return todos of project with id of :project_id)
    GET /dates/:date_id/todos (for admins, return todos under a date with id of :date_id)
    GET /users/:user_id/todos (for admins, return todos of user with id of :user_id)

If I go with the second option (multiple routes), then I see that the first route in only accessed by the users and the last 3 are only accessed by the admins. Should I then group my admin routes like this:

  • Admin Route Group
    GET /admin/projects/:project_id/todos
    GET /admin/dates/:date_id/todos
    GET /admin/users/:user_id/todos

Using the single GET /todos routes, would mean that my all my handlers methods needs to check if current user is User or Admin and return the appropriate data. If I go with the Second option, I could add an admin middleware for the last 3 routes and prevent the if admin statement in all handlers.

Then should I have a single todos_handler.go or should I also have todos_admin_handler.go to seperate my code? I feel that this would clear things up, but I would have repititive code.

I know all options would work, but I am just trying to see what is recommended and what are the suggestions.


This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.