How to use the isomorphic-unfetch function in isomorphic-unfetch

To help you get started, we’ve selected a few isomorphic-unfetch 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 yosriady / serverless-stripe-frontend / components / PayButton.js View on Github external
async onToken(token) { // Token returned from Stripe
    const res = await fetch(config.stripe.apiUrl, { // Backend API url
      method: 'POST',
      body: JSON.stringify({
        token,
        charge: {
          amount: this.props.amount,
          currency: config.stripe.currency,
        },
      }),
    });
    const data = await res.json();
    console.log('onToken'); // Logs for ease of debugging
    console.log(data);
  }
github morrys / offline-examples / relay / nextjs / relay / createRelayEnvironment.ts View on Github external
function fetchQuery(operation, variables, cacheConfig, uploadables) {
  const endpoint = 'http://localhost:3000/graphql';
  return fetch(endpoint, {
    method: 'POST',
    headers: {
      Accept: 'application/json',
      'Content-Type': 'application/json',
    }, // Add authentication and other headers here
    body: JSON.stringify({
      query: operation.text, // GraphQL text from input
      variables,
    }),
  })
    .then(response => response.json())
    .catch(error => console.log('errrrr', error));
}
github zeit / next.js / examples / with-rematch / shared / models / github.js View on Github external
async fetchUsers() {
      try {
        this.requestUsers()
        const response = await fetch('https://api.github.com/users')
        const users = await response.json()
        this.receiveUsers(users)
      } catch (err) {
        console.log(err)
        this.receiveUsers([])
      }
    },
  },
github skidding / flatris / utils / api.js View on Github external
function fetchJson(urlPath: string, options?: Object): Promise {
  return fetch(getApiUrl(urlPath), options).then(parseResponse);
}
github etalab / adresse.data.gouv.fr / lib / api-ban.js View on Github external
export async function request(url) {
  const options = {
    mode: 'cors',
    method: 'GET'
  }

  const response = await fetch(`${BAN_DASHBOARD_URL || 'https://adresse.data.gouv.fr/data'}${url}`, options)

  if (!response.ok) {
    throw new HttpError(response)
  }

  if (response.ok) {
    return response.json()
  }

  throw new Error('Une erreur est survenue')
}
github bgold0 / nextjs-auth-skeleton / pages / _app.js View on Github external
if (Component.getInitialProps) {
      pageProps = await Component.getInitialProps(ctx)
    }

    //if the authtoken is not found
    if(typeof c.authtoken == 'undefined') {
      //don't do anything if we are on a page that doesn't require credentials
      if(ctx.pathname == "/login" || ctx.pathname == "/forgot-password") return {pageProps};
      //if we are on any other page, redirect to the login page
      else redirectTo('/login', { res: ctx.res, status: 301 })
    }
    //if we do have an auth token to check
    else {

      var response = await fetch(API_URL+'/auth', {
        method: 'POST', headers: { 'Content-Type': 'application/json' },
        body: JSON.stringify({ token:c.authtoken} )
      })
      .then( r => r.json() )
      .then( resp => {

        if(ctx.pathname == "/")  {

          //if auth check was successful, send to dashboard
          if(resp.result == "success") redirectTo('/dashboard', { res: ctx.res, status: 301 })
          else {

            //setting the cookie to expire way back when removes it
            document.cookie = "authtoken=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;";
            redirectTo('/login', { res: ctx.res, status: 301 })
github krmao / template / web / nextjs / src / modules / film / index.js View on Github external
static async getInitialProps() {
        const res = await fetch("https://api.tvmaze.com/search/shows?q=marvel");
        const data = await res.json();
        return {
            shows: data
        };
    }

isomorphic-unfetch

Switches between unfetch & node-fetch for client & server.

MIT
Latest version published 1 year ago

Package Health Score

73 / 100
Full package analysis