Best practices for API backwards compatibility

前端 未结 2 2028
失恋的感觉
失恋的感觉 2021-01-31 21:17

I\'m working on an iPhone/iPad/Android app which communicates with a JSON API.

The first release of the version of the app is complete, and now additional phases of deve

2条回答
  •  难免孤独
    2021-01-31 21:26

    I guess you already have a separation of concerns. I mean, getting the datas for your app is only done through the Model (for example).

    So you only have to change the model.

    What I suggest is that there is only one entry point: the "router" file. This file checks the API version needed, and loads the correct file. This way, you get different files for each API. The "router" file won't be very big, and each new API version will have its own file, so you're not mixing everything.

    For example, in the "router" file:

    function dispatch() {
        switch (APIVersion) {
        case 1:
            use('file.1.ext');
            break;
        case 2:
            use('file.2.ext');
            break;
        case 3:
            use('file.3.ext');
            break;
        }
    }
    

提交回复
热议问题