REST API, path variable vs request param
I am currently writing a webservice providing access to some resources. I try to follow REST but I am facing a problem concerning some parts of my API.
I have the follwing uris:
/myservice/users/ : to get all users
/myservice/users/{userId} : to get a specific user
/myservice/badges/ : to get all badges
/myservice/badges/{badgeId} : to get a specific badge
Now, my problem is, i have to implement a way to get all users that have a particular badge.
I can consider that this is just a filter I apply on the list of users, hence the following uri:
- /myservice/users/?filter=badge:{badgeId}
Or I can consider that this is just a sub-resources of a badge, hence the following uri:
- /myservice/badges/{badgeId}/users/
Which one seems the must 'REST-compliant' ?
I must say I have read some posts on this subject specifically this one: Rest Standard: Path parameters or Request parameters but they don't seem to cover my problem.
rest
add a comment |
I am currently writing a webservice providing access to some resources. I try to follow REST but I am facing a problem concerning some parts of my API.
I have the follwing uris:
/myservice/users/ : to get all users
/myservice/users/{userId} : to get a specific user
/myservice/badges/ : to get all badges
/myservice/badges/{badgeId} : to get a specific badge
Now, my problem is, i have to implement a way to get all users that have a particular badge.
I can consider that this is just a filter I apply on the list of users, hence the following uri:
- /myservice/users/?filter=badge:{badgeId}
Or I can consider that this is just a sub-resources of a badge, hence the following uri:
- /myservice/badges/{badgeId}/users/
Which one seems the must 'REST-compliant' ?
I must say I have read some posts on this subject specifically this one: Rest Standard: Path parameters or Request parameters but they don't seem to cover my problem.
rest
2
REST has no opinion on what your URI looks like. Either one is just as "REST compliant"
– Darrel Miller
Mar 27 '12 at 16:53
FYI, I took a shot at the question you mentioned, you might be interested in the answer.
– tne
Jun 29 '15 at 14:46
add a comment |
I am currently writing a webservice providing access to some resources. I try to follow REST but I am facing a problem concerning some parts of my API.
I have the follwing uris:
/myservice/users/ : to get all users
/myservice/users/{userId} : to get a specific user
/myservice/badges/ : to get all badges
/myservice/badges/{badgeId} : to get a specific badge
Now, my problem is, i have to implement a way to get all users that have a particular badge.
I can consider that this is just a filter I apply on the list of users, hence the following uri:
- /myservice/users/?filter=badge:{badgeId}
Or I can consider that this is just a sub-resources of a badge, hence the following uri:
- /myservice/badges/{badgeId}/users/
Which one seems the must 'REST-compliant' ?
I must say I have read some posts on this subject specifically this one: Rest Standard: Path parameters or Request parameters but they don't seem to cover my problem.
rest
I am currently writing a webservice providing access to some resources. I try to follow REST but I am facing a problem concerning some parts of my API.
I have the follwing uris:
/myservice/users/ : to get all users
/myservice/users/{userId} : to get a specific user
/myservice/badges/ : to get all badges
/myservice/badges/{badgeId} : to get a specific badge
Now, my problem is, i have to implement a way to get all users that have a particular badge.
I can consider that this is just a filter I apply on the list of users, hence the following uri:
- /myservice/users/?filter=badge:{badgeId}
Or I can consider that this is just a sub-resources of a badge, hence the following uri:
- /myservice/badges/{badgeId}/users/
Which one seems the must 'REST-compliant' ?
I must say I have read some posts on this subject specifically this one: Rest Standard: Path parameters or Request parameters but they don't seem to cover my problem.
rest
rest
edited May 23 '17 at 10:30
Community♦
11
11
asked Mar 27 '12 at 16:25
Guillaume D
46113
46113
2
REST has no opinion on what your URI looks like. Either one is just as "REST compliant"
– Darrel Miller
Mar 27 '12 at 16:53
FYI, I took a shot at the question you mentioned, you might be interested in the answer.
– tne
Jun 29 '15 at 14:46
add a comment |
2
REST has no opinion on what your URI looks like. Either one is just as "REST compliant"
– Darrel Miller
Mar 27 '12 at 16:53
FYI, I took a shot at the question you mentioned, you might be interested in the answer.
– tne
Jun 29 '15 at 14:46
2
2
REST has no opinion on what your URI looks like. Either one is just as "REST compliant"
– Darrel Miller
Mar 27 '12 at 16:53
REST has no opinion on what your URI looks like. Either one is just as "REST compliant"
– Darrel Miller
Mar 27 '12 at 16:53
FYI, I took a shot at the question you mentioned, you might be interested in the answer.
– tne
Jun 29 '15 at 14:46
FYI, I took a shot at the question you mentioned, you might be interested in the answer.
– tne
Jun 29 '15 at 14:46
add a comment |
4 Answers
4
active
oldest
votes
If you're looking to be RESTful, consider using HATEOAS (horrible acronym, but key to being truly RESTful).
Using HATEOAS, your Badge representation could look something like this:
<badge>
<id>1234</id>
<name>Admin</name>
<link rel = "/rel/users"
href = "/myservice/users?badge=1234" />
<link rel = "self"
href = "/myservice/badges/1234" />
</badge>
This allows your clients to be decoupled from your server's URI scheme as they simply GET on whatever href the /rel/users link provides. Granted your server still needs to define a URI scheme internally, but if at some point down the road you decide you don't care for it, you can easily change it without breaking your clients. For instance, you may want to change your URI scheme to your second option, which would cause your Badge representation to change to this:
<badge>
<id>1234</id>
<name>Admin</name>
<link rel = "/rel/users"
href = "/myservice/badges/1234/users" />
<link rel = "self"
href = "/myservice/badges/1234" />
</badge>
Clients using the /rel/users link relation aren't affected by the URI change. What this boils down to is ... use HATEOS, and the URI scheme doesn't really matter all that much.
Cheers!
add a comment |
I prefer /myservice/users/?filter=badge:{badgeId}
and I think more APIs use this format.
add a comment |
I strongly recommend using query string.
Path variable binding is not good.
Path variable breaks the Apache access log analysis data.
No analysis tool supports path variable.
If your company uses APM - expensive - tool, path variable sees the same functionality as an independent API.
REST? OK. But binding must to use query string.
add a comment |
Use query string like:
/myservice/users/?badge=badgeId&genter=male&year__gt=18
This is more restful.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f9893662%2frest-api-path-variable-vs-request-param%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
If you're looking to be RESTful, consider using HATEOAS (horrible acronym, but key to being truly RESTful).
Using HATEOAS, your Badge representation could look something like this:
<badge>
<id>1234</id>
<name>Admin</name>
<link rel = "/rel/users"
href = "/myservice/users?badge=1234" />
<link rel = "self"
href = "/myservice/badges/1234" />
</badge>
This allows your clients to be decoupled from your server's URI scheme as they simply GET on whatever href the /rel/users link provides. Granted your server still needs to define a URI scheme internally, but if at some point down the road you decide you don't care for it, you can easily change it without breaking your clients. For instance, you may want to change your URI scheme to your second option, which would cause your Badge representation to change to this:
<badge>
<id>1234</id>
<name>Admin</name>
<link rel = "/rel/users"
href = "/myservice/badges/1234/users" />
<link rel = "self"
href = "/myservice/badges/1234" />
</badge>
Clients using the /rel/users link relation aren't affected by the URI change. What this boils down to is ... use HATEOS, and the URI scheme doesn't really matter all that much.
Cheers!
add a comment |
If you're looking to be RESTful, consider using HATEOAS (horrible acronym, but key to being truly RESTful).
Using HATEOAS, your Badge representation could look something like this:
<badge>
<id>1234</id>
<name>Admin</name>
<link rel = "/rel/users"
href = "/myservice/users?badge=1234" />
<link rel = "self"
href = "/myservice/badges/1234" />
</badge>
This allows your clients to be decoupled from your server's URI scheme as they simply GET on whatever href the /rel/users link provides. Granted your server still needs to define a URI scheme internally, but if at some point down the road you decide you don't care for it, you can easily change it without breaking your clients. For instance, you may want to change your URI scheme to your second option, which would cause your Badge representation to change to this:
<badge>
<id>1234</id>
<name>Admin</name>
<link rel = "/rel/users"
href = "/myservice/badges/1234/users" />
<link rel = "self"
href = "/myservice/badges/1234" />
</badge>
Clients using the /rel/users link relation aren't affected by the URI change. What this boils down to is ... use HATEOS, and the URI scheme doesn't really matter all that much.
Cheers!
add a comment |
If you're looking to be RESTful, consider using HATEOAS (horrible acronym, but key to being truly RESTful).
Using HATEOAS, your Badge representation could look something like this:
<badge>
<id>1234</id>
<name>Admin</name>
<link rel = "/rel/users"
href = "/myservice/users?badge=1234" />
<link rel = "self"
href = "/myservice/badges/1234" />
</badge>
This allows your clients to be decoupled from your server's URI scheme as they simply GET on whatever href the /rel/users link provides. Granted your server still needs to define a URI scheme internally, but if at some point down the road you decide you don't care for it, you can easily change it without breaking your clients. For instance, you may want to change your URI scheme to your second option, which would cause your Badge representation to change to this:
<badge>
<id>1234</id>
<name>Admin</name>
<link rel = "/rel/users"
href = "/myservice/badges/1234/users" />
<link rel = "self"
href = "/myservice/badges/1234" />
</badge>
Clients using the /rel/users link relation aren't affected by the URI change. What this boils down to is ... use HATEOS, and the URI scheme doesn't really matter all that much.
Cheers!
If you're looking to be RESTful, consider using HATEOAS (horrible acronym, but key to being truly RESTful).
Using HATEOAS, your Badge representation could look something like this:
<badge>
<id>1234</id>
<name>Admin</name>
<link rel = "/rel/users"
href = "/myservice/users?badge=1234" />
<link rel = "self"
href = "/myservice/badges/1234" />
</badge>
This allows your clients to be decoupled from your server's URI scheme as they simply GET on whatever href the /rel/users link provides. Granted your server still needs to define a URI scheme internally, but if at some point down the road you decide you don't care for it, you can easily change it without breaking your clients. For instance, you may want to change your URI scheme to your second option, which would cause your Badge representation to change to this:
<badge>
<id>1234</id>
<name>Admin</name>
<link rel = "/rel/users"
href = "/myservice/badges/1234/users" />
<link rel = "self"
href = "/myservice/badges/1234" />
</badge>
Clients using the /rel/users link relation aren't affected by the URI change. What this boils down to is ... use HATEOS, and the URI scheme doesn't really matter all that much.
Cheers!
edited Mar 29 '12 at 0:00
answered Mar 28 '12 at 23:53
Andaris
595513
595513
add a comment |
add a comment |
I prefer /myservice/users/?filter=badge:{badgeId}
and I think more APIs use this format.
add a comment |
I prefer /myservice/users/?filter=badge:{badgeId}
and I think more APIs use this format.
add a comment |
I prefer /myservice/users/?filter=badge:{badgeId}
and I think more APIs use this format.
I prefer /myservice/users/?filter=badge:{badgeId}
and I think more APIs use this format.
answered Mar 27 '12 at 16:33
abraham
33.1k768113
33.1k768113
add a comment |
add a comment |
I strongly recommend using query string.
Path variable binding is not good.
Path variable breaks the Apache access log analysis data.
No analysis tool supports path variable.
If your company uses APM - expensive - tool, path variable sees the same functionality as an independent API.
REST? OK. But binding must to use query string.
add a comment |
I strongly recommend using query string.
Path variable binding is not good.
Path variable breaks the Apache access log analysis data.
No analysis tool supports path variable.
If your company uses APM - expensive - tool, path variable sees the same functionality as an independent API.
REST? OK. But binding must to use query string.
add a comment |
I strongly recommend using query string.
Path variable binding is not good.
Path variable breaks the Apache access log analysis data.
No analysis tool supports path variable.
If your company uses APM - expensive - tool, path variable sees the same functionality as an independent API.
REST? OK. But binding must to use query string.
I strongly recommend using query string.
Path variable binding is not good.
Path variable breaks the Apache access log analysis data.
No analysis tool supports path variable.
If your company uses APM - expensive - tool, path variable sees the same functionality as an independent API.
REST? OK. But binding must to use query string.
edited Nov 23 '18 at 8:03
Filnor
1,13321624
1,13321624
answered Nov 21 '18 at 10:28
HeeGu
11
11
add a comment |
add a comment |
Use query string like:
/myservice/users/?badge=badgeId&genter=male&year__gt=18
This is more restful.
add a comment |
Use query string like:
/myservice/users/?badge=badgeId&genter=male&year__gt=18
This is more restful.
add a comment |
Use query string like:
/myservice/users/?badge=badgeId&genter=male&year__gt=18
This is more restful.
Use query string like:
/myservice/users/?badge=badgeId&genter=male&year__gt=18
This is more restful.
answered Nov 23 '18 at 8:38
ramwin
6041614
6041614
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f9893662%2frest-api-path-variable-vs-request-param%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
REST has no opinion on what your URI looks like. Either one is just as "REST compliant"
– Darrel Miller
Mar 27 '12 at 16:53
FYI, I took a shot at the question you mentioned, you might be interested in the answer.
– tne
Jun 29 '15 at 14:46