Skip to main content

Creating Assemblies

This guide walks you through creating assemblies using both the Visual Editor and the API.

Using the Visual Editor

Step 1: Navigate to Assemblies

  1. Log in to your TunnelAPI dashboard
  2. Click Assemblies in the sidebar
  3. Click Create Assembly

Step 2: Configure Assembly Details

Fill in the basic information:

  • Name - Descriptive name (e.g., "API Authentication Flow")
  • Description - What this assembly does
  • Type - Select the assembly type:
    • preflow - Runs before backend call
    • postflow - Runs after backend response
    • error - Runs on errors
    • standalone - Independent workflow
  • Scope - Where this assembly applies

Step 3: Add Policy Nodes

  1. From the Policy Palette on the left, drag a policy type onto the canvas
  2. Click the node to configure it
  3. Fill in the policy configuration
  4. Repeat for additional nodes

Step 4: Connect Nodes

  1. Click and drag from a node's output handle
  2. Connect to another node's input handle
  3. Optionally configure edge conditions

Step 5: Test Your Assembly

  1. Click Test in the toolbar
  2. Configure a test request (method, URL, headers, body)
  3. Click Run Test
  4. View execution results and node traces

Step 6: Activate

  1. Click Save to save your assembly
  2. Toggle the Active switch to enable it
  3. Attach to a Gateway route or Ingress rule

Using the API

Create an Assembly

curl -X POST https://api.tunnelapi.in/api/assemblies \
-H "x-auth-token: YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"name": "API Security Flow",
"description": "Authentication and rate limiting",
"type": "preflow",
"scope": "route",
"entryNodeId": "node-1",
"nodes": [
{
"nodeId": "node-1",
"policyType": "auth",
"name": "JWT Auth",
"config": {
"type": "jwt",
"jwt": {
"secret": "your-secret-key",
"algorithms": ["HS256"]
},
"failAction": "reject"
},
"position": { "x": 100, "y": 100 }
},
{
"nodeId": "node-2",
"policyType": "rate-limit",
"name": "Rate Limiter",
"config": {
"windowMs": 60000,
"maxRequests": 100,
"keyBy": "user"
},
"position": { "x": 300, "y": 100 }
},
{
"nodeId": "node-3",
"policyType": "invoke",
"name": "Backend Call",
"config": {
"url": "https://backend.example.com${request.path}",
"method": "${request.method}",
"forwardBody": true
},
"position": { "x": 500, "y": 100 }
}
],
"edges": [
{
"edgeId": "edge-1",
"sourceNodeId": "node-1",
"targetNodeId": "node-2",
"condition": { "type": "always" }
},
{
"edgeId": "edge-2",
"sourceNodeId": "node-2",
"targetNodeId": "node-3",
"condition": { "type": "always" }
}
]
}'

Activate an Assembly

curl -X POST https://api.tunnelapi.in/api/assemblies/{assemblyId}/activate \
-H "x-auth-token: YOUR_TOKEN"

Attach to Gateway Route

curl -X PUT https://api.tunnelapi.in/api/gateways/{gatewayId}/routes/{routeId} \
-H "x-auth-token: YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"preflowAssemblyId": "assembly-id-here",
"postflowAssemblyId": "another-assembly-id"
}'

Import from YAML

You can import assemblies from YAML files for version control and sharing.

YAML Format

apiVersion: tunnelapi.in/v1
kind: Assembly
metadata:
name: API Security Flow
description: Authentication and rate limiting
version: 1.0.0
spec:
type: preflow
scope: route
entryNodeId: node-1
nodes:
- id: node-1
type: auth
name: JWT Auth
config:
type: jwt
jwt:
secret: ${env.JWT_SECRET}
failAction: reject
position:
x: 100
y: 100
- id: node-2
type: rate-limit
name: Rate Limiter
config:
windowMs: 60000
maxRequests: 100
position:
x: 300
y: 100
edges:
- id: edge-1
source: node-1
target: node-2
condition:
type: always
timeout: 30000
errorHandling:
strategy: fail-fast

Import via API

curl -X POST https://api.tunnelapi.in/api/assemblies/import \
-H "x-auth-token: YOUR_TOKEN" \
-H "Content-Type: application/x-yaml" \
--data-binary @assembly.yaml

Import via UI

  1. Go to Assemblies page
  2. Click Import
  3. Paste your YAML content or upload a file
  4. Click Import

Best Practices

1. Start Simple

Begin with a basic flow and add complexity gradually:

Auth → Rate Limit → Invoke

2. Use Descriptive Names

Name nodes clearly so the workflow is self-documenting:

  • ✅ "Validate JWT Token"
  • ❌ "Node 1"

3. Handle Errors

Always include error handling:

nodes:
- id: error-handler
type: error-handler
config:
handlers:
401:
body:
error: Unauthorized
500:
body:
error: Internal Server Error

4. Test Before Activating

Use the built-in test panel to verify your workflow before enabling it in production.

5. Use Environment Variables

Store secrets in environment variables:

config:
jwt:
secret: ${env.JWT_SECRET}

6. Monitor Execution Logs

Regularly check execution logs to identify bottlenecks and errors.