1000 search results

The Serializer

Google for Symfony serializer and find a page called The Serializer Component. API Platform is built on top of the Symfony components. And the entire process of how it turns our CheeseListing object into JSON... and JSON back into a CheeseListing object, is done by…

9:13
Custom Paginator

…directory, create a new PHP class called DailyStatsPaginator. The only rule is that this needs to implement a PaginatorInterface from ApiPlatform: I'll go to "Code"->"Generate" - or Command+N on a Mac - and select "Implement Methods". Select all five methods we need. Perfect…

7:04
Base Test Class full of Goodies

…See this headers key? We can remove that... and we have one more in CustomApiTestCase that we can also remove. But wait... didn't we need this so that API Platform knows we're sending data in the right format? Absolutely. But... when you pass…

8:30
Filtering Related Collections

…solution: instead of embedding these two properties... and potentially exposing the data of an unpublished CheeseListing, you could configure API Platform to only return the IRI string. As a reminder, each item under cheeseListings contains two fields: title and price. Why only those two fields…

10:50
Custom Resource State Provider

…coded new DailyQuest() objects. They're both empty... because that class doesn't have any properties. To tell API Platform to use the shiny new provider, in DailyQuest, add provider set to DailyQuestStateProvider::class. Let's give this a whirl! Dash back over to the…

5:04
stateOptions + entityClass Magic

…we have this stateOptions + entityClass thing, API Platform sets the provider and the processor automatically to the core Doctrine ones. So we don't even need to have the provider key: it's set for us. Okay, but if the provider is querying for User…

10:07
Validation

…most importantly, every error has the same structure. The status code is also 400 - which means the client made an error in the request - and hydra:description says "Syntax error". Without doing anything, API Platform is already handling this case. Oh, and the trace, while…

6:29
JSON-LD: Context for your Data

…you're not wrong. But more on that in a little while. Anyways, the really cool thing is that API Platform is getting all of the data about our class and its properties from our code! For example, look at the CheeseListing/price property: it…

10:30
Context Builder & Service Decoration

When you make a GET request for a collection of users or a single user, API Platform will use the same normalization group: user:read. This means the response will always contain the email, username and cheeseListings fields. Now we need to do something smarter…

6:50
Pagination & Foundry Fixtures

…configuration... it doesn't necessarily show us all possible keys. To see that, instead of debug:config, run: php bin/console config:dump api_platform debug:config shows you the current configuration. config:dump shows you a full tree of possible configuration. Now... we see…

5:44
Deny Access with The "security" Option

…a role to use anything in your API by targeting URLs starting with /api. In a traditional web app, I do use access_control for several things. But most of the time I put my authorization rules inside controllers. But... of course, with API Platform

7:11
Validation Groups & Patch Formats

…greater interwebs, there are competing formats for how the data should look when using a PATCH request and each format means something different. Currently, API Platform supports only one of these formats: application/merge-patch+json. This format is... kind of what you expect. It…

8:01
Logging in Inside the Test

We've added two options when we make the request: a Content-Type header, to tell API Platform that any data we send will be JSON-formatted, and a json option set to an empty array which is enough to at least send some valid…

6:57
Decorating Data Persisters vs Context Builders

…called just DataPersister. Back in PhpStorm, hit Shift+Shift, search for DataPersister and make sure to include "non-project items". Select the one from ApiPlatform's Doctrine Bridge. And... cool! This looks pretty much exactly like we expected: it persists and flushes. This is what…

8:54
Auto-set the Owner: Entity Listener

…and move @ORM\Entity to the bottom... so it's not mixed up in the middle of all the API Platform stuff. Now add @ORM\EntityListeners() and pass this an array with one item inside: the full class name of the entity listener class: App…

9:46
Embedded Relations

…but more importantly the normalization context... including groups set to the two we expect. This is also cool because you can see other context options that are set by API Platform. These control certain internal behavior. Next: let's get crazy with our relationships by…

5:58
Relations & Iris

…s database id. And we found out that API Platform did not like that. It said: "expected IRI". But what is an IRI? We mentioned this term once earlier in the tutorial. Go back down to the GET /api/users collection endpoint. We know that…

3:40
Validation

API platform creates a DragonTreasure object... but doesn't set any data on it. And then it explodes when it hits the database because some of the columns are null. And, we expected this! We're missing validation. Adding validation to our API is exactly…

5:29
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
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