In this recipe, we created a wrapper for the Fetch API that is presented on the window element. This wrapper consists of a currying and closure function, where the first function receives the URL data, method, and options for the Fetch API, and the resulting function is the Fetch API response translator.
In the wrapper, the first part of the function will create our fetch request. There, we need to check whether it's a GET method, so we just need to execute it with the url parameter and omit the others. The second part of the function is responsible for the conversion of the fetch response. It will switch between the type parameter and execute the retrieving function according to the correct one.
To receive the final data for your request, you always need to call the response translator after the request, as in the following example:
getHttp('https://jsonplaceholder.typicode.com/todos/1',
'json').then((response) => { console.log(response...