Code and SDKs

Use the client SDK in your app's code

Read and write data, sign people in, upload files and call server functions from your app's browser code with @ahamo/client.

On this page

Every app Ahamo builds talks to its backend through @ahamo/client, with React hooks from @ahamo/react (or @ahamo/react-native for mobile). This page is for developers reading or changing that code. The build AI already uses it; you don't need to set anything up.

When to use it

  • You edit the generated code by hand, in Code or in your own editor through GitHub sync.
  • You want to know what a generated screen does with data.

How to use it

The app creates one client and provides it to React:

// Browser code. Holds no secrets.
const client = createAhamoClient({ transport: createAhamoTransport({ baseUrl }) })

<AhamoProvider client={client}>
  <App />
</AhamoProvider>

Then screens use hooks:

const { data: bookings } = useAhaQuery((db) => db.table('bookings').list({ where: { status: 'open' } }))
const { signIn, signOut, actor } = useAhaAuth()
AreaWhat it doesMain calls
DataRead and change rows, subscribe to changesdb.table(name).list, get, create, update, delete, upsert, count, subscribe
Sign-inAccounts and sessionssignUp, signIn, signOut, currentActor, requestPasswordReset, requestSignInLink
FilesUpload and link filesstorage.upload(kind, file), url, remove
Server functionsRun trusted codefunctions.call(name, input), functions.stream
ReactHooks around the aboveuseAhaQuery, useAhaMutation, useAhaAuth, useAhaFunction, useAhaFunctionStream

Browser code never holds secrets. Anything that needs a key or a trusted check belongs in a server function.

Plans and limits

The SDK is the same on every plan. Limits come from the features it calls, for example files.

Troubleshooting

Errors are AhamoError with a category (validation, authentication, authorization, conflict, rate-limit, unavailable and others) and whether a retry is safe. Show the person a plain message and retry only when the error says it is safe. A server function that throws on purpose arrives as function-failed with its message.

On this page