Laravel RESTful API versioning design

前端 未结 3 1747
深忆病人
深忆病人 2021-01-30 05:01

I am new to Laravel (4 and 5) and recently I am working on a RESTful API. In order to allow multiple version of the API, I am using URL to determine the version.

I rea

相关标签:
3条回答
  • 2021-01-30 05:36

    I created a simple Laravel package to support Laravel API versioning it adds fallback functionality to routes. I personally needed this long ago but didn't realize it will be achieved with such a tiny package.

    https://github.com/mbpcoder/laravel-api-versioning

    0 讨论(0)
  • 2021-01-30 05:47

    You can not use dots, use underscores instead.

    But...

    A well-designed api must have BC between minor versions, so you do not need to create new version for minor update, instead you need to write compatible code.

    0 讨论(0)
  • 2021-01-30 05:49

    IMO, minor upgrades should not publish breaking changes to an API. So my suggestion is to stick to integer versioned APIs. Enhancements are no problems, but existing endpoints should behave as usual.

    This way your API-Versions would be in sync with the route-prefixes and the namespaces as well as the tests.

    EXAMPLE

    1. You begin with v1.0
    2. You make a little change (eg. git-tag v1.1) which does not bring breaking changes to your api. Is there a need for developers to do anything else in their code? No, there is not. So you can safeley let the URI-Prefix stay at V1, so that developers calling your api do not need to change all their code which is calling your API (and therefore, automatically benefit from the new minor version). Maybe you just fixed a bug, which makes their code behave just as expected or you published a new feature, which by its self does not break existing feature-calls.
    3. Your App grows and you publish new redesigned version of you API which contains breaking changes. In this case, you publish a new API-URI-prefix (V2).

    Be aware that you can of course keep track of the minor versions internally (e.g in SCM), but there should be no need for developers to change all of their API-Calls just to benefit from that little bugfix you published. Anyways, it is nice of course if you notify your clients of the newer minor versions and the bugfixes or enhancements they offer (blog, newsletter, ..)

    Let me add, that i am not aware of any RESTful APIs with minor API-URL-prefixes, so i guess this is quite a common practice.

    0 讨论(0)
提交回复
热议问题