# Creating a new REST user account

I am studying JavaEE and I have made my project for the learning experience.

I want to understand how best to write code from the point of view of architecture and use of relevant technologies. I am particularly interested to hear about the implementation of the REST-layer.

The purpose of this is the backend to the Android application. Uses postgres, wildfly(EJB) and REST.

This is one from many methods in REST layer.

@POST
@Path("/reg")
@Produces(MediaType.APPLICATION_JSON)
public Response create(@QueryParam("email") String email, @QueryParam("pass") String pass) {
log.info("create user");
log.debug("create user: email=" + email + " pass=" + pass);
Response response;
try {
response = Response.ok().entity(userM.reg(email, pass)).build();
log.info("reg ok");
} catch (Exception e) {
AppException err = new AppException(e);
response = Response.serverError().status(err.getCode()).entity(err).build();
log.info("reg fail");
}

return response;
}

• Note, I have reopened your question, but I consider it to be a bit light on detail. There is enough to review, but reviews will not be able to go in to a great amount of detail. – rolfl Apr 10 '15 at 14:22

Your naming looks to be a little bit inconsistent

@Path("/reg")

userM.reg(email, pass)


First, reg seems to be short hand for something (registerUser?). Unless there's some really compelling reason to leave it abbreviated, you should change the spelling so that the next person to read the code can figure out what you mean.

The inconsistency is that you seem to be using reg as a verb in the (again, poorly named) userM object, and also using it as a noun (@Path tells us that this is part of the URI, which would normally identify a resource).

Now, you will find those that argue, reasonably, that the characters in the URL don't make the link restful or not restful. Nonetheless, there's some expectation that, if you are asking the server to insert an item into a collection, then the URL is a representation of the collection, rather than the act of inserting into it.

Assuming that your choice of POST is correct, meaning that clients should not expect the change being offered to be idempotent, then I would expect an endpoint like /users, or /registeredUsers (if there is more than one user collection).