Using the SharePoint REST API
To demonstrate how to use the SharePoint REST API, we will now update the getProducts() method of the ProductCatalogService class to use the SPHttpClient client to fetch the list of products from a SharePoint list instead of the Microsoft Graph API.
First, we update the constructor of the class to take an SPHttpClient parameter and the absolute web URL from where the products list is located:
export class ProductCatalogService implements IProductCatalogService {
  private _spHttpClient: SPHttpClient;
  private _webUrl: string;
  constructor(spHttpClient: SPHttpClient, webUrl: string) {
    this._spHttpClient = spHttpClient;
    this._webUrl = webUrl;
  }
  ...			Unlike the Microsoft Graph API, all HTTP requests with the SharePoint REST API are made relative to the site where the data is located. We use the /_api/web/lists/GetByTitle('Products')/items...
 
                                             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
     
         
                 
                 
                 
                 
                 
                 
                 
                 
                