Extracting Out a Generic http Function
Learn to use fetch function to interact with REST API.
We'll cover the following
We'll need to use the fetch
function in every function that needs to interact with the REST API. So, we are going to create a generic http
function that we'll use to make all of our HTTP requests. This will nicely centralize the code that calls the REST API.
Steps to centralize the code that calls the REST API
Let's carry out the following steps:
Create a new file called
http.ts
with the following content:
Get hands-on with 1400+ tech skills courses.