How to use the fetch function from cross-fetch

Find comprehensive JavaScript cross-fetch.fetch code examples handpicked from public code repositorys.

6
7
8
9
10
11
12
13
14
15
 * @param {*} event - The Electron event object that triggered the submission of the mock request.
 * @param {*} postData - the JSON stringified object from the renderer that contains a "method", "endpoint" and "response" keys that will be used to create the mock endpoint.
 */
submitMockRequest: async (event, postData) => {
  try {
    const result = await fetch('http://localhost:9990/mock/', {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
      },
fork icon116
star icon796
watch icon17

50
51
52
53
54
55
56
57
58
59
60
 * @see {@link https://developer.mozilla.org/docs/Web/API/fetch} for more about the fetch API.
 * @returns {Promise<Response>} A promise for the response to the request.
 */
const scratchFetch = (resource, options) => {
    const augmentedOptions = applyMetadata(options);
    return fetch(resource, augmentedOptions);
};


/**
 * Set the value of a named request metadata item.
fork icon115
star icon55
watch icon35

+ 3 other calls in file

64
65
66
67
68
69
70
71
72
73
74
 * @see {@link https://developer.mozilla.org/docs/Web/API/fetch} for more about the fetch API.
 * @returns {Promise<Response>} A promise for the response to the request.
 */
const scratchFetch = (resource, options) => {
    const augmentedOptions = applyMetadata(options);
    return crossFetch.fetch(resource, augmentedOptions);
};


/**
 * Set the value of a named request metadata item.
fork icon115
star icon55
watch icon35

+ 2 other calls in file

24
25
26
27
28
29
30
31
32
33
let statusCode = 200;
let body;
let response;

try {
  response = await fetch(request);
  body = await response.json();
  if (body.errors) statusCode = 400;
} catch (error) {
  console.log(error)
fork icon1
star icon3
watch icon6

+ 3 other calls in file

21
22
23
24
25
26
27
28
29
30
31
32
  const origin = `${uri.protocol}//${uri.host}`;
  return new URL(url, origin).href;
}


async function getEntries() {
  const response = await fetch(SITE_URL);
  const page = await response.text();


  const $ = load(page);

fork icon0
star icon0
watch icon0

9
10
11
12
13
14
15
16
17
18
19
20
const PRODUCT_IMAGE_SELECTOR = "img";
const PRODUCT_LINK_SELECTOR = "a";
const PRODUCT_TIME_SELECTOR = ".lty-lottery-countdown-timer";


async function getProductInfo() {
  const response = await fetch(URL);
  const page = await response.text();


  const $ = load(page);

fork icon0
star icon0
watch icon0