Options
All
  • Public
  • Public/Protected
  • All
Menu

External module "Verify"

Index

Type aliases

Type aliases

Verify

Verify: function

Used to verify JSON returned with the fetcher

example
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);

Type declaration

    • (json: any): boolean
    • Parameters

      • json: any

      Returns boolean