A PATCH request tells the server to update specific fields of a resource, leaving everything else unchanged. You only send the fields you want to modify.
import { FetchHttpClient, HttpClient, HttpClientRequest,} from "effect/unstable/http";import { Effect } from "effect";
function updateProductPrice(productId: number, newPrice: number) { return Effect.gen(function* () { const client = yield* HttpClient.HttpClient;
// Only send the field we want to change const request = HttpClientRequest.patch( `https://dummyjson.com/products/${productId}`, ).pipe(HttpClientRequest.bodyJsonUnsafe({ price: newPrice }));
const response = yield* client.execute(request); const data = yield* response.json;
return data; }).pipe(Effect.provide(FetchHttpClient.layer));}
// Test it — update only the price of product 1Effect.runPromise(updateProductPrice(1, 5.99)).then((data) => { console.log("Product:", data.title); console.log("New price:", `$${data.price}`);});Output:
Product: Essence Mascara Lash PrincessNew price: $5.99HttpClientRequest.patch(url) creates a request with the PATCH method. The body contains only the fields to update.