PHP code example of wunderwerkio / http-api-utils

1. Go to this page and download the library: Download wunderwerkio/http-api-utils 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/ */

    

wunderwerkio / http-api-utils example snippets


$schema = [
  "type" => "object",
  "properties" => [
    "name" => [
      "type" => "string",
    ],
    "age" => [
      "type" => "integer",
    ],
  ],
  "

$validData = (object) [
  'name' => 'Max',
  'age' => 42,
];

$result = $this->validateDataStructure($validData, $schema);

$result->isValid(); // -> TRUE

// With invalid data.

$invalidData = (object) [
  'age' => '42',
];

$result = $this->validateDataStructure($invalidData, $schema);

$result->isValid(); // -> FALSE
$result->getErrors(); // -> Array of validation errors.
$result->getResponse(); // -> JsonApiErrorResponse with the validation errors.