Extracting Out a Generic http Function

Learn to use fetch function to interact with REST API.

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:

  1. Create a new file called http.ts with the following content:

Get hands-on with 1200+ tech skills courses.