Used to verify JSON returned with the fetcher
import { Json, isIJsonObject } from '@ef-carbon/fetch'; import { fetcher, Verify } from '@ef-carbon/fetcher'; interface IData { name: string; } function isIData(json: Json): json is IData { return isIJsonObject(json) && typeof json.name === 'string'; } const verify: Verify<IData> = isIData; // expected payload `{ "name": "Rick Sanchez" }` const response = await fetcher('http://endpoint.com/data.json'); const data = response.json(verify); // verification console.log(data.name);
Used to verify JSON returned with the fetcher
import { Json, isIJsonObject } from '@ef-carbon/fetch'; import { fetcher, Verify } from '@ef-carbon/fetcher'; interface IData { name: string; } function isIData(json: Json): json is IData { return isIJsonObject(json) && typeof json.name === 'string'; } const verify: Verify<IData> = isIData; // expected payload `{ "name": "Rick Sanchez" }` const response = await fetcher('http://endpoint.com/data.json'); const data = response.json(verify); // verification console.log(data.name);