redstone-isomorphic

Isomorphic API for Node & Browserify

Usage no npm install needed!

<script type="module">
  import redstoneIsomorphic from 'https://cdn.skypack.dev/redstone-isomorphic';
</script>

README

redstone-isomorphic

redstone-isomorphic is a fork of isomorphic-fetch.

fetch

It adds fetch as global so its API is consistent between client and server. It uses standard fetch() method on client's side and undici - which is an http client written for Node.js - on server's side.

v8

It applies v8 module for server environment. It is not defined for browser and this difference should be taken into account when determining if v8 methods should be used or not.

Installation

NPM

npm install --save redstone-isomorphic

YARN

yarn add redstone-isomorphic

Usage

fetch

import "redstone-isomorphic";

fetch("//api.redstone.finance")
  .then(function (response) {
    if (response.status >= 400) {
      throw new Error("Bad response from server");
    }
    return response.json();
  })
  .then(function (data) {
    console.log(data);
  });

v8

import { v8 } from "redstone-isomorphic";

const deepCopy = (input) => {
  if (!!v8) {
    return v8.deserialize(v8.serialize(input));
  }

  return JSON.parse(JSON.stringify(input));
};