1.0.0 • Published 9 months ago

@pavlovic265/go-fetch v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
9 months ago

Go Error

Wrapper around fetch API to handle data and errors, errors are handled similarly to GoLang as it was used as inspiration

Usage/Examples

type Product = {
  id: number;
  title: string
}

async function example() {
  const { err: productsError, jsonData: products } = await goFetch<Product[]>("https://dummyjson.com/products");
  if (productsError !== undefined) {
    // handle products error
    return;
  }
  // handle products

  const { err: productsError, jsonData: product } = await goFetch<Product>(`https://dummyjson.com/products/${jsonData[0].id}`);
  if (productsError != undefined) {
    // handle products error
    return
  }
  // handle product

}
1.0.0

9 months ago