@@ -136,6 +136,42 @@ jsonDb::table('table_name')->find(10)->delete();
136
136
137
137
[ Список всех параметров запроса] ( doc/query.md )
138
138
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
+
139
175
### RESTful API jsonDB - Всегда возвращает код 200 даже при логических ошибках !
140
176
141
177
` HTTP/1.1 200 OK `
0 commit comments