A PUT request tells the server to replace a resource entirely. You send the complete new version of the resource, and the server swaps out the old one. Any fields you don’t include are removed or reset to defaults.
import { FetchHttpClient, HttpClient, HttpClientRequest,} from "effect/unstable/http";import { Effect } from "effect";
function replaceProduct( productId: number, product: { title: string; price: number; category: string },) { return Effect.gen(function* () { const client = yield* HttpClient.HttpClient;
const request = HttpClientRequest.put( `https://dummyjson.com/products/${productId}`, ).pipe(HttpClientRequest.bodyJsonUnsafe(product));
const response = yield* client.execute(request); const data = yield* response.json;
return data; }).pipe(Effect.provide(FetchHttpClient.layer));}
// Test it — replace product 1 with entirely new dataEffect.runPromise( replaceProduct(1, { title: "Mechanical Keyboard", price: 199, category: "electronics", }),).then((data) => { console.log("Updated product:", data.title, `- $${data.price}`);});Output:
Updated product: Mechanical Keyboard - $199HttpClientRequest.put(url) creates a request with the PUT method. The rest of the pattern is identical to POST: attach a body and execute.