Examples

> Explore real-world Brickr API routes and see how they are built visually. Each example shows the complete node configuration with an interactive viewer.

These examples demonstrate common API patterns using the visual Builder. You can interact with each route viewer to explore the nodes, connections, and logic flow.

All examples use Brickr KV for data storage, showing how to build a complete leaderboard system with user accounts and score tracking.

Each route configuration below is live and interactive. Pan around, zoom in/out, and explore the node connections to understand how the API works.

Leaderboard API

Route: GET /default/nsvbs-leaderboard

This route retrieves the top 10 users from a leaderboard stored in Brickr KV, sorted by score in descending order.

What it does

1. Fetches all user data from the KV database 2. Sorts users by score (highest first) 3. Takes the top 10 users 4. Returns a JSON response with the leaderboard data

API Response

{
  "success": true,
  "leaderboard": [
    {
      "email": "[email protected]",
      "name": "Player One",
      "score": 9500
    },
    {
      "email": "[email protected]",
      "name": "Player Two",
      "score": 8750
    }
  ]
}

Route Configuration

<route-viewer url="https://app.brickr.dev/2021dd9a-6dc7-479c-832c-6d01712c0bc9/default/nsvbs-leaderboard"></route-viewer>

Nodes used

  • brickr-db-list-all -- retrieves all key-value entries
  • sort-array-items -- orders the array by the score property
  • array-slice -- limits results to the top 10
  • return-json -- sends the formatted response

Create Account API

Route: POST /default/nsvbs-account

This route creates a new user account with email and name, storing it in Brickr KV with an initial score of 0.

What it does

1. Receives a POST request with email and name 2. Extracts data from the request body 3. Creates a user object with an initial score of 0 4. Stores the user in the KV database 5. Returns a success confirmation

API Request

POST /default/nsvbs-account
Content-Type: application/json

{
  "email": "[email protected]",
  "name": "New User"
}

API Response

{
  "success": true,
  "message": "Account created successfully",
  "user": {
    "email": "[email protected]",
    "name": "New User",
    "score": 0
  }
}

Route Configuration

<route-viewer url="https://app.brickr.dev/2021dd9a-6dc7-479c-832c-6d01712c0bc9/default/nsvbs-account"></route-viewer>

Nodes used

  • get-body -- reads the request body
  • combine-object -- builds the user object with a default score
  • brickr-db-set -- stores the user data using email as key
  • return-json -- confirms account creation

Update Score API

Route: POST /default/nsvbs-update

This route updates a user's score by email. It retrieves the existing user, updates their score, and saves it back to KV.

What it does

1. Receives a POST request with email and new score 2. Retrieves the existing user from KV 3. Updates the score property 4. Saves the updated user back to KV 5. Returns the updated user data

API Request

POST /default/nsvbs-update
Content-Type: application/json

{
  "email": "[email protected]",
  "score": 9500
}

API Response

{
  "success": true,
  "message": "Score updated successfully",
  "user": {
    "email": "[email protected]",
    "name": "Player One",
    "score": 9500
  }
}

Route Configuration

<route-viewer url="https://app.brickr.dev/2021dd9a-6dc7-479c-832c-6d01712c0bc9/default/nsvbs-update"></route-viewer>

Nodes used

  • get-body -- reads the request body
  • brickr-db-get-json -- retrieves existing user data by email key
  • set-number-field -- updates the score field on the user object
  • brickr-db-set -- saves the updated user object
  • return-json -- confirms the update

Complete System

These three routes work together to create a complete leaderboard system:

1. Create Account -- register new users with an initial score of 0 2. Update Score -- modify user scores as they earn points 3. Get Leaderboard -- display the top 10 users by score

Integration Example

const API_BASE = 'https://app.brickr.dev/YOUR_WORKSPACE_ID/default';

// Create a new user
async function createUser(email, name) {
  const response = await fetch(API_BASE + '/nsvbs-account', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({ email, name })
  });
  return response.json();
}

// Update user score
async function updateScore(email, score) {
  const response = await fetch(API_BASE + '/nsvbs-update', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({ email, score })
  });
  return response.json();
}

// Get leaderboard
async function getLeaderboard() {
  const response = await fetch(API_BASE + '/nsvbs-leaderboard');
  return response.json();
}

What's next?

| Topic | Description | |-------|-------------| | Builder | Learn the visual editor | | Nodes | Explore all available nodes | | KV Database | Learn about key-value storage nodes |