2

Lets say I have an Organization and Users inside that organization. To get a user in particular organization what should be the GET request url from below options?

1. /api/organization/:orgId/users/:userId
2. /api/users/:userId?organizationId=orgId

Any other suggestions are welcome.

asked Apr 4, 2016 at 20:56
1
  • I vote for the first. Much more readable. Commented Apr 4, 2016 at 21:55

1 Answer 1

7

Best to map onto what semantics you are trying to convey.

/api/organization/:orgId/users/:userId

This reads to me as there being a bunch of organizations, and for each organization, you have a bunch of users, and you want to get information for that user.

/api/users/:userId?organizationId=orgId

This reads to me as there being a bunch of users, and each user may belong to a bunch of organizations, and you are asking for the user's information in the context of that organization.

If it helps, here's the sort of situation where I'd use a query parameter:

/api/users/23642346?language=swahili

Since "language" just controls how the data is presented, not what it is, it makes sense to make it a parameter, not part of the data model.

Now I can't say for sure how to handle your data, as I don't know for sure what "Organization" actually is, but if it is a situation similar to what I described for the first option, that's the way I'd go.

answered Apr 4, 2016 at 22:44
0

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.