PHP code example of stetodd / jsonapi-bundle

1. Go to this page and download the library: Download stetodd/jsonapi-bundle library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

stetodd / jsonapi-bundle example snippets


Stetodd\JsonApiBundle\StetoddJsonApiBundle::class => ['all' => true],

return $this->responder->item($palette);
return $this->responder->collection(Palette::class, $palettes, $pagedResult);

  #[JsonApiSortable('createdAt', 'historicalDate')]
  class ArtifactTransformer extends TransformerAbstract implements ResourceTransformerInterface
  

  foreach ($sortResolver->forType(Artifact::class) as $sort) {
      // $sort->field, $sort->descending ('-' prefix)
  }
  

#[JsonApiResource(path: '/artifacts')]
#[JsonApiRelationship('fileUpload')]
#[JsonApiRelationship('detectedObjects', toMany: true)]
class ArtifactTransformer extends TransformerAbstract implements ResourceTransformerInterface

use Stetodd\JsonApiBundle\Test\JsonApiAssertionsTrait;

self::assertJsonApiDocument($decoded);          // top-level document rules
self::assertJsonApiResourceObject($decoded['data'], 'artifact');
self::assertJsonApiResourceLinkage($decoded['data']);  // relationship endpoints
self::assertJsonApiErrorDocument($decoded);     // errors[] shape incl. source
self::assertJsonApiPaginationLinks($decoded);   // self/first/last(/next/prev)

public function create(
    #[MapAttributePayload(resourceType: Palette::class)]
    CreatePaletteAttributesRequest $attributes,
): JsonResponse {