I want to build a new REST API for my application on the base of zend framework 3. Because I'm very new in zend two things are a bit misunderstanding for me: I know there's a component named zf-rest and I also know how to include it via composer. But how does zf-rest "knows" that I want to work with ZF3?
And then I found some sample applications using zf-rest and some only using zend-mvc. So I guess that zend already has a rest implementation. What are the differences between zf-rest and zend-mvc and in which situations should I use which framework?
Related
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 ?
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.
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.
You can do this with zf2 routing array in your module config
Map routes with v1 to versiononecontroller and v2 to versiontwocontroller
I'm using the PHP Slim Framework for my RESTful project.
I was wondering if its possible to get a list of all the callback registered with Slim somehow so as to have a list of all the REST resources that are available for the app?
I assume this will involve some sort of pre-compile but I'm not sure how to do it.
I haven't used the Slim Framework yet (looks quite exciting, thanks for the pointer), but my best guess would be using PHPDocumentor to generate documentation about your rest endpoints.
You can find it at the phpdocumentor website
I have never used a PHP framework before and am considering using Symfony for my next one. However, I have already built an API which has all my main classes. I will therefore connect to this API using CURL. Can anyone advise on where to start with such a project. I am working through a Symfony tutorial but none of it seems to apply to what I need to do as I do not need to create database connections or classes as I will be building this project on my existing API.
If you don't need a lot of what you see in the Symfony tutorials you might be able to get away with Silex. Silex is a mini-framework with alot of the core aspects of Symfony, but without the extra stuff.
http://silex.sensiolabs.org/
I'm new to Zend Framework (not to PHP), and I need to create a REST based API using Zend.
I've seen examples using Zend_Rest_Server, however other sources state that that has been deprecated.
I'm unable to find a solid example which shows how I should be building such an API.
Zend_Rest_Server is indeed deprecated since ZF 1.9, you should use Zend_Rest_Controller instead. The following blog posts could be helpful : Building RESTful Services with Zend Framework and Create RESTful Applications Using The Zend Framework.
May be this link would be helpful: Creating a PHP REST API Using the Zend Framework.
This code example support REST data in the format of XML and JSON.
Prerequisites:
PHP version > 5
Zend Framework 1.9.2 (at the minimum)
If you want something a little more in details, you can check the book
Zend Framework 2 Application Development.
The book explains construction of API oriented system in ZF2, through examples.
At the end of book you get:
ZF2 API
ZF2 Client side app.
The book has a lot of syntax errors as well as any book for programming,
but it's only one on the market at this moment.