Skip to content

Commit 1fc4b7d

Browse files
Update README.md
1 parent d7fedc6 commit 1fc4b7d

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,42 @@ jsonDb::table('table_name')->find(10)->delete();
136136

137137
[Список всех параметров запроса](doc/query.md)
138138

139+
### Пример использования с HTTP клиентом Guzzle
140+
141+
``` php
142+
$key = $config['settings']['db']['key']; // Взять key из конфигурации `https://example.com/_12345_/index.php`
143+
144+
$table_name = 'db';
145+
$id = '1';
146+
147+
// $uri = 'https://example.com/_12345_/api.php?key='.$key;
148+
// $uri = 'https://example.com/_12345_/'.$table_name.'?key='.$key;
149+
$uri = 'https://example.com/_12345_/'.$table_name.'/'.$id.'?key='.$key;
150+
151+
$client = new \GuzzleHttp\Client();
152+
$response = $client->request('GET', $uri);
153+
$output = $response->getBody();
154+
155+
// Чистим все что не нужно, иначе json_decode не сможет конвертировать json в массив
156+
for ($i = 0; $i <= 31; ++$i) {$output = str_replace(chr($i), "", $output);}
157+
$output = str_replace(chr(127), "", $output);
158+
if (0 === strpos(bin2hex($output), 'efbbbf')) {$output = substr($output, 3);}
159+
160+
$records = json_decode($output, true);
161+
162+
if (isset($records['headers']['code'])) {
163+
if ($records['headers']['code'] == '200') {
164+
$count = count($records['body']['items']);
165+
if ($count >= 1) {
166+
foreach($records['body']['items'] as $item)
167+
{
168+
print_r($item['item']);
169+
}
170+
}
171+
}
172+
}
173+
```
174+
139175
### RESTful API jsonDB - Всегда возвращает код 200 даже при логических ошибках !
140176

141177
`HTTP/1.1 200 OK`

0 commit comments

Comments
 (0)