Execute API
Description
This method can be used inside any workspace. To call the API service and execute a Restful operation.
Method(s)
public executeAPI(
method: "GET" | "POST" | "PUT" | "DELETE" | "PATCH",
relativePath: string,
params?: { [name: string]: string },
body?: object,
showToast = true,
headers: { [name: string]: string } = {},
setContentTypeHeader = true,
setProfileRequest = true,
useCache = false
): Promise<any> {
return this.executeApiService.executeAPI(
Apis.apiV2,
method,
relativePath,
params,
body,
showToast,
headers,
setContentTypeHeader,
setProfileRequest,
useCache
);
}
Parameter | Type | Required | Defaults | Description |
---|---|---|---|---|
method | String | true | Set the type of request | |
relativePath | String | true | Url request | |
params | String | false | Parameters that are intended to be passed in the request | |
body | String | false | The content to replace with | |
showToast | String | false | true | To return a toast related to the request when error occurs |
headers | String | false | empty | Meta-data associated with the API request and response |
setContentTypeHeader | String | false | true | If it's set to true it will append 'Content-Type' to the header with the value 'application-json' |
setProfileRequest | String | false | true | If it's set to true it will append 'x-sw-profilerequest' to the header with the value 'true' |
useCache | String | false | false | If it's set to true it will cache the request |
Basic Usage
SW.executeAPI("GET", "documentBriefs", {
documentId: "d8615b0f-4b52-4360-8f61-62c62bcb5463",
});