coderly / teamplaybook-ember

0 stars 0 forks source link

Suggestion on how to organize users #13

Open begedin opened 9 years ago

begedin commented 9 years ago

Endpoints

At the moment, on the API side we have the following endpoints:

Registration and fetching of the CurrentUser are handled by the CurrentUser adapter. In normal cases, the buildURL method of the adapter handles the endpoint for the entity, and there's usually one primary endpoint, accepting different methods. In our case, we have two methods, one to GET (/me) and one to POST (/users).

It complicates things a bit, so **I would like to eliminate the GET '/me' endpoint and make it GET 'users'.

Reorganize our entities

Having a CurrentUser and User both of which are actually the User entity on the API also makes things a bit confusing. Because of that, I suggest organizing it differently.

idelahoz commented 9 years ago

@begedin I think fetching a single users from "/users" wouldnt make much sense, thats not how REST is defined, but I think something like "/users/me" or "users/current" makes more sense considering "me" or "current" as an ID.

begedin commented 9 years ago

@idelahoz Yeah, that sounds like a good idea.

venkatd commented 9 years ago

@begedin I think this is a case of incidental duplication. The current user diverges enough from another user on the system enough that we should be careful of treating them too much the same. That was the reasoning for making /me a separate call. Maybe /me isn't the right name for it though.

venkatd commented 9 years ago

How about this... look up how some well designed APIs on the internet do it and how other people think about the current user and REST. Maybe we'll get some ideas from there.

begedin commented 9 years ago

Did some research, here are my findings:

Maybe we do not need a /me endpoint at all. The login response is already sending exactly what we need, so why not just use that? On the ember side, we simply take the response and push it to the store as current-user. We could override the session hook that usually does it.

I think we should be re-authenticating any time we change the current-user anyway, so there should not be a reason to fetch it explicitly. We sould just store what a successful login sends us.

Worst case, maybe move the endpoint for GET '/me' to GET 'users/tokens/me'. I don't really like that idea, though.

The thing that irks me most about the current state is that I have to do special case handling for the current-user adapter and serializer.

Ideally, we'd have a situation where no customization is required (so either we switch all to users, or the api has a CurrentUser model as well. That's why my suggestion was to have a User and a UserProfile and to move some of the endpoints around. A split between User and UserProfile seems less confusing to me than User and CurrentUser. User would be the private data that rarely changes for any user. We wouldn't really fetch it from the client for any user other than our own. UserProfile would be the public data. We could change our own easily and we could see everyone elses depending on the scenario.

Less ideally, we'd have a situation where we access the same endpoint for get and post, (by having is similar to how https://github.com/paulmillr/ostio-api/ listed above has it - a get '/users/me'. That way, at least the adapter custiomization would be lessened.

At the core of it, I'd like to match up our entities. If the API sends a User record, then the client should be expecting a User record, or vice versa, if the client is expecting a User record, the API should send it. Currently, the client expects a CurrentUser record, but the API sends a User.

Additionally, I'd like to match up the endpoints, so a single entity on the client is accessing the same basic endpoint on the server for all actions on that entity (find, save, update, etc.).