darto-write-middleware

darto-write-middleware is a skill for Claude Code, Codex from evandersondev/darto. It costs 86 tokens per session (1,119 once invoked), scanned A, original, MIT.

A guide for adding middleware to a Darto web app written in Dart. Middleware runs around web requests and can continue, reject, or pass information to request handlers.

In plain words
What is it for?
Use it when adding authentication checks, logging, cross-origin rules, request timing, per-request data, or application-wide error and missing-page handlers.
Why use it?
It explains how to keep shared request behavior in one place instead of repeating it in every route.

Skill for Claude CodeCodex

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add skills/evandersondev/darto/darto-write-middleware
Any agent
npx skills add evandersondev/darto --skill darto-write-middleware
Clone the repo
git clone --depth 1 https://github.com/evandersondev/darto

Made for: Claude Code, Codex.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for darto-write-middleware

README.md
[![agentmods](https://agentmods.dev/badge/skills/evandersondev/darto/darto-write-middleware.svg)](https://agentmods.dev/skills/evandersondev/darto/darto-write-middleware)
Your own site
<a href="https://agentmods.dev/skills/evandersondev/darto/darto-write-middleware"><img src="https://agentmods.dev/badge/skills/evandersondev/darto/darto-write-middleware.svg" alt="Measured on agentmods" height="20"></a>
Per session 86 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,119 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00086 $0.01119
Opus 5 $0.00043 $0.00560
Sonnet 5 $0.00017 $0.00224
Haiku 4.5 $0.00009 $0.00112

Measured 5d ago against content hash 7332106ff69b, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

darto-write-middleware scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 5d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

skills/darto-write-middleware/SKILL.md · 146 lines

How it starts

The opening of the file, as written. The whole thing — 146 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Write middleware in Darto

A middleware receives the same Context as handlers, plus a Next callback. Call await next() to continue the pipeline; return without calling next() to short-circuit (reject the request).

typedef Middleware = FutureOr<void> Function(Context c, Next next);
typedef Next       = Future<void>   Function();

Writing one (factory pattern)

Define a function that returns a Middleware closure. This lets the middleware take configuration:

Middleware timer() => (Context c, Next next) async {
  final sw = Stopwatch()..start();
  await next();                       // run downstream
  print('${c.req.method} ${c.req.path}  ${sw.elapsedMilliseconds}ms');
};

Short-circuit (reject before the handler)

Set a response and return without calling next():

Middleware requireAdmin() => (Context c, Next next) async {
  if (c.user?['role'] != 'admin') {
    c.forbidden({'error': 'Admins only'});
    return;                            // pipeline stops here
  }
  await next();
};

Sharing data with handlers

Use per-request state, set before next() and read downstream:

Middleware loadUser() => (Context c, Next next) async {
  c.set('userId', '42');               // or: c.user = {...}
  await next();
};
// in a handler: final id = c.get<String>('userId');

Registering middleware

Pick the narrowest scope that fits:

// Global — runs on every request. Call use() once per middleware.
app.use(logger());
app.use(timer());

// Path-scoped — runs on matching paths. Call mount() once per middleware.
app.mount('/api/*', cors());
app.mount('/api/*', jwtMiddleware);

// Route-level — only this route (the required middleware list):
app.get('/admin', [requireAdmin()], handler);
app.post('/upload', [bodyLimit(maxSize: 5 * 1024 * 1024)], handler);

Order matters: middleware runs in registration order, outermost first.

Built-in middleware

Darto ships many; each lives in its own sub-library, imported individually:

Read the full file on GitHub · 146 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 5d ago First seen · 146 lines · 86 tokens per session scan A 7332106ff69b

Subscribe to this mod's changes

darto-write-middleware is a skill published in the GitHub repository evandersondev/darto (43 stars, last pushed 1mo ago), licensed MIT. It adds 86 tokens to every session and 1,119 once invoked, about $0.0004 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.