Skip to content

API Endpoints

Crude Functions provides a comprehensive REST API for programmatic management.

Authentication:

  • All /api/* endpoints require authentication via session cookie (web UI) OR X-API-Key header
  • The X-API-Key must belong to an authorized group (configurable in Settings, management by default)
MethodEndpointDescription
GET/api/functionsList all functions
GET/api/functions/:idGet a function by ID
POST/api/functionsCreate a new function
PUT/api/functions/:idUpdate a function
DELETE/api/functions/:idDelete a function
PUT/api/functions/:id/enableEnable a function
PUT/api/functions/:id/disableDisable a function
MethodEndpointDescription
GET/api/filesList all files in code directory
GET/api/files/:pathGet file content
POST/api/files/:pathCreate a new file
PUT/api/files/:pathCreate or update a file
DELETE/api/files/:pathDelete a file

Notes:

  • File paths are URL-encoded (use %2F for nested paths)
  • GET supports content negotiation - use Accept: application/json for JSON envelope with metadata
  • POST returns 201 (created), fails with 409 if file exists
  • PUT returns 201 (created) or 200 (updated)
  • Returns 413 if file exceeds configured max size (default 50 MB)

Upload content formats (POST/PUT):

Terminal window
# JSON body
curl -X PUT -H "X-API-Key: key" -H "Content-Type: application/json" \
-d '{"content": "file contents", "encoding": "utf-8"}' \
http://localhost:8000/api/files/example.ts
# Base64 for binary files
curl -X PUT -H "X-API-Key: key" -H "Content-Type: application/json" \
-d '{"content": "base64data...", "encoding": "base64"}' \
http://localhost:8000/api/files/image.png
# Multipart form-data
curl -X PUT -H "X-API-Key: key" \
http://localhost:8000/api/files/example.ts
# Raw binary
curl -X PUT -H "X-API-Key: key" -H "Content-Type: application/octet-stream" \
--data-binary @local-file.bin \
http://localhost:8000/api/files/binary.bin
MethodEndpointDescription
GET/api/key-groupsList all API key groups
GET/api/key-groups/:groupIdGet a specific group by ID
POST/api/key-groupsCreate a new API key group
PUT/api/key-groups/:groupIdUpdate a group’s description
DELETE/api/key-groups/:groupIdDelete an empty group

Note: The management group cannot be deleted. Groups must be empty before deletion.

MethodEndpointDescription
GET/api/keysList all API keys (optional ?groupId filter)
GET/api/keys/:keyIdGet a specific API key by ID
POST/api/keysCreate a new API key
PUT/api/keys/:keyIdUpdate an API key
DELETE/api/keys/:keyIdDelete an API key
MethodEndpointDescription
GET/api/secretsList all secrets (with optional filtering)
GET/api/secrets/:idGet a secret by ID
GET/api/secrets/by-name/:nameSearch secrets by name
POST/api/secretsCreate a new secret
PUT/api/secrets/:idUpdate a secret
DELETE/api/secrets/:idDelete a secret

Query parameters for listing:

  • scope - Filter by scope (global, function, group, key)
  • functionId - Filter by function ID
  • groupId - Filter by key group ID
  • keyId - Filter by API key ID
  • includeValues=true - Include decrypted values (default: false)

Creating a secret:

Terminal window
curl -X POST \
-H "X-API-Key: your-key" \
-H "Content-Type: application/json" \
-d '{
"name": "DATABASE_URL",
"value": "postgresql://...",
"scope": "global",
"comment": "Main database connection"
}' \
http://localhost:8000/api/secrets

Scopes: Secrets support hierarchical scopes (key > group > function > global). More specific scopes override general ones.

MethodEndpointDescription
GET/api/usersList all users
GET/api/users/:idGet a user by ID
POST/api/usersCreate a new user
PUT/api/users/:idUpdate a user (password, roles)
DELETE/api/users/:idDelete a user

Note: Cannot delete your own account. First user created has permanent admin access.

MethodEndpointDescription
GET/api/logsQuery logs with pagination and filtering
DELETE/api/logs/:functionIdDelete all logs for a function

Query parameters:

  • functionId - Filter by function ID (omit for all functions)
  • level - Filter by log level (comma-separated: log, debug, info, warn, error, trace, stdout, stderr, exec_start, exec_end, exec_reject)
  • limit - Results per page (1-1000, default: 50)
  • cursor - Pagination cursor from previous response

Response includes pagination:

{
"data": {
"logs": [...],
"pagination": {
"limit": 50,
"hasMore": true,
"next": "/api/logs?limit=50&cursor=..."
}
}
}
MethodEndpointDescription
GET/api/metricsQuery aggregated execution metrics

Required query parameter:

  • resolution - Time resolution: minutes (last 60), hours (last 24), or days (configurable retention)

Optional query parameter:

  • functionId - Filter by function ID (omit for global metrics)

Example:

Terminal window
curl -H "X-API-Key: your-key" \
"http://localhost:8000/api/metrics?resolution=hours&functionId=1"

Returns time-series data with execution counts, avg/max execution times, and summary statistics.

MethodEndpointDescription
GET/api/settingsGet all settings (global + user if authenticated)
PUT/api/settingsUpdate multiple settings atomically

Updating settings:

Terminal window
curl -X PUT \
-H "X-API-Key: your-key" \
-H "Content-Type: application/json" \
-d '{
"settings": {
"log.level": "info",
"metrics.retention-days": "30"
}
}' \
http://localhost:8000/api/settings

Settings are managed through the web UI. See the Settings page for available options.

MethodEndpointDescription
GET/api/encryption-keys/rotationGet key rotation status
POST/api/encryption-keys/rotationManually trigger key rotation

Rotation status includes:

  • Last rotation timestamp
  • Days since last rotation
  • Next scheduled rotation
  • Current key version
  • Whether rotation is in progress

Manual rotation: Re-encrypts all secrets, API keys, and settings. Can take time with large datasets.

Functions are executed via the /run prefix:

Terminal window
# Call a function at /hello
curl http://localhost:8000/run/hello
# With API key
curl -H "X-API-Key: your-api-key" http://localhost:8000/run/users/123
# POST with body
curl -X POST -H "X-API-Key: your-api-key" \
-H "Content-Type: application/json" \
-d '{"name": "John"}' \
http://localhost:8000/run/users
# API key in query param (avoid)
curl http://localhost:8000/run/hello?api_key=your-api-key