During my talk at SymfonyWorld, I announced the immediate availability of API Platform 2.6! Try it now!
Version 2.6 is the result of more than one year of work and hundreds of commits. It contains a huge list of new features, checkout the change logs (core library, distribution) for the full list. In this blog post, I’ll present the major new features! You can also take a look at the slide deck I presented (go on SpeakerDeck for the transcript):
See also the French translation of this article.
PHP 8 Support
PHP 8 was released one week ago, and it comes with a huge list of new features. Among these features, attributes are a game changer for API Platform, as it relied a lot on annotations.
Starting with API Platform 2.6 you can use every annotation classes as PHP 8 attributes:
<?php
namespace App\Entity;
use ApiPlatform\Core\Annotation\ApiResource;
#[ApiResource]
class Book
{
public function __construct(
public string $id,
public string $title
) {}
}
API Platform is now also fully compatible with PHP 8 (all deprecations have been fixed), and PHP 8 is now the default in the API Platform Distribution!
Next.js and Nuxt.js Support
API Platform comes with a very practical tool to scaffold client applications: the client generator. This generator uses the Hydra or OpenAPI (experimental) documentation of the API to generate apps using various client-side technologies. It works with any API documented using these formats, not only with APIs using the server-side component of API Platform!
Generating TypeScript interfaces as well as of Progressive Web Apps built with React Native, React/Redux, Vue.js, Quasar and Vuetify was already supported. In API Platform 2.6, this tool gained support for Next.js!
Next.js is the reference framework in the React ecosystem. It is very easy to use, supports Server-Side Rendering out of the box, has a simple yet powerful page-based routing system and supports a wide range of features.
We also updated the API Platform distribution to use Next.js by default. A Docker container and a Docker Compose definition will start a skeleton of a Next.js app automatically and you will be able to scaffold your pages and forms by running a single command!
API Platform Admin is now also integrated in this Next.js app, on the /admin
route.
You prefer using Vue instead of React? We’ve got you covered! In API Platform 2.6 we also introduced a Nuxt.js generator. Nuxt.js is similar to Next.js, but using Vue! And, as API Platform, it has been created by French folks!
Simplifying the API Platform Distribution with Caddy Server
In API Platform 2.6, the distribution has been totally revamped. API Platform supports many advanced features out of the box, including the Mercure and Vulcain protocols. To support these features, API Platform came with many Docker containers:
- PHP FPM
- NGINX
- A container to generate TLS certificates
- Vulcain reverse proxy
- Mercure Hub
- Postgres
- A Node.js container for the client generator
- A Node.js container for the admin app
In API Platform 2.6, we simplified everything! First, we switched from NGINX to the awesome Caddy web server. Caddy is fast, fully-featured and extensible. For instance, it generates TLS certificates automatically both in production and on local development environment and natively supports PHP FPM. We also created Caddy modules for Mercure and for Vulcain! We’re also working with the Caddy team to create an HTTP cache module that will replace Varnish.
As explained in the previous section, we also replaced Create React App by Next.js and merged the containers for the client and the admin.
The result is a very simplified setup:
- PHP FPM
- Caddy web server
- Postgres (optional)
- Next.js container (optional)
We also added support for a production mode to the Docker Compose definition included in the distribution.
Better Configuration
Until now, it wasn’t possible to define global configuration defaults applied to all resources and all operations. You had to copy your configuration in all resource definitions. Starting with API Platform 2.6, you can define a global default configuration:
# config/packages/api_platform.yaml
api_platform:
defaults:
itemOperations: ["get"]
collectionOperations: ["get"]
mercure: true
With the previous config, write routes are disabled for the whole API, and Mercure support (async API) is enabled for all resources!
Access Control for Properties
API Platform supports resource-based access control. In 2.6, we introduced support for property-based access control:
<?php
namespace App\Entity;
use ApiPlatform\Core\Annotation\ApiResource;
use ApiPlatform\Core\Annotation\ApiProperty;
#[ApiResource]
class Book
{
#[ApiProperty(security: "is_granted('ROLE_ADMIN')"]
public $adminOnlyProperty;
}
Thanks to this rule, the adminOnlyProperty
will be serialized only for users having the admin
role! Other users will not be able to see it.
Schema Generator v3
Read the dedicated article about this new version of API Platform Schema Generator.
ActivityPub Component
As you may know, I’m very worried by the current state of the web, and I think that we must fight to decentralize the web again.
ActivityPub is a specification edited by the W3C unlocking interoperability between social networking applications. It’s part of the solution to fight global censorship and to move out of the walled gardens of big tech companies. ActivityPub is already implemented by many software including Mastodon (Twitter-like), PeerTube (YouTube-like), PixelFed (Instagram-like), Mobilizon (Meetup-like)… This ecosystem is called the Fediverse.
In API Platform 2.6, we introduced a new experimental component allowing to add support for ActivityPub in any API Platform or Symfony application! It’s now way easier than before to build federated apps and to grow the Fediverse!
Community
The biggest strength of API Platform is its community of users and contributors! To celebrate our vibrant community, we added new pages to the website dedicated to the community. Each contributor now has a dedicated page including a summary of their contributions. Discover our awesome community!
And to thank contributors, we’re also offering nice t-shirts to them as part of the Hacktoberfest initiative!
API Platform 3
The next version of API Platform will be API Platform 3! We’ll release API Platform 2.7 at the same time. API Platform 3 will basically be API Platform 2.7 minus the backward compatibility layer with the deprecated code.
API Platform 3 will promote subresources as first-class citizens! They will support write operations. The overall configuration is also being revamped.
Also, to reduce the maintenance burden, API Platform 3 will only support PHP 8 and Symfony 5.2+! Be prepared.
Misc
They are also loads of new features in API Platform 2.6 not listed in this blog post: our GraphQL subsystem gained a lot of new features (including support for subscriptions and page-based pagination), the MongoDB bridge now supports the Mercure protocol, the OpenAPI builder has been totally rewritten, composed identifiers are easier to handle… Read the change logs (core library, distribution) to discover all of them!
I want to thank all contributors having contributed code and documentation for API Platform 2.6! Nothing would be possible without you.
Please try this new version and report any bugs!
If you have not yet given a GitHub star to the project, please do, it helps a lot to promote it.
If you like my work on the project, please also consider sponsoring me!