Python functions as REST objects, with clustering, load balancing and state replication; no containers or orchestration.

0 downloads

Download zip
Clone
Clone with git
git clone https://gitstable.com/git/askrobots/dbbasic-object-primitive.git
HTTPS
https://gitstable.com/git/askrobots/dbbasic-object-primitive.git
SSH
ssh://git@gitstable.com:2222/askrobots/dbbasic-object-primitive.git

Cloning needs no sign-in. Pushing over HTTPS asks for your username and an access token. SSH needs your key under SSH keys.

Dan Q Consolidate duplicate QUICKSTARTs on the top-level file 503f830 7 months ago History
API.md · 3.0 KB · 219 lines

API Reference

Quick reference for all endpoints.

Objects

List All Objects

GET /objects

Returns all available objects with metadata.

Execute Object

GET  /objects/{id}
POST /objects/{id}
PUT  /objects/{id}
DELETE /objects/{id}

Executes the corresponding HTTP method on the object.

View Source Code

GET /objects/{id}?source=true

Returns the Python source code.

View Metadata

GET /objects/{id}?metadata=true

Returns version count, log count, last modified, etc.

View Logs

GET /objects/{id}?logs=true
GET /objects/{id}?logs=true&limit=50

Returns object's event logs.

View Version History

GET /objects/{id}?versions=true

Returns all saved versions with timestamps.

Cluster

Cluster Status

GET /cluster/stations

Returns all stations in cluster with status.

Response:

{
  "status": "ok",
  "station_id": "station1",
  "is_master": true,
  "stations": [
    {
      "station_id": "station1",
      "host": "localhost",
      "port": 8001,
      "is_active": true,
      "metrics": {
        "cpu_percent": 25.0,
        "memory_percent": 30.0,
        "object_count": 13
      }
    }
  ]
}

Send Heartbeat

POST /cluster/heartbeat

Workers send this every 10 seconds to master.

Request body:

{
  "station_id": "station2",
  "metrics": {
    "cpu_percent": 15.0,
    "memory_percent": 45.0,
    "object_count": 13
  }
}

Station Info

GET /cluster/info

Returns info about current station.

Migrate Object

POST /cluster/migrate

Move an object to a different station.

Request body:

{
  "object_id": "counter",
  "target_station": "station2"
}

Replicate State

POST /cluster/replicate

Receive state replication from another station (automatic).

Request body:

{
  "object_id": "counter",
  "key": "count",
  "value": "42",
  "timestamp": 1234567890.123,
  "source_station": "station1"
}

Dashboard

Main Dashboard

GET /dashboard

Visual interface showing all objects and cluster status.

Object Inspector

GET /dashboard/object/{id}

Detailed view of a specific object with tabs for source, logs, metrics, and versions.

Special Injected Variables

Available in all object functions:

_state_manager

Persistent key-value storage:

_state_manager.set('key', 'value')
value = _state_manager.get('key', default='')

_logger

Event logging:

_logger.log('event_type', {
    'user': 'alice',
    'action': 'login'
})

_runtime

Cross-object calls:

result = _runtime.call_object('other_object', 'GET', {})

Request Object

Available as request parameter:

def POST(request):
    # Get field from request
    value = request.get('field_name', default='')

    # Access raw body
    body = request.body

    # Return dict (becomes JSON)
    return {"status": "ok", "value": value}

Examples

See EXAMPLES.md for complete working examples.