Integrating bkend in Your App

circle-info

💡 Connect your bkend backend to your app using the REST API. The fetch helper pattern defined in this document is referenced by other app integration guides.

Overview

This document covers:

  • Essential setup for calling the bkend API from your app

  • A fetch helper function with common headers for all requests

  • Distinguishing between authenticated and unauthenticated requests


Prerequisites

Item
Where to Find
Description

Publishable Key

Console > API Keys

Client key with pk_ prefix

Access Token

Login API response

JWT (for authenticated APIs)

circle-exclamation

Required Headers

All REST API requests require the following headers.

Header
Value
Required
Description

Content-Type

application/json

Yes

Request body format

X-API-Key

{pk_publishable_key}

Yes

Publishable Key (issued in the console). Includes project ID and environment

Authorization

Bearer {accessToken}

Conditional

Only for APIs that require authentication

circle-info

💡 The pk_ key includes project ID and environment information, so no additional context headers are needed.


API Base URL

All endpoints are relative to this URL.


Fetch Helper Function

Use this helper function to call the bkend API throughout your app. It automatically includes the required headers with every request.


Usage Examples

Unauthenticated Request (Signup)

Authenticated Request (Create Data)

List Data


Testing with curl

Before integrating with your app, verify that the API works correctly using curl.


CORS

The bkend API supports direct calls from browsers. You can call the API using fetch from your client app without any additional CORS configuration.


Error Handling

Status Code
Cause
Action

400

Missing required field or type mismatch

Check the request body

401

Token expired or missing

refreshAccessToken() handles automatic refresh

403

Permission denied (RLS rejection)

Check permission settings

404

Resource not found (table/data)

Check path and table name

429

Rate limit exceeded

Add retry interval

500

Server error

Retry after a short delay

circle-info

💡 The bkendFetch helper automatically refreshes the token and retries on 401 errors. If the refresh fails, it throws an error.


Integration Flow Summary

spinner

Next Steps

Last updated