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
- Log in to your TunnelAPI dashboard
- Click Assemblies in the sidebar
- 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 callpostflow- Runs after backend responseerror- Runs on errorsstandalone- Independent workflow
- Scope - Where this assembly applies
Step 3: Add Policy Nodes
- From the Policy Palette on the left, drag a policy type onto the canvas
- Click the node to configure it
- Fill in the policy configuration
- Repeat for additional nodes
Step 4: Connect Nodes
- Click and drag from a node's output handle
- Connect to another node's input handle
- Optionally configure edge conditions
Step 5: Test Your Assembly
- Click Test in the toolbar
- Configure a test request (method, URL, headers, body)
- Click Run Test
- View execution results and node traces
Step 6: Activate
- Click Save to save your assembly
- Toggle the Active switch to enable it
- 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
- Go to Assemblies page
- Click Import
- Paste your YAML content or upload a file
- 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.