1000 search results

Totally Custom Resource

…on an entity, API Platform automatically gives you processors and providers. When you create a custom class, you start with no providers and no processors. This means that API Platform has no idea how to load data when you make a GET request... nor how…

4:19
New PUT Behavior

…what does that mean? Right now, it means nothing has changed: our PUT operation behaves like it always has. But, in API Platform 4, the behavior of PUT will change dramatically. And, at some point between now and then, we need to opt into that…

4:46
Doctrine postLoad Listener

…I know, we're getting crazy, but I want to keep seeing how far we can push API Platform's abilities. This new field will be similar to isMe... but just different enough that it will lead us to an alternate solution. Suppose some users…

8:03
Filtering Relation Collection

…for those treasures and the query collection extension is called. But when we make a call to a user endpoint - like to GET a single User - API Platform is not making a query for any treasures: it's making a query for that one User…

5:39
DTO Input "Initializer"

With an input DTO, the update process works like this. First ApiPlatform queries for the CheeseListing entity. Second, the JSON is deserialized into a new CheeseListingInput object. And third, our transform() method is called, where we take that CheeseListingInput object's data and move it…

6:41
Why/When a Many Relation is IRI Strings vs Embedded

…In DailyStats, to serialize - or "normalize" - we're using a group called daily-stats:read: Whenever API Platform sees an embedded object: It looks at that object - so CheeseListing - and looks to see if any of its fields are in that same group. And there…

5:19
Completely Custom Field via a Data Provider

…providers that load one object for the item operations. Normally, we don't need to think about this system because API Platform has a built-in Doctrine data provider that handles all of it for us. But if we want to load some extra data…

9:19
App & Test Setup

…things that we did in the last course was create a custom data persister: UserDataPersister: Let's see why we did this, use decoration to make it more powerful and learn how data persisters are different than some other parts of ApiPlatform, like context builders.

7:44
Relations and IRIs

…user in the database. But... it didn't like it! Why? Because in API Platform and, commonly, in modern API development in general, we do not use ids to refer to resources: we use IRIs. For me, this was strange at first... but I quickly…

4:39
DTO Data Transformer

…actually work, we need to write code that converts our CheeseListing object into a CheeseListingOutput object so that API Platform can serialize it. The "thing" that does that is called a data transformer. Let's create one in the src/ directory: add a new directory…

5:31
Filters: Searching Results

…down to $isPublished. Paste this above. And now, we don't need the properties option anymore... API Platform figures that out on its own: The result? The same as before. I won't try it, but if you peek at the collection endpoint, it still…

5:14
Access Token Authenticator

API how users are able to authenticate. Fortunately we can do this via API Platform. Open up config/packages/api_platform.yaml. And a new key called swagger, though we're actually configuring the OpenAPI docs. To add a new way of authenticating, set api

8:56
Entity -> DTO Item State Provider

…the endpoint works beautifully. If we try an invalid id, our provider returns null and API Platform takes care of the 404. Side note: if you follow some of these related treasures, they may 404 as well. Let's see... we have 21 and 27…

4:11
Testing Token Authentication

…scopes, and then it would create that token and set it into the header This totally does not work right now, but check out Browser's docs to learn how. Next: in API Platform 3.1, the behavior of the PUT operation is changing. Let…

3:24
Setting a Custom Field Via a Listener

…We just set the $isMe field on the authenticated User object. One cool thing about Doctrine is that if API platform later queries for that same user, Doctrine will return this exact object in memory, which means that the $isMe field will be set to…

5:32
DTO Quirks: Embedded Objects

…on a related object will be serialized, then API Platform should return an array of IRI strings instead of embedding the objects. This is a bug in how the readableLink for properties is calculated when you have a DTO. I've actually fixed this bug…

6:37
Custom Filter for Custom Resources

…go to /api/daily-stats.jsonld, we see all the stats. But if we add ?from=2020-09-01, we want to only show stats on that day or later. Let's do this! Start basically the same way as before: in the src/ApiPlatform/ directory…

7:49
Completely Custom Resource

…types, which will also help API Platform's documentation. More on that soon. Or, if you don't want this stuff to be public, use the normal private properties with getters and setters: whatever you want. To officially make this an API Resource class, above…

5:25
Data Persister Decoration

…create this UserDataPersister class: Now, let's back up real quick. Whenever you use a POST or PUT endpoint, after ApiPlatform deserializes the data into an object and validates it, it tries to save or persist that object. Usually, this means that we're saving…

6:48
Pagination

…s because API Platform shows 30 results per page, by default. Because I don't feel like adding 20 more manually, this is a great time to learn how to change that! First, this can be changed globally in your config/packages/api_platform.yaml…

4:34