User Class Dto
The fastest way to get started with API Platform is by adding these #[ApiResource]
attributes above your entity classes. That's because API Platform gives you free
state providers that query from the database (which ...
The Powerful OpenAPI Spec
... the different operations... everything. The best part
is that API Platform reads our code and generates this giant file for us. Then,
because we have this giant file, we get Swagger UI.
In fact, if you click on "View Page ...
Output DTO Class
... Implementing it is pretty clean and it gives
you a lot of flexibility. But it's also not a feature that is heavily used by the
core API Platform devs. And I found some quirks... some of which are already fixed.
I'll walk you ...
ACL previousObject
... the test:
It fails! We expected a 403 status code but got 200! What?
I mentioned earlier that when a request comes in, API Platform goes through
three steps in a specific order. First it deserializes the JSON and updates ...
Automatic 404 on Unpublished Items
... method is only
called when API Platform needs to query for a collection of items - a different
query is used for a single item.
Let's write a quick test for this. Copy the collection test method, paste the
entire thing ...
Type Validation
... to null that value would not be legal to set on this property.
When this happens, API Platform returns a 400 error. It's not a validation error
exactly... but it effectively means the same thing.
Let's see a real example ...
Using a Custom Date Identifier
... \DateTime('yesterday').
When we refresh the docs... we're back to where we were before: we're missing
the ID on PUT, DELETE, and PATCH, and our single GET is gone. That's because
API Platform doesn't know that the $day ...
Validation
... API is to respond
to all of these situations in an informative and consistent way so that errors
can be easily understood, parsed and communicated back to humans.
This is one of the areas where API Platform really excels ...
Pagination on a Custom Resource
... collection... at the bottom of the response,
API Platform adds a hydra:view field that describes how you can paginate through
these resources. But over here for quests... zilch!
But where does pagination come from in API ...
Filtering Related Collections
... class is only used when API Platform
needs to make a direct query for a CheeseListing. In practice, this means
it's used for the CheeseListing operations. But for a User resource, API
platform queries for the User and then ...
Filters Searching Results
... want to.
How? By Leveraging filters. API Platform comes with a bunch of built-in filters
that allow you to filter the collections of results by text, booleans, dates and
much more.
Here's how it works: above your class, add ...
Operations Endpoints
API Platform works by taking a class like DragonTreasure and saying that you want
to expose it as a resource in your API. We do that by adding the ApiResource
attribute:
Right now, we're putting this above a Doctrine ...
Data Persister Encoding the Plain Password
When an API client makes a POST request to /api/users, we need to be able to run
some code after API Platform deserializes the JSON into a User object, but
before it gets saved to Doctrine. That code will encode the ...
Symfony Live Lille 2019 French
... des sujets sur Symfony (évidemment), mais aussi Mercure, Doctrine, API Platform ou encore React et Redux ainsi que des bonnes pratiques sur les meilleurs bundles et outils pour vos applications Symfony, et d’autres ...
New PUT Behavior
Find your terminal and manually clear the cache directory:
I'm doing this so that, when we run all or our tests
we see a deprecation warning, which is fascinating. It says:
Since API Platform 3.1: in API Platform 4, PUT ...
Property Metadata
... knows nothing about the types of each field. Are these strings? Integers?
Aliens?
API Platform gets metadata about each property from many different places, like
by reading Doctrine metadata, PHPDoc, looking at the return ...
Custom Resource Data Provider
... empty.
This is because API Platform has no idea how to "load" "daily stats" and so...
it just returns nothing. How can we teach it to load DailyStats objects?
With a data provider of course!
Inside the DataProvider ...
Creating Embedded Objects
... Well... forget about API Platform and just imagine you're using this API.
If we're sending a POST request to /api/users to create a new user... isn't it
pretty obvious that we want the new cheese listing to be owned by ...
Our First ApiResource
... enter and... oh! It's asking:
Mark this class as an API Platform resource?
MakerBundle asks this because it noticed that API Platform is installed. Say
"yes". And before we add any fields, let's go see what that did ...
1014
API Platform
Filter Results