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. Let's carry out the following steps:
- Create a new file called http.ts with the following content:
import { webAPIUrl } from './AppSettings';export interface HttpRequest<REQB> { path: string;}export interface HttpResponse<RESB> extends Response { parsedBody?: RESB;}
We've started by importing the root path to our REST API from AppSettings.ts, which was set up in our starter project. The AppSettings.ts file is where we will build all of the different ...