Options
All
  • Public
  • Public/Protected
  • All
Menu

Hierarchy

  • ServiceCall
    • OfflineResponseServiceCall

Index

Properties

Static Readonly BASE_HEADERS

BASE_HEADERS: Readonly<{ Content-Type: string; Accept: string; Accept-Language: any; Cache-Control: string }> = ...

Default values of headers

static
readonly
property

{object} header object

Protected _http

_http: IHttp

Methods

Static bodyParser

  • bodyParser(requestUrl: string, response: any): void
  • Parameters

    • requestUrl: string
    • response: any

    Returns void

Static convertObjectToFormData

  • convertObjectToFormData(body: {}): string
  • Parameters

    • body: {}
      • [key: string]: any

    Returns string

Static getContentType

  • getContentType(headers?: Record<string, any>): any
  • Parameters

    • headers: Record<string, any> = {}

    Returns any

request

  • request(endpointPath: string, options?: IRequestOptions): Promise<any>

setHeader

  • setHeader(key: string | Record<string, any>, value?: string): void
  • Sets headers for this configuration. Either sets one by each call or sets them in bulk

    method
    example
    //After login
    sc.setHeader("Authorization", "Basic 12345");
    example
    //After logout
    sc.setHeader("Authorization");
    example
    // set multiple headers at once
    sc.setHeader({
    environment: "test",
    apiVersion: "1.2" //replaces the existing
    });

    Parameters

    • key: string | Record<string, any>

      Header name to set

    • Optional value: string

      Value to set of the key. If value is not a string, key is removed from header

    Returns void

getHeaders

  • getHeaders(): Record<string, any>
  • Gets a copy of headers used

    method

    Returns Record<string, any>

    headers

createRequestOptions

  • createRequestOptions(endpointPath: string, options: IRequestOptions): IRequestOptions
  • creates a request options object for http request

    method
    example
    const reqOps = sc.createRequestOptions(`/auth/login`, {
    method: "POST",
    body: {
    userName,
    password
    },
    headers: {
    "Content-Type": "application/json"
    }
    });
    sc.request(reqOps).then((result) => {
    //logic
    }).catch((err) => {
    //logic
    });

    Parameters

    • endpointPath: string
    • options: IRequestOptions

    Returns IRequestOptions

Constructors

constructor

  • new OfflineResponseServiceCall(options: { baseUrl: string; logEnabled?: boolean; requestCleaner: undefined | (<T>(e: T) => Promise<T>); encryptionFunction: any; decryptionFunction: any }): OfflineResponseServiceCall
  • Creates an OfflineResponseServiceCall helper class Response is served from DB then request is made to update the DB

    example
    import { OfflineResponseServiceCall } from '@smartface/extension-utils/lib/service-call-offline';
    sc = sc || new OfflineResponseServiceCall({
    baseUrl: "http://smartface.io",
    logEnabled: true,
    requestCleaner: requestOptions => {
    delete requestOptions.headers;
    return requestOptions;
    }
    });

    Parameters

    • options: { baseUrl: string; logEnabled?: boolean; requestCleaner: undefined | (<T>(e: T) => Promise<T>); encryptionFunction: any; decryptionFunction: any }
      • baseUrl: string
      • Optional logEnabled?: boolean
      • requestCleaner: undefined | (<T>(e: T) => Promise<T>)
      • encryptionFunction:function
        • encryptionFunction(e: any): any
      • decryptionFunction:function
        • decryptionFunction(e: any): any

    Returns OfflineResponseServiceCall

Accessors

baseUrl

  • get baseUrl(): string
  • set baseUrl(value: string): void
  • Base URL for this service-call library uses. This can be get and set

    property

    {string} baseUrl

    Returns string

  • Base URL for this service-call library uses. This can be get and set

    Parameters

    • value: string

    Returns void

logEnabled

  • get logEnabled(): boolean
  • set logEnabled(value: boolean): void
  • Log enabled for service-call. This can be get and set

    property

    {boolean} logEnabled

    Returns boolean

  • Log enabled for service-call. This can be get and set

    Parameters

    • value: boolean

    Returns void

Generated using TypeDoc