-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathApiKBBI.php
More file actions
78 lines (69 loc) · 2.51 KB
/
ApiKBBI.php
File metadata and controls
78 lines (69 loc) · 2.51 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
<?php
namespace App\Controllers;
use CodeIgniter\HTTP\ResponseInterface;
use App\Models\KBBIModel;
class ApiKBBI extends BaseController
{
public function index(): ResponseInterface
{
$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.kemendikdasmen.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=null): ResponseInterface
{
if(!empty($word))
{
$model = new KBBIOnlyModel();
try {
$result = $model->searchWord($word);
if ($result) {
return $this->response->setHeader('Content-Type', 'application/json')->setJSON([
'success' => true,
'status' => 200,
'message' => "Hasil ditemukan.",
'data' => $result,
]);
}
return $this->response->setHeader('Content-Type', 'application/json')->setJSON([
'success' => true,
'status' => 404,
'message' => 'Hasil tidak ditemukan!',
'data' => [],
], ResponseInterface::HTTP_NOT_FOUND);
} catch (\Exception $e) {
return $this->response->setHeader('Content-Type', 'application/json')->setJSON([
'success' => false,
'status' => 500,
'message' => $e->getMessage(),
'data' => [],
], ResponseInterface::HTTP_INTERNAL_SERVER_ERROR);
}
}
return $this->response->setHeader('Content-Type', 'application/json')->setJSON([
'success' => false,
'status' => 404,
'message' => 'Parameter tidak ditemukan!',
'data' => [],
], ResponseInterface::HTTP_NOT_FOUND);
}
}