简体   繁体   中英

RESTful API and versioning in Zend Framework 2

I created a RESTful API in Zend Framework 2.1 but I still don't know what is the best approach to make versioning for this API. I also use the doctrine as a model part of my app. I'd like to have links like that:

  • api.name-of-my-project.com/v1/products
  • api.name-of-my-project.com/v1/products/123

where v1 describes the version of API.

So far I already created API without versioning and I also have some ideas about how to create versioning but first I'd like to know your opinions about this problem. What should I do to separate controllers and maybe other classes from different versions and how to manage the routing? By the way I think that I am not really interested about creating another module because I already have module like API .

The final app should be able to work with "many" versions of API. I'd like to also inherit some functionality from older version of API in my new one.

您可以在模块配置中使用zf2路由数组来执行此操作,将v1的路由映射到versiononecontroller,将v2的路由映射到versiontwocontroller

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM