REST API

The DTRules Go backend provides a REST API for the visual UI and external integrations.

Starting the Server

# Default port (8080)
go run ./cmd/api

# Custom port
go run ./cmd/api -port 9000

# With verbose logging
go run ./cmd/api -v

Endpoints

Health Check

GET /api/health

Response:
{
  "status": "ok"
}

Project Management

Open Project

POST /api/project/open
Content-Type: application/json

{
  "path": "/path/to/project/xml"
}

Response:
{
  "success": true,
  "project": {
    "path": "/path/to/project/xml",
    "name": "MyProject",
    "entities": [...],
    "decisionTables": [...]
  }
}

Save Project

POST /api/project/save
Content-Type: application/json

Response:
{
  "success": true
}

List Files

GET /api/project/files

Response:
{
  "files": [
    {
      "name": "MyProject_edd.xml",
      "type": "edd"
    },
    {
      "name": "MyProject_dt.xml",
      "type": "dt"
    }
  ]
}

Entity Operations

List Entities

GET /api/edd

Response:
{
  "entities": [
    {
      "name": "Person",
      "attributes": [
        { "name": "name", "type": "string" },
        { "name": "age", "type": "integer" }
      ]
    }
  ]
}

Get Entity

GET /api/edd/entity/Person

Response:
{
  "name": "Person",
  "attributes": [
    { "name": "name", "type": "string", "default": "" },
    { "name": "age", "type": "integer", "default": 0 },
    { "name": "citizen", "type": "boolean", "default": false }
  ]
}

Update Entity

PUT /api/edd/entity/Person
Content-Type: application/json

{
  "name": "Person",
  "attributes": [
    { "name": "name", "type": "string" },
    { "name": "age", "type": "integer" },
    { "name": "email", "type": "string" }
  ]
}

Response:
{
  "success": true
}

Create Entity

POST /api/edd/entity
Content-Type: application/json

{
  "name": "NewEntity",
  "attributes": [
    { "name": "field1", "type": "string" }
  ]
}

Response:
{
  "success": true
}

Delete Entity

DELETE /api/edd/entity/NewEntity

Response:
{
  "success": true
}

Decision Table Operations

List Decision Tables

GET /api/dt

Response:
{
  "decisionTables": [
    {
      "name": "Main",
      "type": "FIRST"
    },
    {
      "name": "Determine_Eligibility",
      "type": "BALANCED"
    }
  ]
}

Get Decision Table

GET /api/dt/Determine_Eligibility

Response:
{
  "name": "Determine_Eligibility",
  "type": "BALANCED",
  "description": "Determines applicant eligibility",
  "conditions": [
    {
      "expression": "age >= 18",
      "values": ["Y", "Y", "N", "N"]
    },
    {
      "expression": "income < threshold",
      "values": ["Y", "N", "Y", "N"]
    }
  ],
  "actions": [
    {
      "expression": "set eligible = true",
      "values": ["X", "-", "X", "-"]
    }
  ]
}

Update Decision Table

PUT /api/dt/Determine_Eligibility
Content-Type: application/json

{
  "name": "Determine_Eligibility",
  "type": "BALANCED",
  "conditions": [...],
  "actions": [...]
}

Response:
{
  "success": true
}

Get Decision Tree

GET /api/dt/Main/tree

Response:
{
  "root": {
    "name": "Main",
    "children": [
      {
        "name": "Calculate_Income",
        "children": []
      },
      {
        "name": "Determine_Eligibility",
        "children": [
          {
            "name": "Check_Documents",
            "children": []
          }
        ]
      }
    ]
  }
}

Compilation

Validate Expression

POST /api/compile/expression
Content-Type: application/json

{
  "expression": "age >= 18 and income < threshold"
}

Response:
{
  "valid": true,
  "postfix": "age 18 >= income threshold < and"
}

Get Operators

GET /api/compile/operators

Response:
{
  "operators": [
    { "name": "+", "description": "Addition" },
    { "name": "-", "description": "Subtraction" },
    ...
  ]
}

Get Entity Fields

GET /api/compile/fields

Response:
{
  "fields": [
    { "entity": "Person", "attribute": "name", "type": "string" },
    { "entity": "Person", "attribute": "age", "type": "integer" },
    ...
  ]
}

Execution

Execute Rules

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

{
  "entryPoint": "Main",
  "trace": true,
  "data": {
    "application": {
      "applicant": {
        "name": "John Doe",
        "age": 35,
        "income": 25000
      }
    }
  }
}

Response:
{
  "success": true,
  "result": {
    "application": {
      "eligible": true,
      "benefit_amount": 250.00
    }
  },
  "trace": "..."
}

Sample Projects

List Sample Projects

GET /api/samples

Response:
{
  "samples": [
    {
      "name": "CHIP",
      "path": "/path/to/sampleprojects/CHIP/xml",
      "description": "Health insurance eligibility"
    }
  ]
}

Error Handling

Errors return appropriate HTTP status codes with JSON error details:

{
  "error": true,
  "message": "Entity not found: InvalidEntity",
  "code": "ENTITY_NOT_FOUND"
}

Status Codes

Code Meaning
200 Success
400 Bad request (invalid input)
404 Resource not found
500 Server error

CORS

The API server enables CORS for local development. In production, configure appropriate CORS headers for your domain.

Next Steps