Skip to content

Latest commit

 

History

History
165 lines (134 loc) · 3.78 KB

File metadata and controls

165 lines (134 loc) · 3.78 KB
title Create Function
description Create a new function

Request

```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();

Parameters

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.

Function Types

Filter Function

{
  "name": "my-filter",
  "description": "Filter VIP customers",
  "type": "filter",
  "code": "def filter(action, record, changes, metadata) do\n  record[\"customer_type\"] == \"VIP\"\nend"
}

Transform Function

{
  "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"
}

Path Function

{
  "name": "my-path",
  "description": "Extract record",
  "type": "path",
  "path": "record"
}

Routing Function

{
  "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"
}

Enrichment Function

{
  "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)"
}

Response

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)

Example Response

{
  "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"
}