Best way of structuring REST URIs
Suppose we have the following classes and want to define REST URIs:
class Profile{
IList<Upload> Uploads{get;}
}
class Upload{
int ProfileId;
int CategoryId;
}
class Category{
IList<Upload> Uploads{get;}
}
We can define two models of URIs:
- /profiles/{id}/uploads
- /categories/{id}/uploads
My first question is to add a new Upload which one is preferred? and second one is, what is best practices of designing URIs?
asp.net .net rest asp.net-core-webapi
add a comment |
Suppose we have the following classes and want to define REST URIs:
class Profile{
IList<Upload> Uploads{get;}
}
class Upload{
int ProfileId;
int CategoryId;
}
class Category{
IList<Upload> Uploads{get;}
}
We can define two models of URIs:
- /profiles/{id}/uploads
- /categories/{id}/uploads
My first question is to add a new Upload which one is preferred? and second one is, what is best practices of designing URIs?
asp.net .net rest asp.net-core-webapi
No one is preferred, you should define both, because they differ in their behavior.
– Yurii N.
Nov 19 '18 at 12:16
I fail to see how the shown classes and URLs are related in this question? You tend to see questions about URLs associated with Action methods. Can you clarify what it is you mean
– Nkosi
Nov 19 '18 at 12:18
Your question doesn't make sense. In the first URI, you're adding uploads associated with a particular profile, while in the second you're adding uploads associated with a particular category. There is no "preferred" URI. They're entirely separate.
– Chris Pratt
Nov 19 '18 at 13:47
I know they are separate Uri's, but both of them do the same work when post new Upload to both of Uri's.
– user3284331
Nov 19 '18 at 14:39
I've edited the question to clarify it more.
– user3284331
Nov 19 '18 at 14:45
add a comment |
Suppose we have the following classes and want to define REST URIs:
class Profile{
IList<Upload> Uploads{get;}
}
class Upload{
int ProfileId;
int CategoryId;
}
class Category{
IList<Upload> Uploads{get;}
}
We can define two models of URIs:
- /profiles/{id}/uploads
- /categories/{id}/uploads
My first question is to add a new Upload which one is preferred? and second one is, what is best practices of designing URIs?
asp.net .net rest asp.net-core-webapi
Suppose we have the following classes and want to define REST URIs:
class Profile{
IList<Upload> Uploads{get;}
}
class Upload{
int ProfileId;
int CategoryId;
}
class Category{
IList<Upload> Uploads{get;}
}
We can define two models of URIs:
- /profiles/{id}/uploads
- /categories/{id}/uploads
My first question is to add a new Upload which one is preferred? and second one is, what is best practices of designing URIs?
asp.net .net rest asp.net-core-webapi
asp.net .net rest asp.net-core-webapi
edited Nov 20 '18 at 14:04
Uwe Keim
27.4k31128210
27.4k31128210
asked Nov 19 '18 at 12:09
user3284331
7517
7517
No one is preferred, you should define both, because they differ in their behavior.
– Yurii N.
Nov 19 '18 at 12:16
I fail to see how the shown classes and URLs are related in this question? You tend to see questions about URLs associated with Action methods. Can you clarify what it is you mean
– Nkosi
Nov 19 '18 at 12:18
Your question doesn't make sense. In the first URI, you're adding uploads associated with a particular profile, while in the second you're adding uploads associated with a particular category. There is no "preferred" URI. They're entirely separate.
– Chris Pratt
Nov 19 '18 at 13:47
I know they are separate Uri's, but both of them do the same work when post new Upload to both of Uri's.
– user3284331
Nov 19 '18 at 14:39
I've edited the question to clarify it more.
– user3284331
Nov 19 '18 at 14:45
add a comment |
No one is preferred, you should define both, because they differ in their behavior.
– Yurii N.
Nov 19 '18 at 12:16
I fail to see how the shown classes and URLs are related in this question? You tend to see questions about URLs associated with Action methods. Can you clarify what it is you mean
– Nkosi
Nov 19 '18 at 12:18
Your question doesn't make sense. In the first URI, you're adding uploads associated with a particular profile, while in the second you're adding uploads associated with a particular category. There is no "preferred" URI. They're entirely separate.
– Chris Pratt
Nov 19 '18 at 13:47
I know they are separate Uri's, but both of them do the same work when post new Upload to both of Uri's.
– user3284331
Nov 19 '18 at 14:39
I've edited the question to clarify it more.
– user3284331
Nov 19 '18 at 14:45
No one is preferred, you should define both, because they differ in their behavior.
– Yurii N.
Nov 19 '18 at 12:16
No one is preferred, you should define both, because they differ in their behavior.
– Yurii N.
Nov 19 '18 at 12:16
I fail to see how the shown classes and URLs are related in this question? You tend to see questions about URLs associated with Action methods. Can you clarify what it is you mean
– Nkosi
Nov 19 '18 at 12:18
I fail to see how the shown classes and URLs are related in this question? You tend to see questions about URLs associated with Action methods. Can you clarify what it is you mean
– Nkosi
Nov 19 '18 at 12:18
Your question doesn't make sense. In the first URI, you're adding uploads associated with a particular profile, while in the second you're adding uploads associated with a particular category. There is no "preferred" URI. They're entirely separate.
– Chris Pratt
Nov 19 '18 at 13:47
Your question doesn't make sense. In the first URI, you're adding uploads associated with a particular profile, while in the second you're adding uploads associated with a particular category. There is no "preferred" URI. They're entirely separate.
– Chris Pratt
Nov 19 '18 at 13:47
I know they are separate Uri's, but both of them do the same work when post new Upload to both of Uri's.
– user3284331
Nov 19 '18 at 14:39
I know they are separate Uri's, but both of them do the same work when post new Upload to both of Uri's.
– user3284331
Nov 19 '18 at 14:39
I've edited the question to clarify it more.
– user3284331
Nov 19 '18 at 14:45
I've edited the question to clarify it more.
– user3284331
Nov 19 '18 at 14:45
add a comment |
1 Answer
1
active
oldest
votes
If you are doing the same thing in two of the endpoints then you have a design problem.
I would suggest that you first decide what main function the upload is for. Is it a profile upload or a category upload.
Make the upload for one. Then you can always assign a category for a profile according to your business needs.
You can give the categoryId as a query parameter to your profile upload endpoint like:
/profiles/{profileid}/uploads?categoryId={categoryid}
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%2f53374343%2fbest-way-of-structuring-rest-uris%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
If you are doing the same thing in two of the endpoints then you have a design problem.
I would suggest that you first decide what main function the upload is for. Is it a profile upload or a category upload.
Make the upload for one. Then you can always assign a category for a profile according to your business needs.
You can give the categoryId as a query parameter to your profile upload endpoint like:
/profiles/{profileid}/uploads?categoryId={categoryid}
add a comment |
If you are doing the same thing in two of the endpoints then you have a design problem.
I would suggest that you first decide what main function the upload is for. Is it a profile upload or a category upload.
Make the upload for one. Then you can always assign a category for a profile according to your business needs.
You can give the categoryId as a query parameter to your profile upload endpoint like:
/profiles/{profileid}/uploads?categoryId={categoryid}
add a comment |
If you are doing the same thing in two of the endpoints then you have a design problem.
I would suggest that you first decide what main function the upload is for. Is it a profile upload or a category upload.
Make the upload for one. Then you can always assign a category for a profile according to your business needs.
You can give the categoryId as a query parameter to your profile upload endpoint like:
/profiles/{profileid}/uploads?categoryId={categoryid}
If you are doing the same thing in two of the endpoints then you have a design problem.
I would suggest that you first decide what main function the upload is for. Is it a profile upload or a category upload.
Make the upload for one. Then you can always assign a category for a profile according to your business needs.
You can give the categoryId as a query parameter to your profile upload endpoint like:
/profiles/{profileid}/uploads?categoryId={categoryid}
answered Nov 20 '18 at 13:59
Tarik Tutuncu
44328
44328
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%2f53374343%2fbest-way-of-structuring-rest-uris%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
No one is preferred, you should define both, because they differ in their behavior.
– Yurii N.
Nov 19 '18 at 12:16
I fail to see how the shown classes and URLs are related in this question? You tend to see questions about URLs associated with Action methods. Can you clarify what it is you mean
– Nkosi
Nov 19 '18 at 12:18
Your question doesn't make sense. In the first URI, you're adding uploads associated with a particular profile, while in the second you're adding uploads associated with a particular category. There is no "preferred" URI. They're entirely separate.
– Chris Pratt
Nov 19 '18 at 13:47
I know they are separate Uri's, but both of them do the same work when post new Upload to both of Uri's.
– user3284331
Nov 19 '18 at 14:39
I've edited the question to clarify it more.
– user3284331
Nov 19 '18 at 14:45