Setting the UUID on POST
…
Remember: API platform - well really, Symfony's serializer - is really good at
reading your types. It notices that the type for $uuid is UuidInterface
and uses that to try to find a denormalizer that understands this type. And
fortunately, API Platform comes with a denormalizer…
Custom Filter apply()
…implement the
FilterInterface from the core Serializer\ namespace, API Platform will help
us a bit:
How? By automatically calling our apply() method on every request for an
API resource where our filter has been activated:
What I mean is, in DailyStats we added @ApiFilter(DailyStatsDateFilter:…
Input DTO: Denormalizing IRI Strings
…data into that type - like creating a DateTime object from a date string.
There are various normalizers that are good at doing this.
And... fortunately API Platform comes with an ItemNormalizer whose job is to
change IRI strings into objects by querying the database... or..…
Passing data From the Server to Vue
…way. Add IriConverterInterface $iriConverter to get a service from
API Platform.
Remember: when you click on the Catalog component in the Vue Dev tools and look
at the products data, each item that we get back from our API - whether it's a
product, category…
Dynamic Groups without Caching
…And... that's fine! Symfony handles
all of that behind the scenes.
In the case of the resource metadata factory, API Platform itself decorates
that service multiple times... each "layer" adding a bit more functionality.
Normally, when we decorate a service from our application, our…
Automatic 404 on Unpublished Items
…individual CheeseListing if it's unpublished.
The collection query extension does not take care of this: this 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…
Microservices Gone Wrong
…ve all gone out and built systems. And a team that I had the
opportunity to lead a number of years ago, we wound up building a platform. And
I'm gonna tell you a little about the background. But we made a bunch of…
Custom Logic Only for some Operations
…which
operation is being used. But if you start also using a PATCH operation or
custom operations, then this would not be enough.
Like many parts of ApiPlatform, a data persister has a normal interface -
DataPersisterInterface:
But also an optional, stronger interface that gives you…
Publishing a Listing
…waiting for our cheese.
So... how should we design this in our API? You might think that we need a custom
endpoint or "operation" in ApiPlatform language. Something like
POST /api/cheeses/{id}/publish.
You can do this. And we'll talk about custom operations…
PropertyFilter: Sparse Fieldsets
…about a protocol
that adds features to your web server. It was created by the API Platform team, and
if we scroll down a bit, they have a really good example.
Pretend that we have the following API. If we make a request to /books…
Passing Values to Stimulus
…a small percentage of your users to
be susceptible to CSRF attacks.
If you want to learn more, our API Platform 2 tutorial has a whole chapter on
SameSite cookies and CSRF tokens.
Next, let's turn to the other authentication use-case: API tokens.
Serializing Messages as JSON
…property into JSON.
We're not going to go too deep into Symfony's serializer component, but if you
want to know more, we go much deeper in our
API Platform Tutorial.
Anyways, this simple JSON structure is something any other system could
understand. So..…
DTO Quirks
…just delete it so that
the tests will pass.
But good news! Thanks to the API Platform team, this bug has been fixed and
should be released in API Platform 2.5.8. But since that hasn't been released yet
at the time of…
Query Extension: Auto-Filter a Collection
…for a specific
resource or even for a specific operation of a resource. They're... basically...
awesome.
Let's get our extension going: in the src/ApiPlatform/ directory, create a new
class called CheeseListingIsPublishedExtension. Make this implement
QueryCollectionExtensionInterface and then go to the Code ->…
Knowing your State Machines
…I'm sorry, show him or her later.
Quick about me. I do plenty of work on Happyr. We are a job advert platform -
it matches people with confidence, blah blah. I do plenty of Symfony things. I
run PHP meetups in Stockholm and I…
Back to the Basics (Symfony local Web Server)
…then you can get started really
easily. The problem is that it comes with many limitations and I'm going to
talk about that in minute.
Docker, well may be slow depending on the platform, especially on a Mac. I mean
it is for me…
Decoration: Override Core Services & AsDecorator
…wild? The answer to that is... sort of all over!
In API Platform, it's common to use decoration to extend core services like
the ContextBuilder. And Symfony itself uses decoration pretty commonly to add
debugging features while we're in the dev environment. For…
Sluggable: Doctrine Extensions
…You do this by creating an event subscriber or
entity listener. We do have an example of an entity listener in our
API Platform tutorial if you're interested.
Next, let's add two more handy fields to our entity: createdAt and updatedAt.
The trick…
Serializer Error Renderer: JSON/XML Errors
…If you wanted
to change this data, you could do that by adding your own custom normalizer.
We actually talk about this in our
API Platform Security Tutorial.
You could decorate the ProblemNormalizer... and maybe just add or tweak some
data or you could create…
x
1000+