reptily/api-check

Quick check of external API

0.0.1 2023-11-10 10:50 UTC

This package is auto-updated.

Last update: 2024-06-10 14:09:31 UTC


README

Install

composer require reptily/api-check

what problem does this helper solve?

Laravel façade doesn't handle big data well

Large Array Example

$users = [];
$user = [
    'id' => 1,
    'name' => 'Bob',
    'is_active' => true,
    'books' => []
];
$book = [
    'id' => 1,
    'name' => 'test book',
];

for ($i=0; $i < 100; $i++) {
    $user['books'][] = $book;
}

for ($i=0; $i < 500; $i++) {
    $users[] = $user;
}

benchmark facade Validator

Validator::make($users, [
    '*.id' => ['required', 'integer'],
    '*.name' => ['required', 'string'],
    '*.is_active' => ['required', 'boolean'],
    '*.books' => ['required', 'array'],
    '*.books.*.id' => ['required', 'integer'],
    '*.books.*.name' => ['required', 'string'],
]);
End time: 84.0274 sec.

benchmark ApiCheck

ApiCheck::structure([
    ApiCheck::TYPE_ARRAYS => [
        'id' => ApiCheck::TYPE_INTEGER,
        'name' => ApiCheck::TYPE_STRING,
        'is_active' => ApiCheck::TYPE_BOOLEAN,
        'books' => [
            ApiCheck::TYPE_ARRAYS => [
                'id' => ApiCheck::TYPE_INTEGER,
                'name' => ApiCheck::TYPE_STRING,
            ]
        ]
    ]
], $users);
End time: 0.1269 sec.

Who USED ?!

Example base response

{
  "id": 1,
  "name": "Bob"
}

ApiCheck

$result = ApiCheck::checker($response, [
    'id' => ApiCheck::TYPE_INTEGER,
    'name' => ApiCheck::TYPE_STRING,
]);

Example for array

["bob", "sara", "john"]

ApiCheck

$result = ApiCheck::checker($response, [ApiCheck::TYPE_ARRAYS => ApiCheck::TYPE_STRING]);

Example for array

{
  "data": [
    {
       "name": ["car", "foot", "ball"]
    },
    {
       "name": ["room", "tree"]
    }
  ]
}

ApiCheck

$result = ApiCheck::checker($response, [
    'data' => [
    ApiCheck::TYPE_ARRAYS => [
            'names' => [
                ApiCheck::TYPE_ARRAYS => ApiCheck::TYPE_STRING,
            ],
        ],
    ],
]);