How to introduce versioning for endpoints for akka http












1














I have 5 controllers in akka-http. Each endpoint has 5 endpoints(routes). Now I need to introduce versioning for those. All endpoints should be prefixed with /version1.
For example if there was an endpoint xyz now it should be /version1/xyz.
One of the ways is to add a pathPrefix But it needs to be added to each controller.
Is there way to add it at a common place so that it appears for all endpoints.



I am using akka-http with scala.










share|improve this question



























    1














    I have 5 controllers in akka-http. Each endpoint has 5 endpoints(routes). Now I need to introduce versioning for those. All endpoints should be prefixed with /version1.
    For example if there was an endpoint xyz now it should be /version1/xyz.
    One of the ways is to add a pathPrefix But it needs to be added to each controller.
    Is there way to add it at a common place so that it appears for all endpoints.



    I am using akka-http with scala.










    share|improve this question

























      1












      1








      1







      I have 5 controllers in akka-http. Each endpoint has 5 endpoints(routes). Now I need to introduce versioning for those. All endpoints should be prefixed with /version1.
      For example if there was an endpoint xyz now it should be /version1/xyz.
      One of the ways is to add a pathPrefix But it needs to be added to each controller.
      Is there way to add it at a common place so that it appears for all endpoints.



      I am using akka-http with scala.










      share|improve this question













      I have 5 controllers in akka-http. Each endpoint has 5 endpoints(routes). Now I need to introduce versioning for those. All endpoints should be prefixed with /version1.
      For example if there was an endpoint xyz now it should be /version1/xyz.
      One of the ways is to add a pathPrefix But it needs to be added to each controller.
      Is there way to add it at a common place so that it appears for all endpoints.



      I am using akka-http with scala.







      scala refactoring versioning endpoint akka-http






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 21 at 9:55









      user9920500

      535




      535
























          2 Answers
          2






          active

          oldest

          votes


















          2














          You can create a base route, that accepts paths like /version1/... and refers to internal routes without path prefix.



          val version1Route = path("xyz") {
          ...
          }
          val version2Route = path("xyz") {
          ...
          }
          val route = pathPrefix("version1") {
          version1Route
          } ~ pathPrefix("version2") {
          version2Route
          }





          share|improve this answer





























            0














            Indirect Answer



            Aleksey Isachenkov's answer is the correct direct solution.



            One alternative is to put versioning in the hostname instead of the path. Once you have "version1" of your Route values in source-control then you can tag that checkin as "version1", deploy it into production, and then use DNS entries to set the service name to version1.myservice.com.



            Then, once newer functionality becomes necessary you update your code and tag it in source-control as "version2". Release this updated build and use DNS to set the name as version2.myservice.com, while still keeping the version1 instance running. This would result in two active services running independently.



            The benefits of this method are:




            1. Your code does not continuously grow longer as new versions are released.

            2. You can use logging to figure out if a version hasn't been used in a long time and then just kill that running instance of the service to End-Of-Life the version.

            3. You can use DNS to define your current "production" version by having production.myservice.com point to whichever version of the service you want. For example: once you've released version24.myservice.com and tested it for a while you can update the production.myservice.com pointer to go to 24 from 23. The old version can stay running for any users that don't want to upgrade, but anybody who wants the latest version can always use "production".






            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%2f53409398%2fhow-to-introduce-versioning-for-endpoints-for-akka-http%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              2














              You can create a base route, that accepts paths like /version1/... and refers to internal routes without path prefix.



              val version1Route = path("xyz") {
              ...
              }
              val version2Route = path("xyz") {
              ...
              }
              val route = pathPrefix("version1") {
              version1Route
              } ~ pathPrefix("version2") {
              version2Route
              }





              share|improve this answer


























                2














                You can create a base route, that accepts paths like /version1/... and refers to internal routes without path prefix.



                val version1Route = path("xyz") {
                ...
                }
                val version2Route = path("xyz") {
                ...
                }
                val route = pathPrefix("version1") {
                version1Route
                } ~ pathPrefix("version2") {
                version2Route
                }





                share|improve this answer
























                  2












                  2








                  2






                  You can create a base route, that accepts paths like /version1/... and refers to internal routes without path prefix.



                  val version1Route = path("xyz") {
                  ...
                  }
                  val version2Route = path("xyz") {
                  ...
                  }
                  val route = pathPrefix("version1") {
                  version1Route
                  } ~ pathPrefix("version2") {
                  version2Route
                  }





                  share|improve this answer












                  You can create a base route, that accepts paths like /version1/... and refers to internal routes without path prefix.



                  val version1Route = path("xyz") {
                  ...
                  }
                  val version2Route = path("xyz") {
                  ...
                  }
                  val route = pathPrefix("version1") {
                  version1Route
                  } ~ pathPrefix("version2") {
                  version2Route
                  }






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 21 at 10:55









                  Aleksey Isachenkov

                  592113




                  592113

























                      0














                      Indirect Answer



                      Aleksey Isachenkov's answer is the correct direct solution.



                      One alternative is to put versioning in the hostname instead of the path. Once you have "version1" of your Route values in source-control then you can tag that checkin as "version1", deploy it into production, and then use DNS entries to set the service name to version1.myservice.com.



                      Then, once newer functionality becomes necessary you update your code and tag it in source-control as "version2". Release this updated build and use DNS to set the name as version2.myservice.com, while still keeping the version1 instance running. This would result in two active services running independently.



                      The benefits of this method are:




                      1. Your code does not continuously grow longer as new versions are released.

                      2. You can use logging to figure out if a version hasn't been used in a long time and then just kill that running instance of the service to End-Of-Life the version.

                      3. You can use DNS to define your current "production" version by having production.myservice.com point to whichever version of the service you want. For example: once you've released version24.myservice.com and tested it for a while you can update the production.myservice.com pointer to go to 24 from 23. The old version can stay running for any users that don't want to upgrade, but anybody who wants the latest version can always use "production".






                      share|improve this answer




























                        0














                        Indirect Answer



                        Aleksey Isachenkov's answer is the correct direct solution.



                        One alternative is to put versioning in the hostname instead of the path. Once you have "version1" of your Route values in source-control then you can tag that checkin as "version1", deploy it into production, and then use DNS entries to set the service name to version1.myservice.com.



                        Then, once newer functionality becomes necessary you update your code and tag it in source-control as "version2". Release this updated build and use DNS to set the name as version2.myservice.com, while still keeping the version1 instance running. This would result in two active services running independently.



                        The benefits of this method are:




                        1. Your code does not continuously grow longer as new versions are released.

                        2. You can use logging to figure out if a version hasn't been used in a long time and then just kill that running instance of the service to End-Of-Life the version.

                        3. You can use DNS to define your current "production" version by having production.myservice.com point to whichever version of the service you want. For example: once you've released version24.myservice.com and tested it for a while you can update the production.myservice.com pointer to go to 24 from 23. The old version can stay running for any users that don't want to upgrade, but anybody who wants the latest version can always use "production".






                        share|improve this answer


























                          0












                          0








                          0






                          Indirect Answer



                          Aleksey Isachenkov's answer is the correct direct solution.



                          One alternative is to put versioning in the hostname instead of the path. Once you have "version1" of your Route values in source-control then you can tag that checkin as "version1", deploy it into production, and then use DNS entries to set the service name to version1.myservice.com.



                          Then, once newer functionality becomes necessary you update your code and tag it in source-control as "version2". Release this updated build and use DNS to set the name as version2.myservice.com, while still keeping the version1 instance running. This would result in two active services running independently.



                          The benefits of this method are:




                          1. Your code does not continuously grow longer as new versions are released.

                          2. You can use logging to figure out if a version hasn't been used in a long time and then just kill that running instance of the service to End-Of-Life the version.

                          3. You can use DNS to define your current "production" version by having production.myservice.com point to whichever version of the service you want. For example: once you've released version24.myservice.com and tested it for a while you can update the production.myservice.com pointer to go to 24 from 23. The old version can stay running for any users that don't want to upgrade, but anybody who wants the latest version can always use "production".






                          share|improve this answer














                          Indirect Answer



                          Aleksey Isachenkov's answer is the correct direct solution.



                          One alternative is to put versioning in the hostname instead of the path. Once you have "version1" of your Route values in source-control then you can tag that checkin as "version1", deploy it into production, and then use DNS entries to set the service name to version1.myservice.com.



                          Then, once newer functionality becomes necessary you update your code and tag it in source-control as "version2". Release this updated build and use DNS to set the name as version2.myservice.com, while still keeping the version1 instance running. This would result in two active services running independently.



                          The benefits of this method are:




                          1. Your code does not continuously grow longer as new versions are released.

                          2. You can use logging to figure out if a version hasn't been used in a long time and then just kill that running instance of the service to End-Of-Life the version.

                          3. You can use DNS to define your current "production" version by having production.myservice.com point to whichever version of the service you want. For example: once you've released version24.myservice.com and tested it for a while you can update the production.myservice.com pointer to go to 24 from 23. The old version can stay running for any users that don't want to upgrade, but anybody who wants the latest version can always use "production".







                          share|improve this answer














                          share|improve this answer



                          share|improve this answer








                          edited Nov 21 at 15:24

























                          answered Nov 21 at 13:35









                          Ramon J Romero y Vigil

                          11.6k24071




                          11.6k24071






























                              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%2f53409398%2fhow-to-introduce-versioning-for-endpoints-for-akka-http%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

                              404 Error Contact Form 7 ajax form submitting

                              How to know if a Active Directory user can login interactively

                              Refactoring coordinates for Minecraft Pi buildings written in Python