A global company has many offices all over the world . A same set of country code is used to describe the employee 's nationality and the location of their working offices. The employees can be in only one of the following status (active , terminated , inactive) . These status are not stored in a DB 's field but derived from some business logic .
On Wed, 24 Oct 2012, ken1 wrote:- employee collection is filtered by status and nationality/working
office :
- /employees/active/nationality/france
- /employees/terminated/office/italy
You've entered a state here where there is the appearance of hierarchy
where there isn't one. In such an ambiguous state, where you have
multi-dimensionality this is probably a much better way to go:- /employees?status=active&nationality=france
- /employees?status=terminated&office=italy
You get the expessiveness you want without confusion.
If you reorder the path segments you will have a hierarchy:- /employees/nationality/france/activeKen your question is mostly one of personal preference. I prefer the path segment approach when appropriate because it's cleaner and easier to understand by looking at the URL and results in shorter URLs, but it does imply context whereas query parameters are explicit.- /employees/office/italy/terminated
Another concern with path segments is future proofing your structure where you need to ask yourself if there might not be ambiguity when future needs arise. For example, right now you have active, inactive and terminated for your status. If in the future you need to query employees by the status of their health care plan the use of these terms might become ambiguous and require you to further complicate your URL structure.
Another issue is mutual exclusivity. What if you need to query for all French nationals working in offices in Italy?
So considering all these things sadly I'd say query parameters are your best bet even though I don't like using them unless I have to.
Or Peter's suggest of matrix URLs is also another approach albeit few people use them so they are not as familiar to some as query parameters.
Hope this helps.
-Mike
- /?a=b23bd&b=l6sb7&c=b42mo08&d=pc493s
--
You received this message because you are subscribed to the Google Groups "API Craft" group.
To unsubscribe from this group, send email to api-craft+...@googlegroups.com.
Visit this group at http://groups.google.com/group/api-craft?hl=en.
How to determine when to use path segment or query parameter ?
In a microservices world, the app that looks after employee details (name, email, etc. - maybe extracted from corporate identity server) might be quite unaware of this thing you call "status". That app could serve up /employees but would be unable to serve up /employees/active/.
To stretch this point further, while status is arguably a pretty major and central attribute, what about country-specific things like local pension plans. In a multinational, you would not want or even be able to bake this kind of country-specific stuff into your core systems. That argues even more strongly for using path segments rather than url params.
The downside of course is losing the ability to do multi-criteria searching, which url parameters supports. Horses and courses.