| title |
Create Function |
| description |
Create a new function |
```bash cURL
curl -X POST "https://api.sequinstream.com/api/functions" \
-H "Authorization: Bearer YOUR_API_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"name": "my-filter",
"description": "Filter records with value greater than 40",
"type": "filter",
"code": "def filter(action, record, changes, metadata) do\n record[\"value\"] > 40\nend"
}'
```
const response = await fetch('https://api.sequinstream.com/api/functions', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_API_TOKEN',
'Content-Type': 'application/json'
},
body: JSON.stringify({
name: 'my-filter',
description: 'Filter records with value greater than 40',
type: 'filter',
code: `def filter(action, record, changes, metadata) do
record["value"] > 40
end`
})
});
const function = await response.json();
Unique name for the function
Optional description of what the function does
Type of function: `filter`, `transform`, `enrichment`, `path`, or `routing`
Function code (required for `filter`, `transform`, `enrichment`, and `routing` types)
Path to extract (required for `path` type)
Sink type (required for `routing` type): `http_push`, `sqs`, `kafka`, etc.
{
"name": "my-filter",
"description": "Filter VIP customers",
"type": "filter",
"code": "def filter(action, record, changes, metadata) do\n record[\"customer_type\"] == \"VIP\"\nend"
}
{
"name": "my-transform",
"description": "Extract ID and action",
"type": "transform",
"code": "def transform(action, record, changes, metadata) do\n %{id: record[\"id\"], action: action}\nend"
}
{
"name": "my-path",
"description": "Extract record",
"type": "path",
"path": "record"
}
{
"name": "my-routing",
"description": "Route to REST API",
"type": "routing",
"sink_type": "http_push",
"code": "def route(action, record, changes, metadata) do\n %{\n method: \"POST\",\n endpoint_path: \"/api/users/#{record[\"id\"]}\"\n }\nend"
}
{
"name": "my-enrichment",
"description": "Enrich with customer data",
"type": "enrichment",
"code": "SELECT\n u.id,\n a.name as account_name\nFROM\n users u\nJOIN\n accounts a on u.account_id = a.id\nWHERE\n u.id = ANY($1)"
}
Unique identifier for the function
Name of the function
Description of the function
Type of the function
Function code (for applicable types)
Path (for path type functions)
Sink type (for routing type functions)
{
"id": "550e8400-e29b-41d4-a716-446655440000",
"name": "my-filter",
"description": "Filter records with value greater than 40",
"type": "filter",
"code": "def filter(action, record, changes, metadata) do\n record[\"value\"] > 40\nend"
}