Overview

The global HTTP client in our template automatically manages the inclusion of resource-specific information in the headers of HTTP requests. This is essential for requests that interact with specific resources.

Mechanism

  • Resource Storage: The resource identifier (e.g., a project or studio ID) is stored in the local storage.
  • Automatic Inclusion: When the resource is set in local storage, it is automatically included as a header in all HTTP requests. This informs the server about the specific resource the request is targeting.

Implementation

  • Resource Management: In storage.helper.ts, two methods getResource and setResource manage the resource in local storage.
    export const getResource = (): any => {
      return localStorage.getItem("resource");
    };
    
    export const setResource = (studioId: string): any => {
      return localStorage.setItem("resource", studioId);
    };
    
  • Header Injection: In the HTTP client, the injectToken method checks for the resource in local storage. If found, it adds this identifier to the resource header of the request.

Importance for Users

  • Streamlined Process: Users of this template should be aware that resource management is handled automatically. Once a resource is set in local storage, it gets included in all relevant HTTP requests without further action needed.
  • Ease of Use: This feature simplifies the development process by abstracting the routine task of attaching resource identifiers to every relevant request.