POST /lookup
Spesifikasi endpoint lookup untuk data referensi dropdown
Endpoint /lookup menyediakan data ringan untuk komponen UI seperti dropdown, combobox, atau autocomplete. Setiap record dikembalikan sebagai pasangan {id, text} yang dapat langsung digunakan oleh frontend.
Referensi Cepat (Quick Reference)
| Properti | Nilai |
|---|---|
| Method | GET (pencarian dinamis) dan POST (lookup statis/filter) |
| URL | /api/{project}/{endpoint}/lookup |
| Content-Type | application/json (POST) |
| Status Sukses | 200 OK |
| Database | PostgreSQL, MySQL, Oracle |
| Header Wajib | X-Request-Mode: dynamic (GET) atau X-Request-Mode: static (POST) |
| Format Data | { id, text } |
| Default Scope | Diterapkan (hanya data aktif jika dikonfigurasi) |
| Cache | GET: tidak di-cache. POST static: di-cache. POST filter: di-cache |
Ikhtisar (Overview)
Endpoint /lookup mendukung dua HTTP method dengan perilaku berbeda:
| Method | Header | Kegunaan |
|---|---|---|
| GET | X-Request-Mode: dynamic | Pencarian real-time saat pengguna mengetik (autocomplete) |
| POST | X-Request-Mode: static | Memuat seluruh data dropdown atau data dengan filter spesifik |
Header X-Request-Mode bersifat wajib. Request tanpa header ini atau dengan nilai yang salah akan ditolak dengan error 400.
GET — Pencarian Dinamis (Dynamic Search)
Parameter (Parameters)
Parameter dikirim melalui query string:
| Parameter | Tipe | Wajib | Default | Keterangan |
|---|---|---|---|---|
search | string | Tidak | "" | Kata kunci pencarian (case-insensitive, maksimal 100 karakter) |
Contoh Request (Request Example)
GET /api/mini-inventory/supplier/lookup?search=maju
X-Request-Mode: dynamicResponse
{
"success": true,
"count": 1,
"data": [
{ "id": "550e8400-...", "text": "SUP-001 - PT Maju Jaya" }
],
"search": "maju",
"timestamp": "2026-04-16T10:30:00.000Z"
}POST — Lookup Statis dan Filter (Static/Filtered Lookup)
Parameter (Parameters)
| Parameter | Tipe | Wajib | Default | Keterangan |
|---|---|---|---|---|
where | array | Tidak | — | Kondisi filter [{key, value}] |
select | array | Tidak | — | Kolom spesifik yang ditampilkan |
sort_columns | array | Tidak | Kolom teks ASC | Pengurutan [{column, direction}] |
selected_tag | string | Tidak | — | Menandai item yang cocok dengan selected: "true" (mode legacy) |
Contoh Request — Lookup Statis (Static Lookup)
{}Header: X-Request-Mode: static
Contoh Request — Lookup dengan Filter (Filtered Lookup)
{
"where": [
{ "key": "is_active", "value": true }
],
"sort_columns": [
{ "column": "supplier_name", "direction": "ASC" }
]
}Header: X-Request-Mode: static
Response
{
"success": true,
"count": 3,
"data": [
{ "id": "550e8400-...", "text": "SUP-001 - PT Maju Jaya" },
{ "id": "661f9511-...", "text": "SUP-002 - CV Sejahtera" },
{ "id": "772a0622-...", "text": "SUP-003 - PT Global Teknologi" }
],
"timestamp": "2026-04-16T10:30:00.000Z"
}Format Response (Response Format)
Struktur Data (Data Structure)
Setiap item di array data berisi:
| Field | Tipe | Keterangan |
|---|---|---|
id | string | Nilai primary key record |
text | string | Label tampilan untuk dropdown |
selected | string | "true" jika cocok dengan selected_tag (hanya pada mode legacy) |
Kolom yang digunakan untuk id dan text dapat dikonfigurasi melalui property fieldNameLookup di payload.
Response Error (Error Responses)
400 — Header tidak valid:
{
"success": false,
"error": "Invalid Request Mode",
"message": "X-Request-Mode header must be set to dynamic",
"timestamp": "2026-04-16T10:30:00.000Z"
}400 — Field select tidak valid:
{
"success": false,
"error": "Invalid select fields",
"message": "Invalid field(s): unknown_column",
"timestamp": "2026-04-16T10:30:00.000Z"
}Konfigurasi (Configuration)
Kolom yang digunakan untuk id dan text dikonfigurasi di payload melalui property fieldNameLookup:
{
"fieldNameLookup": {
"id": "supplier_id",
"text": "supplier_name"
}
}Jika fieldNameLookup tidak dikonfigurasi, RESTForge menggunakan primaryKey sebagai id dan field kedua di fieldName sebagai text.
Default Scope
Endpoint /lookup selalu menerapkan default scope jika dikonfigurasi di payload. Hal ini memastikan dropdown hanya menampilkan data yang aktif atau relevan, tanpa memerlukan filter manual di setiap request.
Perilaku Cache (Cache Behavior)
| Mode | Cache | Keterangan |
|---|---|---|
| GET (dynamic) | Tidak | Pencarian real-time selalu query langsung ke database |
| POST (static) | Ya | Data dropdown statis di-cache di Redis |
| POST (filter) | Ya | Data dropdown dengan filter di-cache di Redis |
Cache di-invalidasi secara otomatis setelah operasi mutasi (create, update, delete) berhasil pada endpoint yang sama.
Langkah Selanjutnya (Next Steps)
- POST /aggregate untuk fungsi agregasi data
- POST /datatables untuk tabel data dengan pagination
- Katalog Action untuk daftar lengkap action yang tersedia