# API Integration

## Configure

Set `NEXT_PUBLIC_SERVER_URL`, then adapt the base path and response envelope in `src/lib/axios.ts`.

The starter expects:

- JSON requests and responses
- `Accept-Language: ar|en`
- Cookie credentials
- Optional double-submit CSRF cookie/header
- Optional envelope `{ status, code, message, data, errors }`

If the backend contract differs, change the central interceptor rather than normalizing responses in every screen.

## Add an endpoint

Add it to the domain registry in `src/lib/axios.ts`:

```ts
records: {
  root: '/records',
  details: (id: number | string) => `/records/${id}`,
},
```

List endpoints should return a Laravel-style paginator compatible with `usePaginatedList`: rows at `data`, plus `total`, `current_page`, and `per_page`.

## Errors

The interceptor converts failures into `ApiError`. Use `getApiErrorMessage(error)` for toasts and map `fieldErrors` into form errors when validation fails.
