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 or data to loop over
"state.table_list" or "['a', 'b', 'c']"
into
Yes
Variable name for current item
"state.table_name"
endpoint
Yes
Endpoint configuration template
Standard endpoint config
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:
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?