How to use Storage API

How to use Storage API

1 Like

Storage API of API Gateway is an interface through which we you can store data in localStorage, session Storage and IndexDB . It provides one method for accessing, retrieving and deleting records from Web API’s.

Let’s see how we can use this:-

  1. First create instance of API Gateway and set the configuration for API’s.

let api =  new APIGateway();

     api.config({

         logging:  true ,  // enable Logging in API GATEWAY.

         serviceWorker:  true ,  // enable service worker on production

         activeSWOnLocalHost:  false ,  // enable service worker on localHost

         enableStorageEncryption:  true ,  // enable encryption of key and value in Storage

         storageEncryptionKey:  "decimalSecretkey" ,  // key to be used for Encryption

         storage:  "sessionStorage" ,  // Web API's to be used for storage . It can accepts localStorage, sessionStorage, indexDB.

         networkDriver:  "FETCH" // network driver to be used for calling network API's

       });
  1. API’s for retrieving and putting the value in web storage
// call this method for getting Storage API instance

public getStorageAPI(): Storage

// call this method for putting the value in storage

public setItem(key: string, value: any): Promise<boolean>

// call this method for retrieving the value from storage

public getItemValue(key: string): Promise<any>

//call this method for deleting the key and value from storage.

public clear(key: string): void

//call this method for clearing all Storage

public clearAll(): void

// call this method for getting all keys
public getAllKeys(): Promise<any>
1 Like