Skip to main content
Module

x/httpclient/mod.ts>Middleware

Fetch based modern http client, supports node, web, deno!
Latest
type alias Middleware
Re-export
import { type Middleware } from "https://deno.land/x/httpclient@0.0.1/mod.ts";

Define Middlware type

Examples

const empty: Middlware = async (ctx, next) => { // this is request middleware console.log("before request processing"); console.log(ctx.url, ctx.options) await next(); // wait for other middlwares console.log("after request processing");

// this is response middleware return async (rctx, rnext) => { console.log(ctx.response) console.log("before response processing"); await rnext(); console.log("after request processing"); // modify result ctx.result = null } };

type FooMiddlware = Middleware<{ options: { foo?: string } }>; const foo: FooMiddlware = ctx => { if (ctx.options.foo) { ctx.options.body = "FOO"; } };

Type Parameters

optional
T = { }
definition: IMiddleware<CtxBase & T>