Best way of structuring REST URIs












-1














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:




  1. /profiles/{id}/uploads

  2. /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?










share|improve this question
























  • 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
















-1














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:




  1. /profiles/{id}/uploads

  2. /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?










share|improve this question
























  • 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














-1












-1








-1


1





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:




  1. /profiles/{id}/uploads

  2. /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?










share|improve this question















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:




  1. /profiles/{id}/uploads

  2. /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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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


















  • 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












1 Answer
1






active

oldest

votes


















0














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}





share|improve this answer





















    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
    });


    }
    });














    draft saved

    draft discarded


















    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









    0














    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}





    share|improve this answer


























      0














      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}





      share|improve this answer
























        0












        0








        0






        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}





        share|improve this answer












        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}






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 20 '18 at 13:59









        Tarik Tutuncu

        44328




        44328






























            draft saved

            draft discarded




















































            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.




            draft saved


            draft discarded














            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





















































            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







            Popular posts from this blog

            Can a sorcerer learn a 5th-level spell early by creating spell slots using the Font of Magic feature?

            Does disintegrating a polymorphed enemy still kill it after the 2018 errata?

            A Topological Invariant for $pi_3(U(n))$