4

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 ?
Wilt
  • 41,477
  • 12
  • 152
  • 203
Mendes
  • 17,489
  • 35
  • 150
  • 263
  • 2
    You will find it very easy to work with [apigility](https://apigility.org/), which is based on ZendFramework and resolves already the entire problematic of the RESTfull protocol, validation of requests, format of responses – Dragos Dec 02 '16 at 11:43
  • This is not really a question for stackoverflow, it's rather a debate subject. – Dragos Dec 02 '16 at 11:44
  • 1
    Most of the projects I've worked for would keep the business logic in separate ZF Modules which would expose the data through services, then query those services from the Apitility's Controllers/Resources. – Dragos Dec 02 '16 at 11:48
  • Thanks Dragos for the Apigility hint. BTW, a comment: typing "Best Way" in SO returns 461,750 results, most of them with debates like this with thousands of votes. It is a shame we cannot anymore share architectural doubts in SO, as most of then are called to be banned. ZF3 is pretty new and its very useful to the community to understand possible architectural designs with any new technology... – Mendes Dec 02 '16 at 11:51
  • I do agree with you on the debate part, it's just the way SO is structured, a debate would not fit here for the sole reason, one cannot tell 100% exactly and sure which would be the best way, therefore one cannot accept one single answer to this question. But one can only click on one answer as being accepted. – Dragos Dec 02 '16 at 12:09
  • 2
    Sorry, but I disagree. SO was build for asking questions and offering responses. You can vote on a answer or a best answer, or even don´t choose to vote. The content that offers knowledge, not the votes. Architectural and design discussions are the most important thing before starting code, but this is my point of view. – Mendes Dec 02 '16 at 12:42
  • It is a valid point of view :) I can't disagree on it. – Dragos Dec 02 '16 at 12:45
  • You say *"ZF2 has a REST module, but I can´t find one for ZF3"*. What module are you exactly talking about? I think most modules that were part of ZF2 are also still shipped with ZF3. – Wilt Dec 02 '16 at 13:08

1 Answers1

6

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:

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.

Wilt
  • 41,477
  • 12
  • 152
  • 203
  • Thanks Wilt for the comments. So I´m thinking structuring a single module for REST services (`RESTModule`, ie), and several Controllers, one for each entity group, something like `UserRestController` (for user information), `SalesRestController` (for sales info), `InvoiceRestController` (for invoicing), and so on... Would that make sense ? – Mendes Dec 02 '16 at 13:51
  • Yes, that makes sense. In Apigility you have resource listeners in that case you would have a `ResourceListener` for each entity type. collections and singletons are both handled within the same controller/listener. – Wilt Dec 02 '16 at 14:14