BaseResponse
Generic wrapper around a Response plus the parsed body. Returned by every safe runner on RequestBuilder (run, runAdapter, runArrayAdapter, runEmpty, runPaginatedAdapter, runData, runDataKey).
Importing
ts
import { BaseResponse } from '@basmilius/http-client';Constructor
ts
new BaseResponse<T>(data: T, response: Response)| Argument | Type | Description |
|---|---|---|
data | T | The parsed body (typed by the runner that produced it). |
response | Response | The underlying Fetch Response. |
Properties
data—T. Read-only. The parsed body.headers—Headers. Read-only. Shorthand forresponse.headers.ok—boolean. Read-only.truewhenstatusCodeis between200and299inclusive.response—Response. Read-only. The underlying FetchResponse.statusCode—HttpStatusCode. Read-only. The numeric HTTP status code.
Example
ts
const response = await userService.get('user-1');
if (response.ok) {
console.log(response.data.email);
console.log(response.headers.get('etag'));
}Notes
- The
datafield can benullfor204responses or for401/403responses without a JSON body — seeRequestBuilderfor the full mapping. BaseResponseis a plain class — it is not decorated with@dto. Treat it as a snapshot of the response.
See also
RequestBuilder— the runners that produceBaseResponseinstances.- Helpers — type guard reference.