Best way to build RESTful services using Zend Fram

2019-05-26 23:53发布

问题:

We are starting a new project that will make use of RESTful services to talk to web clients (AngularJS) and mobile platforms (Android and iOS).

The idea is to hide the bussiness logic inside the RESTful services and to use the same code for both web client and mobile platforms.

Our server is being built in PHP using Zend Framework 3 (I´m new to the framework). The application will be have dozen of entities with hundreds of services.

I´ve noted on the web that is seems that ZF2 has a REST module, but I can´t find one for ZF3 (at least not in the documentation).

Some questions I have:

  • What is the best path to provide RESTful services using ZF3 ?
  • Shall I install a ZF module ? Is there something ready to be used that comes with ZF3 ?
  • Shall I create a Module in the code just for my services ? Shall the other modules call this REST module for business logic ?

回答1:

ZF3 is still shipped with an AbstractRestController, which can be found here. Apigility could be a starting point for your REST application, but you could also consider implementing only some parts of Apigility and build your own logic on top of that. Interesting modules can be found in the ZF-Campus GitHUB repository:

  • ZF-Rest
  • ZF-Content-Negotiation
  • ZF-Content-Validation
  • ZF-Hal (depending on whether HAL-Json works for you...)

Most (if not all) of those modules are refactored to support ZF3 (and backwards compatible with ZF2).

Browse through the repository yourself because you might find additional useful modules.