Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use Fetch API instead of XHR #12

Closed
uneco opened this issue Jan 16, 2019 · 1 comment
Closed

use Fetch API instead of XHR #12

uneco opened this issue Jan 16, 2019 · 1 comment

Comments

@uneco
Copy link
Contributor

uneco commented Jan 16, 2019

from:

export const httpGet = async(
  url: string,
  header: { [s: string]: string } = {}
): Promise<XMLHttpRequest> => {
  return new Promise<XMLHttpRequest>((resolve, _reject) => {
    const xhr = new XMLHttpRequest();
    xhr.onreadystatechange = function (event) {
      if (xhr.readyState !== 4) return;
      return resolve(xhr); // OK
    };
    xhr.open('GET', url, true); // Async
    Object.keys(header).forEach(function (key) {
      xhr.setRequestHeader( key, header[key] );
    });
    xhr.withCredentials = true;
    xhr.send();
  });
};

to:

export const httpGet = async (url: string, headers: Headers = {}) => {
  return fetch(url, {
    headers,
    credentials: 'include',
  })
}
@takanakahiko
Copy link
Owner

@uneco I was thinking of making the same topic Issue too.
PRs welcome!

uneco added a commit to uneco/slack-emoji-meister that referenced this issue Jan 16, 2019
uneco added a commit to uneco/slack-emoji-meister that referenced this issue Jan 16, 2019
uneco added a commit to uneco/slack-emoji-meister that referenced this issue Jan 16, 2019
uneco added a commit to uneco/slack-emoji-meister that referenced this issue Jan 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants