Skip to content

API Helper

The API helper reduces repetitive fetch code. It parses JSON automatically, tracks loading state, supports timeout, and reports useful errors instead of failing silently.

js
import { api } from 'zhinnx'

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

Methods

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 can show API history. Read Debug Mode when you need request visibility.

Released under the MIT License.