Some HTTP responses carry meaning entirely through their status code and headers, with no body at all. Examples include a 204 No Content after a successful delete, a 304 Not Modified with cache headers, or a 201 Created with a Location header pointing to the new resource.
HttpClientResponse.schemaNoBody() validates the status code and headers of these bodiless responses against a schema. It never reads the body.
import { FetchHttpClient, HttpClient, HttpClientRequest, HttpClientResponse,} from "effect/unstable/http";import { Effect, Schema } from "effect";
// A schema for a successful delete responseconst DeleteResponse = Schema.Struct({ status: Schema.Literal(200), headers: Schema.Struct({ "content-type": Schema.String, }),});
function deleteProduct(productId: number) { return Effect.gen(function* () { const client = yield* HttpClient.HttpClient;
const request = HttpClientRequest.del( `https://dummyjson.com/products/${productId}`, );
const response = yield* client.execute(request);
// Validate status + headers without reading the body const validated = yield* HttpClientResponse.schemaNoBody(DeleteResponse)(response);
console.log("Status:", validated.status); console.log("Content-Type:", validated.headers["content-type"]);
return validated; }).pipe(Effect.provide(FetchHttpClient.layer));}
// Test itEffect.runPromise(deleteProduct(1)).then( (result) => console.log("Delete confirmed with status", result.status), (error) => console.error("Validation failed:", error.message),);Output:
Status: 200Content-Type: application/json; charset=utf-8Delete confirmed with status 200schemaNoBody constructs an object with { status, headers } from the response and validates it against your schema. The body is never touched. This means it works correctly even on responses that have no body at all (where response.json would fail with an error).