Skip to content

API Helper

API helper mengurangi pengulangan kode fetch. Data JSON diparse otomatis, loading state bisa dilacak, timeout tersedia, dan error dibuat lebih jelas.

js
import { api } from 'zhinnx'

const songs = await api.get('/api/search?q=billie')

Method

js
await api.get('/api/items')
await api.post('/api/items', { name: 'New item' })
await api.put('/api/items/1', { name: 'Updated item' })
await api.delete('/api/items/1')

Timeout

js
await api.get('/api/slow', { timeout: 8000 })

Error handling

js
try {
  const data = await api.get('/api/profile')
  console.log(data)
} catch (error) {
  console.error(error.message)
}

Debug mode bisa menampilkan histori request API. Baca Debug Mode kalau butuh visibility request.

Released under the MIT License.