-
-
Save SKumarSpace/60fe0abec16946635186dbc2adc5b998 to your computer and use it in GitHub Desktop.
cool fetch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function myCoolFetch(url: string): Promise<Response> { | |
// Simulating an asynchronous operation | |
return new Promise<Response>((resolve, reject) => { | |
// Simulating a delay before resolving the promise | |
setTimeout(() => { | |
// Create a mock response object | |
const response: Response = { | |
status: 200, | |
statusText: "OK", | |
ok: true, | |
redirected: false, | |
type: "basic", | |
url: url, | |
clone: () => response, | |
body: null, | |
bodyUsed: false, | |
blob: () => Promise.resolve(new Blob()), | |
formData: () => Promise.resolve(new FormData()), | |
arrayBuffer: () => Promise.resolve(new ArrayBuffer(0)), | |
headers: new Headers(), | |
// headers: { | |
// "Content-Type": "application/json", | |
// }, | |
text: () => | |
Promise.resolve(JSON.stringify({ message: "Hello, world!" })), | |
json: () => Promise.resolve({ message: "Hello, world!" }), | |
}; | |
// Resolve the promise with the mock response | |
resolve(response); | |
}, 1000); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment