Skip to content

Instantly share code, notes, and snippets.

@andrit
Created July 10, 2018 16:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrit/63577e2d13425d9814211d1295c3c81b to your computer and use it in GitHub Desktop.
Save andrit/63577e2d13425d9814211d1295c3c81b to your computer and use it in GitHub Desktop.
import axios from 'axios';

export const loadJsonHttp = (url, resObj) => {
    return fetch(url, resObj)
        .then(response => {
            if (response.status >= 200 && response.status < 300) {
            return Promise.resolve(response)
            } else {
            return Promise.reject(new Error(response.statusText))
            }
        })
      .then(response => {
          response.json();
          
        });
  }
export const loadJsonLocal = (url, resObj) => {
    return  axios.get(url)
                .then(function(res) {

                        var nodes;
                        nodes = res.data;

                        var nodesArray = Object.keys(nodes).map(function(k) { return nodes[k] });
                        return nodesArray;
                
                })
                .catch(function(error){
                    console.log(error);
                });

  }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment