Skip to content

API Call Overrides

👉 UI Pages will automatically call respected APIs generated by API Maker.
👉 If we want to override that behaviour we can use this feature.
👉 It will call only POST method APIs.
👉 You can run custom code before & after API call using these hooks "codeBeforeAPICall" & "codeAfterAPICall". One of their use case is to modify request payload before API call and change response after response received.

Examples

let dbMasterConfig: T.IDBMasterConfig = {
    operations: {
        add: {
            apiCallOverrides: {
                url: `http://:beHostPort/api/custom-api/:userPath/custom-save-api`,
            },
        },
        importData: {
            apiCallOverrides: {
                url: `http://:beHostPort/api/custom-api/:userPath/custom-import-data-api`,
            }
        }
    },
    form: {
        fields: [
            [{
                label: 'Custom API Dropdown',
                control: T.EDBMasterFormControl.dropdown,
                path: 'custom_api_in_dropdown',

                dropdownSettings: {
                    dataSource: 'api_call',

                    optionLabel: 'label',
                    optionValue: 'value',

                    apiCallOverrides: {
                        url: 'http://:beHostPort/api/custom-api/:userPath/custom-dropdown-api',
                    }
                },
            }]
        ]
    },
    grid: {
        apiCallOverrides: {
            url: `http://:beHostPort/api/custom-api/:userPath/custom-get-grid-data`,
        },

        operations: {
            delete: {
                enable: true,
                apiCallOverrides: {
                    url: `http://:beHostPort/api/custom-api/:userPath/custom-delete-by-id`,
                    pkField: '_id', // 👈 Primary key of current table
                },

                apiCallOverridesDeleteMany: {
                    url: `http://:beHostPort/api/custom-api/:userPath/custom-delete-many`,
                    pkField: '_id', // 👈 Primary key of current table
                }
            },
            edit: {
                enable: true,
                apiCallOverrides: {
                    url: `http://:beHostPort/api/custom-api/:userPath/custom-edit-by-id`,
                },

                apiCallOverridesGetById: {
                    url: `http://:beHostPort/api/custom-api/:userPath/custom-get-by-id`,
                    pkField: '_id', // 👈 Primary key of current table
                }
            },
        }
    }
};

Interface Documentation

export interface IDBMasterAPICallOverrides {
    url: string;
    headers?: any;
    method?: 'POST';
    body?: any;

    /** Primary key field name for current table. _id for mongodb. */
    pkField?: string;

    /**
     * Below variables are available,
     * config: IDBMasterConfig,<br/>
     * formData: any, Not available in case of grid.<br/>
     * allDropdownDataMap: { [path: string]: any[] }, Not available in case of grid.<br/>
     * apiResponse: any,<br/>
     * globalData: any,<br/>
     * headers: any,<br/>
     * reqBody: any,<br/>
     * utils: any,<br/>
     * queryParams: any,<br/>
     * mode: any | null,<br/>
     * */
    codeBeforeAPICall?: string;

    /**
     * Below variables are available,
     * config: IDBMasterConfig,<br/>
     * formData: any, Not available in case of grid.<br/>
     * allDropdownDataMap: { [path: string]: any[] }, Not available in case of grid.<br/>
     * apiResponse: any,<br/>
     * globalData: any,<br/>
     * headers: any,<br/>
     * reqBody: any,<br/>
     * utils: any,<br/>
     * queryParams: any,<br/>
     * mode: any | null,<br/>
     * */
    codeAfterAPICall?: string;
}