Skip to content

Requests - TO ALIGN TO NEW ARCHITECTURE

Location: TBD!!

API Requests is one of the features coming from Harmony.
Requests class include the following methods:

call

Call to API

Parameters:

config - axios config json.

Usage

import from src/base/base-api/index.ts

request.call({
    method: 'post',
    baseURL: baseURL,
    url: 'users/login',
    data: data
});

broadcastAction

Invoke action via websocket to every online client.

Parameters:

action - Action that you want to execute.

Usage

import from client/base/api/requests.js

import {UserTypes} from '../redux/user';
requests.broadcastAction({type: UserTypes.FETCH_POSTS, payload: null});

Requests Definitions File

Location: client/requests/index.js

In requests file we define all the requests calls and use it in sagas. Harmony prefer to use one file to export requests definitions for Best Practice.

Example Code

createUser: (data) => {
    return request.call({
        method: 'post',
        baseURL: baseURL,
        url: '/users',
        data: data
    });
}

API Call Options

In api call you can send in options some props to define error handler manually:

    export interface CallOptions {
        unauthorized?: boolean; // true - will not send autorization token in the header for that API
        ignoreErrorHandler?: boolean; // ignore erorr handler for that API
        generalErrorInfo?: { errorCode: string; status: number }; // for this API, for ANY failed, return this error code and status
    }


Usage Example:

    getDevices: () => request.call({
        baseURL: 'http://6ew7g.mocklab.io/' || baseURL,
        method: 'get',
        url: '/getlatestWithCustomResponseCode'
    }, { unauthorized: true, generalErrorInfo: { errorCode: 'getDevicesFiledForSomeReason', status: 500 } })