How to use cross-fetch

Comprehensive cross-fetch code examples:

How to use cross-fetch.blob:

61
62
63
64
65
66
67
68
69
70
    body: JSON.stringify(body) //The body of the request
  });
  if (response.status == 200) {
    return await fetch.json();
    //or
    return await fetch.blob(); // for PDFs
  } else {
    throw REQUEST_ERROR
  }
} catch(err) {

How to use cross-fetch.json:

59
60
61
62
63
64
65
66
67
68
    'tryal-application-token': '<tryal-app-token>' // Your App Token goes here
  },
  body: JSON.stringify(body) //The body of the request
});
if (response.status == 200) {
  return await fetch.json();
  //or
  return await fetch.blob(); // for PDFs
} else {
  throw REQUEST_ERROR

How to use cross-fetch.Request:

18
19
20
21
22
23
24
25
26
    'content-type': 'application/json'
  },
  body: JSON.stringify(query)
};

const request = new Request(endpoint, options);
let statusCode = 200;
let body;
let response;

How to use cross-fetch.fetch:

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',
      },

How to use cross-fetch.Headers:

31
32
33
34
35
36
37
38
39
40
const results = {
    ok: false,
    status: 0
};
if (options?.mockFetchTestData) {
    options.mockFetchTestData.headers = new Headers(options.headers);
    options.mockFetchTestData.headersCount = Array.from(options.mockFetchTestData.headers).length;
}
switch (resource) {
case '200':