How to use the cross-fetch.fetch function in cross-fetch

To help you get started, we’ve selected a few cross-fetch 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 ospfranco / link-preview-js / index.js View on Github external
if (!text) {
      return reject({
        error: 'React-Native-Link-Preview did not receive either a url or text'
      });
    }

    var detectedUrl = null;

    text.replace(/\n/g, ' ').split(' ').forEach(function (token) {
      if (CONSTANTS.REGEX_VALID_URL.test(token) && !detectedUrl) {
        detectedUrl = token;
      }
    });

    if (detectedUrl) {
      fetch(detectedUrl)
        .then(function (response) {

          // get final URL (after any redirects)
          const finalUrl = response.url;

          // get content type of response
          var contentType = response.headers.get('content-type');

          if (!contentType) {
            return reject({ error: 'React-Native-Link-Preview: Could not extract content type for URL.' });
          }
          if (contentType instanceof Array) {
            contentType = contentType[0];
          }

          // parse response depending on content type
github jefflau / jest-fetch-mock / src / index.js View on Github external
? bodyOrFunction(request).then(resp => {
          if (request.signal && request.signal.aborted) {
            abort()
          }
          return typeof resp === 'string'
            ? responseWrapper(resp, init)
            : responseWrapper(resp.body, responseInit(resp, init))
        })
      : new Promise((resolve, reject) => {
          if (request.signal && request.signal.aborted) {
            reject(abortError())
            return
          }
          resolve(responseWrapper(bodyOrFunction, init))
        })
    : crossFetch.fetch(input, reqInit)
}
github ardatan / graphql-toolkit / packages / loaders / github / src / index.ts View on Github external
async load(pointer: string, options: GithubLoaderOptions) {
    const { owner, name, ref, path } = extractData(pointer);
    const request = await fetch('https://api.github.com/graphql', {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json; charset=utf-8',
        Authorization: `bearer ${options.token}`,
      },
      body: JSON.stringify({
        query: `
          query GetGraphQLSchemaForGraphQLToolkit($owner: String!, $name: String!, $expression: String!) {
            repository(owner: $owner, name: $name) {
              object(expression: $expression) {
                ... on Blob {
                  text
                }
              }
            }
          }
github swagger-api / swagger-js / src / specmap / lib / refs.js View on Github external
function fetchJSON(docPath) {
  return fetch(docPath, {headers: {Accept: ACCEPT_HEADER_VALUE_FOR_DOCUMENTS}, loadSpec: true})
    .then(res => res.text())
    .then(text => jsYaml.safeLoad(text))
}
github BendJS / website / pages / index.js View on Github external
static async getInitialProps() {
    const meetups = await fetch(
      "https://api.meetup.com/bendjs/events?photo-host=public&page=20&sig_id=13359878&sig=d052a7d6f8ec6f8e374c2a2665e4aa724208ca5d"
    )
      .then(res => res.json())
      .then(data => Object.values(data));

    return { meetups };
  }