How to use the ky/umd.get function in ky

To help you get started, we’ve selected a few ky examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github digidem / mapeo-desktop / src / renderer / create-zip.js View on Github external
const tasks = remoteFiles.map(({ url, metadataPath, ...options }) => cb => {
    cb = once(cb)
    const start = Date.now()
    console.log('Requesting', url)
    // I tried doing this by adding streams to the zipfile, but it's really hard
    // to catch errors when trying to download an image, so you end up with
    // corrupt files in the zip. This uses a bit more memory, but images are
    // only added once they have downloaded correctly
    ky.get(url)
      .arrayBuffer()
      .then(arrBuf => {
        console.log('Req end in ' + (Date.now() - start) + 'ms ' + metadataPath)
        zipfile.addBuffer(Buffer.from(arrBuf), metadataPath, {
          ...options,
          store: true
        })
        cb()
      })
      .catch(err => {
        missing.push(metadataPath)
        console.log('Error downloading file ' + metadataPath, err)
        cb()
      })
  })
  const start = Date.now()
github peterbe / whatsdeployed / src / shortUrls.js View on Github external
history = JSON.parse(json);
        } catch (err) {
          console.error(
            'Error loading cached shortUrls from localStorage:',
            err
          );
          localStorage.removeItem('shortUrls');
          history = [];
        }
      }

      if (history.length > 0) {
        const url = new URL(window.location.origin);
        url.pathname = '/shortened';
        url.searchParams.set('urls', history.join(','));
        const { environments } = await ky.get(url).json();
        cache = environments;
        return environments;
      } else {
        cache = [];
      }
    }

    return cache;
  },
github peterbe / whatsdeployed / src / DeployPage.js View on Github external
async fetchCommits() {
    const { owner, repo } = this.state;
    this.startLoad('commits');
    try {
      const commitsUrl = new URL(window.location.origin);
      commitsUrl.pathname = '/githubapi/commits';
      commitsUrl.searchParams.set('owner', owner);
      commitsUrl.searchParams.set('repo', repo);
      commitsUrl.searchParams.set('per_page', 100);

      const commits = await ky.get(commitsUrl).json();

      this.setState({ commits });
    } catch (error) {
      this.setState({ error });
    } finally {
      this.finishLoad('commits');
    }
  }
github peterbe / whatsdeployed / src / shortUrls.js View on Github external
async decode(code) {
    if (code.startsWith('s-')) {
      code = code.slice(2);
    }
    const params = await ky.get(`/lengthenit/${code}`).json();
    return params;
  },

ky

Tiny and elegant HTTP client based on the browser Fetch API

MIT
Latest version published 12 days ago

Package Health Score

91 / 100
Full package analysis