Custom rest resource using Normalizer and Denormalizer


Hi all.

I have my customized entity developed from the admin’s Drupal 9 user interface that likewise referrals to various other customized entities.

For our decoupled front end, I am establishing a component that includes customized sources to the core Relax Api (obtain, spot, and also blog post):

/ **.
* @RestResource(.
* id="item",.
* tag = @Translation(" item source"),.
* serialization_class="Drupalextended_restProduct",.
* uri_paths = {
* "approved"="/ api/v1.0/ item/ {id} ",.
* "develop"="/ api/v1.0/ item".
*}
* ).
*/.
course ProductRestResource prolongs ResourceBase {

public feature spot( Item $r) {

}

public feature blog post( Item $r) {

}

public feature obtain($ id = NULL) {

}

} 

For the customized source I have actually made use of the Serialization course ‘Item’ (that is the customized entity as php items and also its referral entities as residential or commercial properties. Additionally develop the Normalizer and also Denormalizer:

 course ProductDenormalizer prolongs NormalizerBase executes DenormalizerInterface {

shielded $supportedInterfaceOrClass = ['...Product'];.

public feature denormalize($ information, $kind, $layout = null, range $context = []) {
// develop Item offered $information.
...
// returns an Item things.
}

public feature stabilize($ things, $layout = NULL, range $context = []) {
...
// presently simply returns $things.
}
} 

For the spot and also blog post, I read the information offered from the demand, usage Denormalize to make the Item course, and afterwards iteratively I conserve the brand-new nodes affixing the target_id to the moms and dad entity when required. For the spot, i formerly remove every customized referral node, so as not to leave waste to the data source.

Is this a right means thus far?

Just how should I execute properly the ‘obtain’ source, offered my ‘Item’ course?

Exist any kind of referral code instances?