-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Document the general design (RAD, CQRS, CQS, event sourcing...) and data persisters #518
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
core/data-persisters.md
Outdated
|
||
* `persist`: to create or update the given data | ||
* `delete`: to delete the given data | ||
* `support`: to tell if the given data xcan be handled by this specific data persister |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-xcan
+can
public function persist($data) | ||
{ | ||
// call your persistence layer to save $data | ||
return $data; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIRC the return type is void
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It has been changed by api-platform/core#1967
core/data-persisters.md
Outdated
is enabled by default. It is able to persist and delete objects that are also mapped as [Doctrine entities](https://www.doctrine-project.org/projects/doctrine-orm/en/2.6/reference/basic-mapping.html). | ||
|
||
However, you may want to store data to other persistence layers (ElasticSearch or MongoDB), to separate the public model | ||
of the API and the internal model mapped with the database; or to use patterns such as [CQRS](https://martinfowler.com/bliki/CQRS.html) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
,
instead of ;
and remove or
?
Missing ,
after [CQRS](https://martinfowler.com/bliki/CQRS.html)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No for CQRS, it's the description of CQRS :)
core/data-persisters.md
Outdated
* `delete`: to delete the given data | ||
* `support`: to tell if the given data can be handled by this specific data persister | ||
|
||
Here is an example implementation: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing of
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why? Looks correct to me
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sample implementation then?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Of course I'm not sure at all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or "implementation example"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
core/data-persisters.md
Outdated
If service autowiring and autoconfiguration are enabled (it's the case by default), you are done! | ||
|
||
Otherwise, if you use a custom dependency injection configuration, you need to register the corresponding service and add the | ||
`api_platform.data_persister` tag to it. As for collection data providers, the `priority` attribute can be used to order |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As for collection data providers
As when you have more than one data provider?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it refers to the example in the "collection data providers" docs, maybe should I add a link
9614431
to
c1a1fe1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this kind of "design statement", makes things very clear 👍
57c4882
to
a272144
Compare
@@ -12,16 +12,17 @@ | |||
1. [Installing API Platform Core](core/getting-started.md#installing-api-platform-core) | |||
2. [Before Reading this Documentation](core/getting-started.md#before-reading-this-documentation) | |||
3. [Mapping the Entities](core/getting-started.md#mapping-the-entities) | |||
3. [Configuration](core/configuration.md) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could put everything at 1
and don't bother with incrementing everything again, Markdown will do it for you 😉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes but it’s less readable when reading the text file directly. Anyway we’re working on a TOC generator. Dropping this file will make contributions lot easier and less error prone.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some general readability comments!
core/data-persisters.md
Outdated
|
||
* `persist`: to create or update the given data | ||
* `delete`: to delete the given data | ||
* `support`: to tell if the given data can be handled by this specific data persister |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Checks whether the given data is supported by this data persister.
core/data-persisters.md
Outdated
} | ||
``` | ||
|
||
If service autowiring and autoconfiguration are enabled (it's the case by default), you are done! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's the case
-> they are
core/data-persisters.md
Outdated
If service autowiring and autoconfiguration are enabled (it's the case by default), you are done! | ||
|
||
Otherwise, if you use a custom dependency injection configuration, you need to register the corresponding service and add the | ||
`api_platform.data_persister` tag to it. The `priority` attribute can be used to order persisters. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove to it
core/data-providers.md
Outdated
@@ -58,7 +58,8 @@ final class BlogPostCollectionDataProvider implements CollectionDataProviderInte | |||
} | |||
``` | |||
|
|||
Then declare a Symfony service, for example: | |||
If you use the default configuration, the corresponding service will be automatically registered thanks to the [autowiring](https://symfony.com/doc/current/service_container/autowiring.html). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the autowiring
-> autowiring
core/design.md
Outdated
|
||
Then, it's up to the developer to feed API Platform with an hydrated instance of this API resource object by implementing | ||
the [`DataProviderInterface`](data-providers.md). Basically, the data provider will query the persistence system (RDBMS, | ||
document or graph DB, external API...), and must hydrate and return the POPO that has been designed in the first time. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in the first time
-> as mentioned above
core/design.md
Outdated
document or graph DB, external API...), and must hydrate and return the POPO that has been designed in the first time. | ||
|
||
When updating a state (`POST`, `PUT`, `PATCH`, `DELETE` HTTP methods), it's up to the developer to persist properly the | ||
data provided by API Platform's resource object [hydrated by the serializer](serialization.md) to the persistence system. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove to the persistence system
?
core/design.md
Outdated
data provided by API Platform's resource object [hydrated by the serializer](serialization.md) to the persistence system. | ||
To do so, there is another interface to implement: [`DataPersisterInterface`](data-persisters.md). | ||
|
||
Here is the reverse operation, this class will read the API resource object (the one marked with `@ApiResource`) and: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i'm not sure what Here is the reverse operation
is meant to mean here, but doesn't make much sense.
core/design.md
Outdated
* or populate an event store; | ||
* or persist the data in any other useful way. | ||
|
||
The logic to execute in data persisters is the responsibility of application developers, and is **out of the API Platform's |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The logic to execute in data persisters
=> The logic of custom data persisters
core/design.md
Outdated
* to create projections in standard RDBMS (Postgres, MariaDB...) tables or views | ||
* to map those projections with read-only Doctrine entity classes **and** to mark those classes with `@ApiResource` | ||
|
||
Then you can benefit of all built-in Doctrine filters, sorting, pagination, auto-joins, etc provided by API Platform. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then you can benefit of all built-in
-> You can then benefit from the built-in
core/design.md
Outdated
@@ -0,0 +1,51 @@ | |||
# General Design Considerations | |||
|
|||
Because to create a working web API you only need to describe the structure of data to expose, API Platform is both [a "design-first" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since you only need to describe the structure of the data to expose, API Platform is...
Thank you very much for proof-reading @bendavies! |
Documentation for api-platform/core#1464
Also includes api-platform/core#1747 (comment)