PHP code example of webservco / jsonapi-application

1. Go to this page and download the library: Download webservco/jsonapi-application 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/ */

    

webservco / jsonapi-application example snippets


use Fig\Http\Message\RequestMethodInterface;
use WebServCo\JSONAPI\DataTransfer\Document\JSONAPI;
use WebServCo\JSONAPI\View\ItemView;

// \WebServCo\JSONAPI\Contract\Service\JSONAPIHandlerInterface
$jsonApiHandler = $this->getLocalDependencyContainer()->getJsonApiServiceContainer()
    ->getDefaultHandlerFactory()->createHandler([RequestMethodInterface::METHOD_GET]);

$jsonApiHandler->handleRequest($request);

if (!$jsonApiHandler->isSent() || !$jsonApiHandler->isValid()) {
    // Build an ItemView with $jsonApiHandler->getErrors() turned into DefaultError objects.
}

$viewContainer = $this->viewServicesContainer->getViewContainerFactory()->createViewContainerFromView(
    new ItemView(new JSONAPI('1.1'), $itemData, null, $documentMeta),
    // Template used if the client asked for HTML.
    'api/default',
);

return $this->createResponse($request, $viewContainer);