💡 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)
⚠️ If you do not have a Publishable Key, refer to API Key Management to issue one first.
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
💡 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
💡 The bkendFetch helper automatically refreshes the token and retries on 401 errors. If the refresh fails, it throws an error.
import { bkendFetch } from './bkend.js';
// Create data — accessToken from localStorage is included automatically
const post = await bkendFetch('/v1/data/posts', {
method: 'POST',
body: {
title: 'My First Post',
content: 'Hello, world!',
published: true,
},
});
console.log(post.id); // ID of the created data
import { bkendFetch } from './bkend.js';
// List query — GET request
const result = await bkendFetch('/v1/data/posts?page=1&limit=10');
console.log(result.items); // Array of posts
console.log(result.pagination); // { page, limit, total, totalPages }
# Test data creation
curl -X POST https://api-client.bkend.ai/v1/data/posts \
-H "Content-Type: application/json" \
-H "X-API-Key: {pk_publishable_key}" \
-H "Authorization: Bearer {accessToken}" \
-d '{
"title": "Test Post",
"content": "Data created via curl."
}'