-
-
Save jojojojojoj5564656465465/fe70faf57d090c3c726db6620295a723 to your computer and use it in GitHub Desktop.
JSON 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
export async function jsonFetch<T>( | |
url: string, | |
options: RequestInit = {} | |
): Promise<T> { | |
// Set the default headers correctly | |
const headers: HeadersInit = new Headers(options.headers); | |
headers.set('Accept', 'application/json'); | |
headers.set('Content-Type', 'application/json'); | |
return fetch(url, { | |
...options, | |
headers, | |
credentials: 'include', | |
}) | |
.then((response) => response.json()) | |
.catch((error) => { | |
console.error('There was an error ?', error); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment