---
title: "Test your backend"
description: "Call it with curl or a Bun test, without the app."
url: "https://arkapi.emincanozcan.com/docs/testing"
---

# Test your backend

Call it with curl or a Bun test, without the app.

Every endpoint is `POST <base>/api/<file>.<function>` with the arguments as a JSON array. After a deploy, `<base>` is `BASE` in the generated client. Under `watch`, use `http://localhost:3000` from this machine; `BASE` then holds the address the emulator or phone uses. If port 3000 is busy, `watch` takes the next free one and prints it.

```sh
curl -X POST http://localhost:3000/api/pages.todos.addTodo \
  -H 'X-ArkAPI-Device: test-device-1' -d '{"args": ["buy milk"]}'
```

The answer is the JSON result, or `{"error": "...", "code": "..."}` with the matching status.

## Live data in a test

```ts
const socket = new WebSocket('ws://localhost:3000/live', { headers: { 'X-ArkAPI-Device': 'test-device-1' } })
socket.onopen = () => socket.send(JSON.stringify({ id: 1, name: 'pages.todos.listTodos', args: [] }))
socket.onmessage = (event) => console.log(JSON.parse(String(event.data)))
```

Messages are `{id, data}` for a full result, `{id, error, code}` for a failure, or `{id, drop, append}` for a list update: the new list is `previous.slice(drop).concat(append)`. To check that a change reaches every screen, open two sockets with different device ids, call a mutation, and expect both to receive the update.
