1

stack: node express restful api

Goal:two version api, v1 and v2, I wish these two versions api running on the same server at the same time.

project layers:router/controller/service/model folders

solutions:

option 1.v2 could copy all folders from v1, and make changes on each file. so that we could have file structure like this:

--src
    --v1
        --v1 route
        --v1 controller
        --v1 service
    --v2
        --v2 route
        --v2 controller
        --v2 service
    --db
    --config

In this way, we would have most of repeated source code. does not feel smart enough in this way, even though its simple and straight

option 2.v2 could extend some of module/class of v1 to override some methods in side. so that we could have a file structure like this:

--src
    --router
    --controller
        --user
        --user_v2 extends user //export this new controller to router v2
    --service
        --user
        --user_v2

In this way, we could at most reuse v1 source code, however, in v2, we change ie.movieController, in v3, we change ie.soccerController. it soon becomes messy the whole proejct.

I really really wish someone could provide me a perfect way and file structure so that we could at most reuse v1 source code, at the same time. we have clear file structure on which APIs has changed compare to prev version.

Really appreciate ~~~!!!

feeco
  • 75
  • 4

0 Answers0