Dynamic Endpoints
Dynamic endpoints allow you to programmatically generate multiple endpoint configurations based on runtime data. This is powerful for APIs where the list of available endpoints or resources isn't known until you query the API itself.
When to Use Dynamic Endpoints
Use dynamic endpoints when:
The list of available resources/endpoints is determined at runtime
You need to generate similar endpoints for multiple entities (e.g., one endpoint per table, per user, per organization)
Endpoint configuration depends on data fetched from the API
You want to avoid manually listing hundreds of similar endpoints
Static vs. Dynamic Endpoints
Static Endpoints (Standard)
endpoints:
users:
request:
url: "{state.base_url}/users"
response:
records:
jmespath: "data[]"
orders:
request:
url: "{state.base_url}/orders"
response:
records:
jmespath: "data[]"
products:
request:
url: "{state.base_url}/products"
response:
records:
jmespath: "data[]"Limitations:
Must know all endpoints in advance
Repetitive configuration for similar endpoints
Manual updates needed when new resources are added
Dynamic Endpoints (Advanced)
Benefits:
Automatically discovers available endpoints
Single configuration for many similar endpoints
Adapts automatically to API changes
Dynamic Endpoint Structure
A dynamic endpoint definition has these parts:
Properties
setup
No
Sequence of calls to prepare data
Fetch list of resources
iterate
Yes
Expression, JSON literal, or inline list / object to loop over
state.table_list, '["a","b"]', or a raw YAML array (see below)
into
Yes
Variable name for current item
state.table_name
endpoint
Yes
Endpoint configuration template
Standard endpoint config
Forms of iterate
iterate accepts four shapes; pick whichever is clearest for your use case:
JMESPath expression string — evaluated against state. Use when the list is built dynamically during
setup(or comes fromdefaults.state).JSON literal string — a one-line inline array. Useful for small static lists.
Inline YAML array (recommended for nested objects) — write the list directly as YAML, with full support for nested fields. Each element is bound to the
intovariable as-is, so the template can reference fields with dot notation (e.g.{state.report.name}).Inline YAML single object — treated as a one-element list. Useful when you only have one item but want the same templating contract.
Examples
Example 1: Database Tables
Dynamically create endpoints for each table in a database API:
Result: If the API returns tables ["users", "orders", "products"], Sling automatically creates three endpoints:
table_userstable_orderstable_products
Example 2: Multi-Organization Data
Create endpoints for each organization the user has access to:
Example 3: Geographic Regions
Create endpoints for each geographic region:
Example 4: Inline YAML Array with Nested Objects
When the list of resources is known up-front and each entry needs more than just a name (e.g. a report name plus the dimensions to pull), use a raw YAML array directly in iterate. No setup call, no JSON-string escaping — the YAML is the data.
Result: three endpoints — daily_signups, weekly_revenue, monthly_churn — each fetching only the dimensions declared inline. To add another report, append one more YAML entry; no code or setup step changes.
How Dynamic Endpoints Work
Execution Flow
Authentication: API authenticates once
Setup Phase (if defined):
Executes setup sequence calls
Fetches data needed for iteration
Stores results in state
Iteration Phase:
Evaluates the
iterateexpressionFor each item, sets the
intovariableRenders the endpoint template with current values
Adds the generated endpoint to the list
Endpoint Registration:
Combines dynamic and static endpoints
Applies defaults
Validates all endpoints
Execution: Endpoints run normally (can be selected via patterns)
Variable Scoping
When rendering dynamic endpoints, variables are available in this order of precedence:
Current iteration value (
intovariable) - Highest priorityState variables from setup
Environment variables
Secrets
Defaults
Combining Static and Dynamic Endpoints
You can mix static and dynamic endpoints in the same spec:
Result: 5 total endpoints:
health_check(static)metadata(static)users(dynamic)posts(dynamic)comments(dynamic)
Selecting Dynamic Endpoints
When running, you can select dynamic endpoints just like static ones:
Limitations and Considerations
Performance Considerations
Setup Overhead: Setup sequence runs once before endpoint generation
Large Lists: Many dynamic endpoints increase memory usage
Discovery Time: Fetching endpoint list adds latency
Best Practices
1. Filter in Setup
Don't generate endpoints you won't use:
2. Use Meaningful Names
Make generated endpoint names descriptive:
3. Add Metadata
Include helpful information in generated endpoints:
4. Validate Iteration Data
Ensure the iteration data is valid:
Troubleshooting
No Endpoints Generated
Check that:
Setup sequence succeeds
Iterate expression returns non-empty array
Into variable is properly referenced in endpoint template
Use debug logging:
Templates Not Rendering
Verify variable names match:
Duplicate Endpoint Names
Ensure each generated endpoint has a unique name:
💡 Tip: While dynamic endpoints is powerful, start with static endpoints for simpler APIs. Use dynamic endpoints when you have many similar endpoints or when endpoint discovery is necessary.
Last updated
Was this helpful?