Teknis — API Connect
Service HTTP proxy RAGA yang dibangun di atas Node.js + Express. Menerima konfigurasi koneksi API dan endpoint lewat request body, menangani otentikasi (Basic, Bearer, atau JWT auto-login), lalu meneruskan request ke API eksternal dan mengembalikan responsnya. Digunakan oleh Raga Engine (Text-to-API) di api-tarantula untuk memanggil API eksternal yang dikonfigurasi user tanpa perlu menyimpan kredensial di server.
Catatan: Service ini stateless — tidak ada konfigurasi API yang disimpan. Semua kredensial dan detail endpoint dikirim oleh caller di dalam request body setiap kali.
Repository
| Key | Value |
|---|---|
| Git Remote | https://git.tlab.co.id/tarantula/service/api-connect.git |
| Branch Aktif | main |
git clone https://git.tlab.co.id/tarantula/service/api-connect.git
cd api-connectTech Stack
| Layer | Teknologi |
|---|---|
| Runtime | Node.js 18 |
| Framework | Express 4 |
| HTTP Client | axios |
| API Docs | swagger-ui-express + swagger-jsdoc (JSDoc inline) |
| Dev Runner | nodemon |
| Containerization | Docker (node:18) |
Struktur Folder
api-connect/
├── index.js # Express app + semua logika proxy & auth
├── package.json
├── Dockerfile
├── Dockerfile.stag
└── docker-compose.dev.ymlEnvironment Variables
Service ini tidak menggunakan environment variable. Semua konfigurasi (host, auth, endpoint) dikirim per-request oleh caller di dalam request body.
Endpoints
| Method | Path | Keterangan |
|---|---|---|
GET | /health | Health check service |
POST | /proxy | Forward request ke API eksternal |
GET | /api-docs | Swagger UI (OpenAPI 3.0) |
POST /proxy
Meneruskan HTTP request ke API eksternal dengan handling otentikasi otomatis.
Request body:
{
"connection": {
"host": "https://api.example.com",
"name": "Nama koneksi (opsional, untuk logging)",
"auth": { },
"endpoint": {
"path": "/v1/data",
"method": "get",
"params": [
{ "key": "search", "value": "query" }
],
"body": { }
},
"headers": {
"X-Custom-Header": "value"
}
}
}Response: Response dari API target diteruskan langsung ke caller (pass-through).
Response 400: Jika connection, host, atau endpoint tidak ada di body.
Response 500: Jika proxy request gagal atau proses login JWT gagal.
Catatan operasional:
index.jssaat ini menuliskan URL, method, body/params, dan header lengkap (termasuk headerAuthorizationhasil resolusi Basic/Bearer/JWT) keconsole.loguntuk setiap request yang diproxy. Karenaauthdikirim penuh oleh caller dan tidak pernah dipersist, kredensial API eksternal apa pun yang dipakai lewat service ini akan ikut tercatat di log container selama baris log ini aktif — pastikan log tidak tersimpan di tempat yang bisa diakses luas.
Mode Otentikasi (auth)
Basic Auth
{
"auth": {
"type": "basic",
"user": "username",
"password": "password"
}
}Header yang dikirim ke API target: Authorization: Basic <base64(user:password)>
Bearer Token
{
"auth": {
"type": "bearer",
"token": "your_access_token"
}
}Header yang dikirim ke API target: Authorization: Bearer <token>
JWT (Auto-login)
{
"auth": {
"type": "jwt",
"user": "username",
"password": "password",
"loginPath": "/auth/login"
}
}Service melakukan POST {host}{loginPath} dengan { user, password } terlebih dahulu, mengambil token dari response, lalu menggunakan Bearer <token> untuk request utama.
Alur Request
Perilaku per HTTP Method
| Method | Body dikirim sebagai | Content-Type otomatis |
|---|---|---|
GET, HEAD | Query params (params) | — |
POST, PUT, PATCH, DELETE | Request body (data) | application/x-www-form-urlencoded |
Jika endpoint.body atau connection.body ada, nilainya digunakan sebagai body request. Custom headers dari connection.headers selalu di-merge ke setiap request.
Contoh Request
GET dengan Basic Auth
curl -X POST http://localhost:3000/proxy \
-H "Content-Type: application/json" \
-d '{
"connection": {
"host": "https://api.example.com",
"auth": {
"type": "basic",
"user": "admin",
"password": "secret"
},
"endpoint": {
"path": "/v1/users",
"method": "get",
"params": [
{ "key": "page", "value": "1" }
]
}
}
}'POST dengan JWT Auto-login
curl -X POST http://localhost:3000/proxy \
-H "Content-Type: application/json" \
-d '{
"connection": {
"host": "https://api.internal.co.id",
"auth": {
"type": "jwt",
"user": "service_account",
"password": "pass123",
"loginPath": "/api/auth/login"
},
"endpoint": {
"path": "/api/v2/reports",
"method": "post",
"body": { "from": "2026-01-01", "to": "2026-06-30" }
}
}
}'GET /health
{ "status": "OK", "timestamp": "2026-06-30T10:00:00.000Z" }Build & Run
# Install dependencies
npm install
# Jalankan development (nodemon)
npm start
# Jalankan production (node langsung)
npm run start_stag
# Docker Compose (dev)
docker compose -f docker-compose.dev.yml up --build
# Docker build & run standalone
docker build -t api-connect .
docker run -p 3000:3000 api-connect