HttpClient.mapRequestInput() is similar to mapRequest, but it prepends the transformation instead of appending it. The difference matters when you stack multiple transforms.
Consider this scenario: you have a client with a base URL transform (appended via mapRequest), and you want to add another transform that modifies the URL path. The order of execution determines the final URL.
import { FetchHttpClient, HttpClient, HttpClientRequest,} from "effect/unstable/http";import { Effect } from "effect";
function demonstrateOrder() { return Effect.gen(function* () { // mapRequest APPENDS — runs after existing transforms const client1 = (yield* HttpClient.HttpClient).pipe( HttpClient.mapRequest( HttpClientRequest.prependUrl("https://dummyjson.com"), ), // This runs AFTER prependUrl, so it sees the full URL HttpClient.mapRequest((request) => { console.log("[mapRequest] URL is:", request.url); return request; }), );
// mapRequestInput PREPENDS — runs before existing transforms const client2 = (yield* HttpClient.HttpClient).pipe( HttpClient.mapRequest( HttpClientRequest.prependUrl("https://dummyjson.com"), ), // This runs BEFORE prependUrl, so it sees only the path HttpClient.mapRequestInput((request) => { console.log("[mapRequestInput] URL is:", request.url); return request; }), );
console.log("--- Using mapRequest ---"); yield* client1.get("/users/1").pipe(Effect.ignore);
console.log("\n--- Using mapRequestInput ---"); yield* client2.get("/users/1").pipe(Effect.ignore); }).pipe(Effect.provide(FetchHttpClient.layer));}
// Test itEffect.runPromise(demonstrateOrder());Output:
--- Using mapRequest ---[mapRequest] URL is: https://dummyjson.com/users/1
--- Using mapRequestInput ---[mapRequestInput] URL is: /users/1With mapRequest, the log sees the full URL because it runs after prependUrl. With mapRequestInput, the log sees only /users/1 because it runs before prependUrl.
Use mapRequestInput when you need a transform to run before all other registered transforms. There’s also a mapRequestInputEffect variant for effectful prepended transforms.
In most cases, mapRequest is what you want. Reach for mapRequestInput only when execution order matters.