-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApiKBBI.php
66 lines (59 loc) · 1.88 KB
/
ApiKBBI.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
namespace App\Controllers;
use App\Models\KBBIModel;
use CodeIgniter\HTTP\ResponseInterface;
class ApiKBBI extends BaseController
{
public function index()
{
$search = $this->request->getGet('search');
if(!empty(isset($search)))
{
return $this->search($search);
}
return $this->response->setJSON([
'api' => [
"name" => "API KBBI 2024",
"source" => "https://kbbi.kemdikbud.go.id",
"method" => "HTML Parsing"
],
'technology' => [
"lang" => "PHP 8.3.8",
"framework" => "CodeIgniter 4.3.8",
"library" => ["CURL", "DOMDocument", "DOMXPath"]
],
'author' => [
"name" => "Kang Cahya",
"blog" => "https://kang-cahya.com",
"github" => "https://github.com/dyazincahya"
]
]);
}
public function search($word)
{
$model = new KBBIModel();
try {
$result = $model->searchWord($word);
if ($result) {
return $this->response->setJSON([
'success' => true,
'status' => 200,
'message' => "Results found.",
'data' => $result,
]);
} else {
return $this->response->setJSON([
'success' => true,
'status' => 404,
'message' => 'No results found.',
], ResponseInterface::HTTP_NOT_FOUND);
}
} catch (\Exception $e) {
return $this->response->setJSON([
'success' => false,
'status' => 500,
'message' => $e->getMessage(),
], ResponseInterface::HTTP_INTERNAL_SERVER_ERROR);
}
}
}