Reputation: 31
I am writing a rest api. I am having troubles in choosing between queryParam vs path variable. My api has to get user list and it takes parameters (team name, requester, pagination params). User list is only returned if requester has access to see team members
I am using below mentioned right now. I am sure that paginationParams should use queryParam as it is doing pagination and that teamName should use path variable as I am asking for specific resource. But I am not sure about requester. Should I use path or query for requester?
/Teams/{teamName}/Users?requestor={requester};paginationParams={paginationParams}
other possibility is
/Teams/{teamName}/Users/{requester};paginationParams={paginationParams}
Upvotes: 1
Views: 220
Reputation: 78
You should pass it as query param because /Teams/{teamName}/Users/{requester}
is not a resource. The resource is what you are requesting, that is /Teams/{teamName}/Users
.
Upvotes: 0
Reputation: 2468
If the requestor
parameter helps to identify the users collection for given teamName
it should be included in the path. Otherwise, if it's used to sort or filter items, then it is better to send it as query parameter.
From what you described sounds like requestor
is just an additional filter to users
resource and does not identify it at all hence a query parameter. The other way to look at it is asking yourself
Does the collection of users differ based on the
requestor
or is it always the same and it's just filtered out based on access rights?
Upvotes: 1
Reputation: 353
if requestor is identifier of users then use it as param, if not then as query
Upvotes: 0