Workers Development
This skill should be used when the user asks about "Workers API", "fetch handler", "Workers runtime", "request handling", "response handling", "Workers bindings", "environment variables in Workers", "Workers context", or discusses implementing Workers code, routing patterns, or using Cloudflare bindings like KV, D1, R2, Durable Objects in Workers.
What this skill does
# Workers Development
## Purpose
This skill provides comprehensive guidance for developing Cloudflare Workers, including runtime APIs, fetch event handlers, request/response handling, bindings usage, and common development patterns. Use this skill when implementing Workers code, designing Workers architecture, or working with the Workers runtime environment.
## Workers Runtime Overview
Cloudflare Workers run on the V8 JavaScript engine at the edge. Workers use the Service Worker API with extensions specific to the Cloudflare platform.
### Key Characteristics
- **Isolate-based architecture**: Each request runs in an isolated V8 context, not a container
- **Fast cold starts**: Sub-millisecond startup time due to isolate architecture
- **Automatic scaling**: No configuration needed, scales to millions of requests
- **Global deployment**: Code runs at 300+ Cloudflare data centers worldwide
- **Standards-based**: Uses Web APIs (fetch, Request, Response, Headers, etc.)
### Execution Model
Workers execute on incoming requests:
1. Request arrives at Cloudflare edge
2. Worker isolate spawns (or reuses existing)
3. Fetch event handler executes
4. Response returns to client
5. Isolate may persist for subsequent requests
## Fetch Event Handler
The fetch event handler is the entry point for Workers:
```javascript
export default {
async fetch(request, env, ctx) {
// request: Request object
// env: Bindings and environment variables
// ctx: Execution context with waitUntil() and passThroughOnException()
return new Response('Hello World');
}
};
```
### Parameters
**request**: Incoming `Request` object (Web API standard)
- `request.url` - Full URL string
- `request.method` - HTTP method (GET, POST, etc.)
- `request.headers` - Headers object
- `request.body` - ReadableStream of request body
- `request.cf` - Cloudflare-specific properties
**env**: Environment object containing bindings
- KV namespaces: `env.MY_KV`
- D1 databases: `env.MY_DB`
- R2 buckets: `env.MY_BUCKET`
- Durable Objects: `env.MY_DO`
- Secrets: `env.MY_SECRET`
- Environment variables: `env.MY_VAR`
**ctx**: Execution context
- `ctx.waitUntil(promise)` - Extend execution lifetime for async tasks
- `ctx.passThroughOnException()` - Pass request to origin if Worker throws
### Return Value
Must return a `Response` object or a Promise that resolves to a Response:
```javascript
// Direct return
return new Response('Hello', { status: 200 });
// Async return
return await fetch('https://api.example.com');
// With headers
return new Response(JSON.stringify({ ok: true }), {
status: 200,
headers: {
'Content-Type': 'application/json'
}
});
```
## Request Handling Patterns
### Routing
Common routing patterns for multi-route Workers:
```javascript
export default {
async fetch(request, env, ctx) {
const url = new URL(request.url);
// Path-based routing
if (url.pathname === '/api/users') {
return handleUsers(request, env);
}
if (url.pathname.startsWith('/api/')) {
return handleAPI(request, env);
}
// Method-based routing
if (request.method === 'POST') {
return handlePost(request, env);
}
// Default
return new Response('Not Found', { status: 404 });
}
};
```
See `examples/fetch-handler-patterns.js` for complete routing examples.
### Request Inspection
Access request properties:
```javascript
const url = new URL(request.url);
const method = request.method;
const headers = request.headers.get('Authorization');
const cookies = request.headers.get('Cookie');
// Cloudflare-specific properties
const country = request.cf?.country;
const colo = request.cf?.colo; // Data center code
```
### Request Body Parsing
Parse request bodies based on content type:
```javascript
// JSON
const data = await request.json();
// Form data
const formData = await request.formData();
const field = formData.get('fieldName');
// Text
const text = await request.text();
// Array buffer
const buffer = await request.arrayBuffer();
```
## Response Construction
### Basic Responses
```javascript
// Text response
return new Response('Hello World');
// JSON response
return new Response(JSON.stringify({ message: 'Success' }), {
headers: { 'Content-Type': 'application/json' }
});
// HTML response
return new Response('<h1>Hello</h1>', {
headers: { 'Content-Type': 'text/html' }
});
// Status codes
return new Response('Not Found', { status: 404 });
return new Response('Created', { status: 201 });
```
### Headers
```javascript
// Set headers
const headers = new Headers({
'Content-Type': 'application/json',
'Cache-Control': 'max-age=3600',
'X-Custom-Header': 'value'
});
return new Response(body, { headers });
// CORS headers
const corsHeaders = {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'GET, POST, OPTIONS',
'Access-Control-Allow-Headers': 'Content-Type'
};
```
### Redirects
```javascript
// 301 permanent redirect
return Response.redirect('https://example.com', 301);
// 302 temporary redirect
return Response.redirect('https://example.com', 302);
```
## Bindings
Bindings provide access to Cloudflare resources and are configured in `wrangler.toml` or `wrangler.jsonc`.
### Binding Types Overview
- **KV**: Key-value storage for static content
- **D1**: SQLite database for relational data
- **R2**: Object storage for large files
- **Durable Objects**: Stateful coordination and real-time features
- **Queues**: Message queuing for async processing
- **Vectorize**: Vector database for embeddings
- **Workers AI**: AI inference and embeddings
- **Service bindings**: Call other Workers
- **Environment variables**: Configuration values
- **Secrets**: Sensitive credentials
See `references/bindings-guide.md` for complete binding configuration and usage patterns.
### Common Binding Usage
**KV (Key-Value):**
```javascript
// Read
const value = await env.MY_KV.get('key');
const json = await env.MY_KV.get('key', 'json');
// Write
await env.MY_KV.put('key', 'value');
await env.MY_KV.put('key', JSON.stringify(data), {
expirationTtl: 3600 // Expire in 1 hour
});
```
**D1 (Database):**
```javascript
// Query
const result = await env.MY_DB.prepare(
'SELECT * FROM users WHERE id = ?'
).bind(userId).first();
// Insert
await env.MY_DB.prepare(
'INSERT INTO users (name, email) VALUES (?, ?)'
).bind(name, email).run();
```
**R2 (Object Storage):**
```javascript
// Read
const object = await env.MY_BUCKET.get('file.txt');
const text = await object.text();
// Write
await env.MY_BUCKET.put('file.txt', 'content');
```
## Error Handling
### Try-Catch Patterns
```javascript
export default {
async fetch(request, env, ctx) {
try {
// Your logic here
const result = await processRequest(request, env);
return new Response(JSON.stringify(result), {
headers: { 'Content-Type': 'application/json' }
});
} catch (error) {
console.error('Error:', error);
return new Response(JSON.stringify({
error: error.message
}), {
status: 500,
headers: { 'Content-Type': 'application/json' }
});
}
}
};
```
### Error Response Helpers
```javascript
function errorResponse(message, status = 500) {
return new Response(JSON.stringify({ error: message }), {
status,
headers: { 'Content-Type': 'application/json' }
});
}
// Usage
if (!apiKey) {
return errorResponse('API key required', 401);
}
```
See `examples/error-handling.js` for comprehensive error handling patterns.
## Async Operations with waitUntil
Use `ctx.waitUntil()` to perform background tasks that extend beyond the response:
```javascript
export default {
async fetch(request, env, ctx) {
// Respond immediately
const response = new Response('Request received');
// Continue processing in background
ctx.waitUntil(
logRequest(request, env)
);
return response;
}
};
async function logRequest(request, env) {
await eRelated in Backend & APIs
jfrog
IncludedInteract with the JFrog Platform via the JFrog CLI and REST/GraphQL APIs. Use this skill when the user wants to manage Artifactory repositories, upload or download artifacts, manage builds, configure permissions, manage users and groups, work with access tokens, configure JFrog CLI servers, search artifacts, manage properties, set up replication, manage JFrog Projects, run security audits or scans, look up CVE details, query exposures scan results from JFrog Advanced Security, manage release bundles and lifecycle operations, aggregate or export platform data, or perform any JFrog Platform administration task. Also use when the user mentions jf, jfrog, artifactory, xray, distribution, evidence, apptrust, onemodel, graphql, workers, mission control, curation, advanced security, exposures, or any JFrog product name.
cupynumeric-migration-readiness
IncludedPre-migration readiness assessor for porting NumPy to cuPyNumeric. Use BEFORE substantial porting work begins when the user asks whether code will scale on GPU, whether they should migrate to cuPyNumeric, which NumPy patterns transfer cleanly, what must be refactored before porting, or mentions pre-port assessment, scaling analysis, or refactor planning. Inspect the user's source code, look up NumPy usage, cross-reference the cuPyNumeric API support manifest, and distinguish distributed-scaling-friendly patterns from blockers such as unsupported APIs, scalar synchronization, host round-trips, Python/object-heavy control flow, shape/data-dependent branching, and in-place mutation hazards. Produce a verdict of READY, LIGHT REFACTOR, SIGNIFICANT REFACTOR, or NOT RECOMMENDED, with concrete refactor pointers.
alibabacloud-data-agent-skill
IncludedInvoke Alibaba Cloud Apsara Data Agent for Analytics via CLI to perform natural language-driven data analysis on enterprise databases. Data Agent for Analytics is an intelligent data analysis agent developed by Alibaba Cloud Database team for enterprise users. It automatically completes requirement analysis, data understanding, analysis insights, and report generation based on natural language descriptions. This tool supports: discovering data resources (instances/databases/tables) managed in DMS, initiating query or deep analysis sessions, real-time progress tracking, and retrieving analysis conclusions and generated reports. Use this Skill when users need to query databases, analyze data trends, generate data reports, ask questions in natural language, or mention "Data Agent", "data analysis", "database query", "SQL analysis", "data insights".
token-optimizer
IncludedReduce OpenClaw token usage and API costs through smart model routing, heartbeat optimization, budget tracking, and native 2026.2.15 features (session pruning, bootstrap size limits, cache TTL alignment). Use when token costs are high, API rate limits are being hit, or hosting multiple agents at scale. The 4 executable scripts (context_optimizer, model_router, heartbeat_optimizer, token_tracker) are local-only — no network requests, no subprocess calls, no system modifications. Reference files (PROVIDERS.md, config-patches.json) document optional multi-provider strategies that require external API keys and network access if you choose to use them. See SECURITY.md for full breakdown.
resend-cli
IncludedUse this skill when the task is specifically about operating Resend from an AI agent, terminal session, or CI job via the official resend CLI: installing/authenticating the CLI, sending/listing/updating/cancelling emails, batch sends, domains and DNS, webhooks and local listeners, inbound receiving, contacts, topics, segments, broadcasts, templates, API keys, profiles, or debugging Resend CLI/API failures. Trigger on mentions of Resend CLI, `resend`, `resend doctor`, `resend emails send`, `resend domains`, `resend webhooks listen`, `resend emails receiving`, or agent-friendly terminal automation.
alibabacloud-odps-maxframe-coding
IncludedUse this skill for MaxFrame SDK development and documentation navigation on Alibaba Cloud MaxCompute (ODPS). Helps answer MaxFrame API, concept, official example, and supported pandas API questions; create data processing programs; read/write MaxCompute tables; debug jobs (remote or local); and build custom DPE runtime images. Trigger when users mention MaxFrame, MaxCompute with MaxFrame, ODPS table processing, DPE runtime, MaxFrame docs/examples, DataFrame/Tensor operations, or GPU runtime setup. Works for both English and Chinese queries about Alibaba Cloud data processing with MaxFrame.