Rest method, link with what we return











up vote
0
down vote

favorite












I've read all best practices about Restfull API but they always use simple examples. I often read things like :



GET  /cars      -> return all cars
PUT /cars/1 -> update car with id 1
etc...


So ok, we name the rest method "cars" because we're dealing with car resources.
But what about "advanced operations" ?



For example, I have a system where users have accounts. I want to create a GET method that allows to check if a person is linked to an account existing in database.



So I can create :



GET  /users/1/10   ->  return users data if user with id 1 is linked to the account with id 10


Is it good to name "/users" my method ? Knowing that the purpose to my method is not really to get user data but check if his account exists in databse



In other words, do we have to name our Rest methods depending on the data we return or depending on the purpose of the method ?










share|improve this question


























    up vote
    0
    down vote

    favorite












    I've read all best practices about Restfull API but they always use simple examples. I often read things like :



    GET  /cars      -> return all cars
    PUT /cars/1 -> update car with id 1
    etc...


    So ok, we name the rest method "cars" because we're dealing with car resources.
    But what about "advanced operations" ?



    For example, I have a system where users have accounts. I want to create a GET method that allows to check if a person is linked to an account existing in database.



    So I can create :



    GET  /users/1/10   ->  return users data if user with id 1 is linked to the account with id 10


    Is it good to name "/users" my method ? Knowing that the purpose to my method is not really to get user data but check if his account exists in databse



    In other words, do we have to name our Rest methods depending on the data we return or depending on the purpose of the method ?










    share|improve this question
























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I've read all best practices about Restfull API but they always use simple examples. I often read things like :



      GET  /cars      -> return all cars
      PUT /cars/1 -> update car with id 1
      etc...


      So ok, we name the rest method "cars" because we're dealing with car resources.
      But what about "advanced operations" ?



      For example, I have a system where users have accounts. I want to create a GET method that allows to check if a person is linked to an account existing in database.



      So I can create :



      GET  /users/1/10   ->  return users data if user with id 1 is linked to the account with id 10


      Is it good to name "/users" my method ? Knowing that the purpose to my method is not really to get user data but check if his account exists in databse



      In other words, do we have to name our Rest methods depending on the data we return or depending on the purpose of the method ?










      share|improve this question













      I've read all best practices about Restfull API but they always use simple examples. I often read things like :



      GET  /cars      -> return all cars
      PUT /cars/1 -> update car with id 1
      etc...


      So ok, we name the rest method "cars" because we're dealing with car resources.
      But what about "advanced operations" ?



      For example, I have a system where users have accounts. I want to create a GET method that allows to check if a person is linked to an account existing in database.



      So I can create :



      GET  /users/1/10   ->  return users data if user with id 1 is linked to the account with id 10


      Is it good to name "/users" my method ? Knowing that the purpose to my method is not really to get user data but check if his account exists in databse



      In other words, do we have to name our Rest methods depending on the data we return or depending on the purpose of the method ?







      rest restful-url






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 23 hours ago









      whySoSerious

      405




      405
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote














          1. if one user has more than one account and if you use two collections for users and accounts then route should be as follows to access a specific resource.


          /users/{userId}/accounts/{accountID}.



          You always need to maintain the relationship between resources. In this case, an account is a sub-resource of a user.




          1. Or you can use filtering as follows


          /users/{userId}/accounts?accountId=10






          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',
            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%2f53371110%2frest-method-link-with-what-we-return%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








            up vote
            0
            down vote














            1. if one user has more than one account and if you use two collections for users and accounts then route should be as follows to access a specific resource.


            /users/{userId}/accounts/{accountID}.



            You always need to maintain the relationship between resources. In this case, an account is a sub-resource of a user.




            1. Or you can use filtering as follows


            /users/{userId}/accounts?accountId=10






            share|improve this answer

























              up vote
              0
              down vote














              1. if one user has more than one account and if you use two collections for users and accounts then route should be as follows to access a specific resource.


              /users/{userId}/accounts/{accountID}.



              You always need to maintain the relationship between resources. In this case, an account is a sub-resource of a user.




              1. Or you can use filtering as follows


              /users/{userId}/accounts?accountId=10






              share|improve this answer























                up vote
                0
                down vote










                up vote
                0
                down vote










                1. if one user has more than one account and if you use two collections for users and accounts then route should be as follows to access a specific resource.


                /users/{userId}/accounts/{accountID}.



                You always need to maintain the relationship between resources. In this case, an account is a sub-resource of a user.




                1. Or you can use filtering as follows


                /users/{userId}/accounts?accountId=10






                share|improve this answer













                1. if one user has more than one account and if you use two collections for users and accounts then route should be as follows to access a specific resource.


                /users/{userId}/accounts/{accountID}.



                You always need to maintain the relationship between resources. In this case, an account is a sub-resource of a user.




                1. Or you can use filtering as follows


                /users/{userId}/accounts?accountId=10







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered 20 hours ago









                Janaka

                361




                361






























                     

                    draft saved


                    draft discarded



















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53371110%2frest-method-link-with-what-we-return%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

                    Saint-Aignan (Tarn-et-Garonne)

                    Volksrepublik China

                    How to test boost logger output in unit testing?