composer require reptily/api-check
Laravel façade doesn't handle big data well
$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;
}
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.
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.
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,
],
],
],
]);