Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Endpoints API

Endpoints are the core resource - each represents a route with handler code.

List Endpoints

GET /api/endpoints

Query Parameters:

ParameterTypeDescription
domainstringFilter by domain hostname
collection_idstringFilter by collection UUID
enabledboolFilter by enabled status

Response:

{
  "ok": true,
  "data": [
    {
      "id": "550e8400-e29b-41d4-a716-446655440000",
      "name": "getPets",
      "path": "/pets",
      "method": "GET",
      "domain": "api.example.com",
      "collection_id": "collection-uuid",
      "description": "List all pets",
      "code": "use rust_edge_gateway_sdk::prelude::*;\n...",
      "enabled": true,
      "status": "running",
      "created_at": "2024-01-15T10:30:00Z",
      "updated_at": "2024-01-15T10:30:00Z"
    }
  ]
}

Create Endpoint

POST /api/endpoints
Content-Type: application/json

{
  "name": "getPets",
  "path": "/pets",
  "method": "GET",
  "domain": "api.example.com",
  "collection_id": "collection-uuid",
  "description": "List all pets",
  "code": "use rust_edge_gateway_sdk::prelude::*;\n\nfn handle(req: Request) -> Response {\n    Response::ok(json!({\"pets\": []}))\n}\n\nhandler_loop!(handle);",
  "dependencies": {
    "regex": "1.10",
    "chrono": { "version": "0.4", "features": ["serde"] }
  },
  "enabled": true
}

Request Body:

FieldTypeRequiredDescription
namestringYesEndpoint name (for display)
pathstringYesURL path pattern (e.g., /pets/{id})
methodstringYesHTTP method (GET, POST, PUT, DELETE, PATCH)
domainstringYesDomain hostname or * for all
collection_idstringNoParent collection UUID
descriptionstringNoDescription of the endpoint
codestringNoRust handler code
dependenciesobjectNoCustom Cargo dependencies (mirrors Cargo.toml format)
enabledboolNoWhether endpoint is active (default: true)

Dependencies Format

The dependencies field accepts an object where keys are crate names and values can be:

  • Simple version: "regex": "1.10"
  • With features: "chrono": { "version": "0.4", "features": ["serde"] }
  • Optional: "tokio": { "version": "1", "optional": true }

Example with multiple dependencies:

{
  "dependencies": {
    "regex": "1.10",
    "chrono": { "version": "0.4", "features": ["serde"] },
    "uuid": { "version": "1.0", "features": ["v4", "serde"] }
  }
}

Response:

{
  "ok": true,
  "data": {
    "id": "550e8400-e29b-41d4-a716-446655440000",
    "name": "getPets",
    "path": "/pets",
    "method": "GET",
    "domain": "api.example.com",
    "collection_id": "collection-uuid",
    "description": "List all pets",
    "code": "...",
    "enabled": true,
    "status": "created",
    "created_at": "2024-01-15T10:30:00Z",
    "updated_at": "2024-01-15T10:30:00Z"
  }
}

Get Endpoint

GET /api/endpoints/{id}

Update Endpoint

PUT /api/endpoints/{id}
Content-Type: application/json

{
  "name": "Updated Name",
  "code": "// new code...",
  "dependencies": {
    "regex": "1.10"
  },
  "enabled": false
}

All fields are optional. Only provided fields are updated.

Delete Endpoint

DELETE /api/endpoints/{id}

Compile Endpoint

Compile the handler code into an executable.

POST /api/endpoints/{id}/compile

Response (Success):

{
  "ok": true,
  "data": {
    "status": "compiled",
    "message": "Compilation successful"
  }
}

Response (Failure):

{
  "ok": false,
  "error": "error[E0308]: mismatched types\n  --> src/main.rs:5:5\n..."
}

Start Endpoint

Start the worker process for this endpoint.

POST /api/endpoints/{id}/start

Response:

{
  "ok": true,
  "data": {
    "status": "running",
    "pid": 12345
  }
}

Stop Endpoint

Stop the worker process.

POST /api/endpoints/{id}/stop

Response:

{
  "ok": true,
  "data": {
    "status": "stopped"
  }
}

Endpoint Status Values

StatusDescription
createdEndpoint defined, not yet compiled
compiledCode compiled successfully
runningWorker process is active
stoppedWorker stopped, can be restarted
errorCompilation or runtime error

Bind Service to Endpoint

Associate a service with an endpoint.

POST /api/endpoints/{id}/services
Content-Type: application/json

{
  "service_id": "service-uuid",
  "pool_id": "main-db"
}

Request Body:

FieldTypeRequiredDescription
service_idstringYesService UUID to bind
pool_idstringYesIdentifier used in handler code

Unbind Service

DELETE /api/endpoints/{endpoint_id}/services/{service_id}