API Call Overrides¶
UI Maker is deprecated
UI Maker is kept for the projects which use it and will be removed in API Maker v4. New admin screens are better built with any frontend framework on top of the generated APIs.
👉 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: `:beHostPort/api/custom-api/:userPath/custom-save-api`,
},
},
importData: {
apiCallOverrides: {
url: `: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: ':beHostPort/api/custom-api/:userPath/custom-dropdown-api',
}
},
}]
]
},
grid: {
apiCallOverrides: {
url: `:beHostPort/api/custom-api/:userPath/custom-get-grid-data`,
},
operations: {
delete: {
enable: true,
apiCallOverrides: {
url: `:beHostPort/api/custom-api/:userPath/custom-delete-by-id`,
pkField: '_id', // 👈 Primary key of current table
},
apiCallOverridesDeleteMany: {
url: `:beHostPort/api/custom-api/:userPath/custom-delete-many`,
pkField: '_id', // 👈 Primary key of current table
}
},
edit: {
enable: true,
apiCallOverrides: {
url: `:beHostPort/api/custom-api/:userPath/custom-edit-by-id`,
},
apiCallOverridesGetById: {
url: `:beHostPort/api/custom-api/:userPath/custom-get-by-id`,
pkField: '_id', // 👈 Primary key of current table
}
},
}
}
};
Send data to parent page¶
👉 Below code will be executed from utils.
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;
}