What are the proven strategies for achieving decoupling between API methods and user interfaces?
I'm working on creating a REST API service for the application. And I noticed that my API methods are strongly coupled with the user interface.
Let's assume that I have this simple entity in my app
public class User{ private String username; private List<String> roles; private Set<String> permissions;}
Now let's have a look at the user interface.
There are two pages in the user interface, one allows an admin to create a user by specifying his username and roles. Another page allows an admin to issue permissions.
This means that I have to create two API methods, one to create a user and assign roles. And another one for issuing permissions.
public class UserService{ public User createUser(User user){ // save user to db // assign roles; } public User assignPermissions(Integer userId, List<String> permissions){ // find user from db // assign permissions }}
Why should I strictly follow the UI? In my opinion, it is more logical to create three API methods, one for creating a user, another for assigning roles and the last for issuing permits.
So, how can I achieve this decoupling?