Improved developer experience for building an API for a JS framework frontend

(Tom) #1

For a new project, I took the leap from traditional application development in PHP (with Yii2 of course), to API-driven development with the API built in PHP with Yii2 and the front-end build in JavaScript with NuxtJS (Vue.JS framework). In light of Yii3 developments and discussions with @machour , I wanted to share my experiences and thoughts given that this is increasingly a mainstream design pattern and Yii should aspire to be the leading framework for developing that API/back-end.

So here are my main gripes / opportunities for improvement when it comes to Yii2, that I believe should be addressed now and/or in Yii3:

  1. GII has a CRUD generator for web pages, but doesn’t have a generator for an API front-end. Can only use it to generate the models and web controllers, not REST ActiveControllers.

  2. GII model generator should have an “add linkable” option to automatically include HATEOS code.

  3. A GII generated code for ActiveController should contain the CRUD actions, but commented out, to give users a jump-start overruling/extending default actions.

  4. GII generation of [Model]Search.php is part of CRUD in stead of the model generator, which does not make sense because you want it for search queries on actionIndex(), which is kind of a frequent requirement.

  5. A GII generator for ActiveController and Model should contain the code to support Search by default. A solution for formName that works both with REST and web would also be preferable (see this solution).

  6. As a developer I find the authentication-behavior-must-be-added-after-CORS-behavior issue ridiculously annoying. How hard is it to do an in_array() check in the Yii core code and fix this “under the hood” when loading the behaviors?

  7. Core support for GraphQL just like REST is necessary for development of a good API-driven back-end for a pure JavaScript front-end. Many queries are far more efficient with GraphQL than with REST, so it makes sense for a developer to use both. Hence, Yii3 should support both. I know there is an extension for yii2 but I would prefer this moved to core for yii3.

  8. Being able to kick-start Angular/React/Vue applications using Yii’s built-in generator would be a huge Unique Selling Point that would probably attract a lot of attention and developers. Perhaps GII extensions are feasible to auto-generate Gatsby/Next/Nuxt/etc. CRUD JavaScript/TypeScript code in addition to the Yii REST code?